Debugging R Environment and Dependencies
This skill focuses on resolving problems related to R environments rather than analysis logic. It helps restore a working setup so that R scripts and projects can run successfully.
Use this skill when the user encounters:
- - Package installation failures
- Version conflicts between packages
- renv or packrat environment issues
- Bioconductor version mismatches
- System dependency errors (e.g., missing compilers or libraries)
- R failing to start or load packages
What This Skill Does
When activated, this skill will:
- 1. Diagnose the environment
- Check R version
- Check installed packages and versions
- Inspect
renv.lock or project library
- Identify Bioconductor version compatibility
- 2. Resolve package installation issues
- Suggest correct CRAN/Bioconductor repositories
- Install missing system dependencies (e.g.,
libxml2,
curl,
openssl)
- Handle compilation failures on Linux/macOS/Windows
- 3. Fix dependency conflicts
- Align package versions
- Reinstall broken packages
- Clean corrupted package libraries
- 4. Repair project environments
- Restore with
renv::restore()
- Rebuild
renv.lock
- Reinitialize project library if needed
- 5. Bioconductor troubleshooting
- Match Bioconductor version to R version
- Use
BiocManager::install() correctly
- Resolve common bioinformatics package errors
- 6. System-level troubleshooting
- Install missing compilers (e.g.,
gcc,
gfortran)
- Install development libraries required for R packages
- Fix PATH or permission issues
Example User Requests That Should Trigger This Skill
- - "I can't install tidyverse"
- "This package fails with a compilation error"
- "renv restore is broken"
- "Bioconductor says my version is incompatible"
- "library() fails even though the package is installed"
- "R says shared object cannot be loaded"
Example Workflow
User: I get an error when installing sf.
Skill actions:
- - Detect missing system libraries (GEOS, GDAL, PROJ)
- Provide OS-specific install commands
- Retry R package installation
- Confirm successful library loading
Common Problem Categories
| Category | Examples |
|---|
| Missing system libs | xml2, curl, openssl, sf, rJava |
| Compiler issues |
gfortran missing, Xcode tools missing |
| Version mismatch | old R vs new package |
| Bioconductor mismatch | wrong Bioc version for R |
| renv problems | corrupted cache, lockfile mismatch |
| Permission issues | cannot write to library path |
Notes
- - Do not modify analysis code unless necessary
- Prefer fixing the environment over rewriting scripts
- Always aim to make the project reproducible
- Recommend
renv for future environment stability
调试R环境与依赖项
本技能专注于解决与R环境相关的问题,而非分析逻辑。它有助于恢复可正常工作的配置,使R脚本和项目能够成功运行。
当用户遇到以下情况时,请使用此技能:
- - 包安装失败
- 包之间的版本冲突
- renv或packrat环境问题
- Bioconductor版本不匹配
- 系统依赖错误(例如,缺少编译器或库)
- R无法启动或加载包
本技能的功能
激活后,本技能将:
- 1. 诊断环境
- 检查R版本
- 检查已安装的包及其版本
- 检查renv.lock或项目库
- 识别Bioconductor版本兼容性
- 2. 解决包安装问题
- 建议正确的CRAN/Bioconductor仓库
- 安装缺失的系统依赖项(例如libxml2、curl、openssl)
- 处理Linux/macOS/Windows上的编译失败
- 3. 修复依赖冲突
- 对齐包版本
- 重新安装损坏的包
- 清理损坏的包库
- 4. 修复项目环境
- 使用renv::restore()恢复
- 重建renv.lock
- 必要时重新初始化项目库
- 5. Bioconductor故障排除
- 将Bioconductor版本与R版本匹配
- 正确使用BiocManager::install()
- 解决常见的生物信息学包错误
- 6. 系统级故障排除
- 安装缺失的编译器(例如gcc、gfortran)
- 安装R包所需的开发库
- 修复PATH或权限问题
应触发此技能的示例用户请求
- - 我无法安装tidyverse
- 这个包编译时出错
- renv restore坏了
- Bioconductor说我的版本不兼容
- 即使包已安装,library()也失败
- R说无法加载共享对象
示例工作流程
用户: 安装sf时出现错误。
技能操作:
- - 检测缺失的系统库(GEOS、GDAL、PROJ)
- 提供特定操作系统的安装命令
- 重试R包安装
- 确认库加载成功
常见问题类别
| 类别 | 示例 |
|---|
| 缺失系统库 | xml2、curl、openssl、sf、rJava |
| 编译器问题 |
缺少gfortran、缺少Xcode工具 |
| 版本不匹配 | 旧版R与新版包 |
| Bioconductor不匹配 | R的Bioc版本错误 |
| renv问题 | 缓存损坏、锁文件不匹配 |
| 权限问题 | 无法写入库路径 |
备注
- - 除非必要,否则不要修改分析代码
- 优先修复环境而非重写脚本
- 始终致力于使项目可重现
- 推荐使用renv以确保未来环境的稳定性