M1/M2/M3芯片的Mac电脑如何配置R语言环境

视频地址: https://www.bilibili.com/video/BV1Z1421k7tv/

目标:

  1. 安装R语言
  2. 安装Rstudio:
    1. https://posit.co/download/rstudio-desktop/
  3. 安装R包
    1. CRAN
      1. tidyverse
      2. BiocManager
    2. Bioconductor
      1. DESeq2
    3. GitHub
      1. export

配置所需要的一些软件下载:https://pan.baidu.com/s/1f8MTR7mUksXgLpX_WVegaw 提取zgnh

修改镜像的代码

options("repos" = c(CRAN="https://mirror.nju.edu.cn/CRAN/"))
options(BioC_mirror="https://mirrors.tuna.tsinghua.edu.cn/bioconductor")

export安装的报错

Error in dyn.load(dynlib <- getDynlib(dir)) : 
  unable to load shared object '/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/rgl/libs/rgl.so':
  dlopen(/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/rgl/libs/rgl.so, 0x0006): Library not loaded: /opt/X11/lib/libGLU.1.dylib
  Referenced from: <C90BFE0D-3008-3759-8DC8-B7FD5F3D934B> /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/rgl/libs/rgl.so
  Reason: tried: '/opt/X11/lib/libGLU.1.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/X11/lib/libGLU.1.dylib' (no such file), '/opt/X11/lib/libGLU.1.dylib' (no such file), '/Library/Frameworks/R.framework/Resources/lib/libGLU.1.dylib' (no such file), '/Library/Java/JavaVirtualMachines/jdk-11.0.18+10/Contents/Home/lib/server/libGLU.1.dylib' (no such file), '/var/folders/zc/6v0fl8dj657c5cqf3_khprlc0000gn/T/rstudio-fallback-library-path-689470345/libGLU.1.dylib' (no such file)
Error: package or namespace load failed for ‘export’:
 .onLoad failed in loadNamespace() for 'rgl', details:
  call: rgl.init(initValue, onlyNULL)
  error: OpenGL is not available in this build
In addition: Warning messages:
1:   Loading rgl's DLL failed. 
  This build of rgl depends on XQuartz, which failed to load.
 See the discussion in https://stackoverflow.com/a/66127391/2554330 
2: Trying without OpenGL... 

解决方法:需要下载https://www.xquartz.org/ 安装以来环境。

Rstudio打开出现如下错误

Error in python_config_impl(python) : 
  Error 1 occurred running /usr/bin/python3: 
Error in python_config_impl(python) : 
  Error 1 occurred running /usr/bin/python3: 

安装的 reticulate,这个工具依赖于python3. mac没有默认安装python3, 所以就需要配置X-Code环境

  1. 在打开Rstudio的时候,弹出的一个安装提示
  2. 在终端里面输入
xcode-select --install

安装rJava后,无法正常使用rJava.

解决方法: 下载mac的Java环境就可以了

gfortran相关问题 (我发现Big Sur版本也可以用我百度网盘的gfortran)

  1. 安装gfortran,但是还是不能用
ld: warning: search path '/opt/gfortran/lib/gcc/aarch64-apple-darwin20.0/12.2.0' not found
ld: warning: search path '/opt/gfortran/lib' not found
ld: library 'gfortran' not found
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [harmony.so] Error 1
ERROR: compilation failed for package ‘harmony’
* removing ‘/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/harmony’
Warning message:
In i.p(...) :
  installation of package ‘/var/folders/zc/6v0fl8dj657c5cqf3_khprlc0000gn/T//RtmpTKc22n/file11bf5ee9caa5/harmony_1.2.0.tar.gz’ had non-zero exit status
  1. 通过检索,我们碰巧发现gfotran在 /usr/local/gfortran目录下
  2. 编辑配置文件,让R能够识别

编辑配置文件: ~/.R/Makevars

FC      = /usr/local/gfortran/bin/gfortran
F77     = /usr/local/gfortran/bin/gfortran
FLIBS   = -L/usr/local/gfortran/lib

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×