R for Mac(M1)安装R包辛酸教程

欢迎收看hanhan的辛酸血泪史orz

关于R for Mac(M1)安装失败/下载后报错

前言

鬼迷心窍买了Mac,用着很爽,配置的很痛苦~

我个人觉得很多工程师程序猿应该都觉得,配置是最快乐但也是最痛苦的事情,尤其是在Win教程那么多,我却用Mac的当下。

作为一个正在努力学英语(但是依旧英语白痴)的工程师,看不懂代码,自然就会直接去百度,但是这样最大的问题是什么呢?你不知道真正的问题是什么,可能你搜的有个偏差,搜到你电脑爆炸都没搜出来。

所以在这我好心劝告,看报错吧,看懂了比啥都有用。

备注一句:要我学好英语,可能只有投胎有用了orz

1. 非零报错-have no-zero-there is no package-缺包

我在刚开始最头痛的就是这一点了,我下什么包都这个毛病,真的气死我了!!!我们特意删了个之前好不容易装好的包,来把这个报错弄出来:

> install.packages('VIM')

  There is a binary version available but the source
  version is later:
    binary source needs_compilation
VIM  6.1.0  6.1.1              TRUE

Do you want to install from sources the package which needs compilation? (Yes/no/cancel) y
installing the source package ‘VIM’

trying URL 'https://cran.rstudio.com/src/contrib/VIM_6.1.1.tar.gz'
Content type 'application/x-gzip' length 2193653 bytes (2.1 MB)
==================================================
downloaded 2.1 MB

* installing *source* package ‘VIM’ ...
** package ‘VIM’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
clang++ -arch arm64 -std=gnu++14 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I'/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/Rcpp/include' -I/opt/R/arm64/include   -fPIC  -falign-functions=64 -Wall -g -O2  -c RcppExports.cpp -o RcppExports.o
clang++ -arch arm64 -std=gnu++14 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I'/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/Rcpp/include' -I/opt/R/arm64/include   -fPIC  -falign-functions=64 -Wall -g -O2  -c gowerD.cpp -o gowerD.o
clang++ -arch arm64 -std=gnu++14 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/opt/R/arm64/lib -o VIM.so RcppExports.o gowerD.o -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
installing to /Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/00LOCK-VIM/00new/VIM/libs
** R
** data
*** moving datasets to lazyload DB
** inst
** byte-compile and prepare package for lazy loading
Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) : 
  there is no package called ‘vctrs’
Calls: <Anonymous> ... loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart
Execution halted
ERROR: lazy loading failed for package ‘VIM’
* removing ‘/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/VIM’
Warning in install.packages :
  installation of package ‘VIM’ had non-zero exit status

The downloaded source packages are in
	‘/private/var/folders/bj/w7w9z5vd3cz7vsrcfr7m0pz80000gn/T/RtmpLJq2I7/downloaded_packages’

所以这个报错究竟是发生甚么事了?我们可以看这几行:

Do you want to install from sources the package which needs compilation? (Yes/no/cancel) y
Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) : 
  there is no package called ‘vctrs’
Calls: <Anonymous> ... loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart
Execution halted
Warning in install.packages :
  installation of package ‘VIM’ had non-zero exit status

在代码中,凭肉眼觉得可能有毛病的信息有这些,我先来讲第三个-非零报错:

  • 其实看这个根本看不懂是啥毛病,但是我就是根据这个去网上搜毛病的,所以我才说要好好看报错

然后再看第二个,报错说我们没有’vctrs’这个包,他这么说我就好办了,你说没有我就装呗:

> install.packages('vctrs')
trying URL 'https://cran.rstudio.com/bin/macosx/big-sur-arm64/contrib/4.1/vctrs_0.3.8.tgz'
Content type 'application/x-gzip' length 1450121 bytes (1.4 MB)
==================================================
downloaded 1.4 MB


The downloaded binary packages are in
	/var/folders/bj/w7w9z5vd3cz7vsrcfr7m0pz80000gn/T//RtmpLJq2I7/downloaded_packages
> install.packages('VIM')

  There is a binary version available but the source
  version is later:
    binary source needs_compilation
VIM  6.1.0  6.1.1              TRUE

Do you want to install from sources the package which needs compilation? (Yes/no/cancel) y
installing the source package ‘VIM’

trying URL 'https://cran.rstudio.com/src/contrib/VIM_6.1.1.tar.gz'
Content type 'application/x-gzip' length 2193653 bytes (2.1 MB)
==================================================
downloaded 2.1 MB

* installing *source* package ‘VIM’ ...
** package ‘VIM’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
clang++ -arch arm64 -std=gnu++14 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I'/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/Rcpp/include' -I/opt/R/arm64/include   -fPIC  -falign-functions=64 -Wall -g -O2  -c RcppExports.cpp -o RcppExports.o
clang++ -arch arm64 -std=gnu++14 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I'/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/Rcpp/include' -I/opt/R/arm64/include   -fPIC  -falign-functions=64 -Wall -g -O2  -c gowerD.cpp -o gowerD.o
clang++ -arch arm64 -std=gnu++14 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/opt/R/arm64/lib -o VIM.so RcppExports.o gowerD.o -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
installing to /Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/00LOCK-VIM/00new/VIM/libs
** R
** data
*** moving datasets to lazyload DB
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (VIM)

The downloaded source packages are in
	‘/private/var/folders/bj/w7w9z5vd3cz7vsrcfr7m0pz80000gn/T/RtmpLJq2I7/downloaded_packages’

wow,我们装好了,所以其实现在没装好的原因是我们缺包了,我们把包装上就好了。所以看报错很重要

那我们遇到这种问题,把提出来的Error都处理了就好了。

(备注:关于上面的问题,因为我只删除了VIM包和vctrs这两个包,所以只要安装vctrs就可以了,但其实最开始有更多包没装,所以要根据报错一个一个装哦)

但我列出来了都第一条:我们在最开始选择的yes/no/cancel。这个有什么问题呢,话说有没有想过为什么有三个选项呢?我放下一节来讲。

2. 安装失败-install from sources the package-下载源文件

我在非零报错那里讲到的一个问题,就是我们有一个选择:yes/no/cancel。一般也就是装或不装,为什么有三个呢?我考虑到了,但是还有点小问题,看下面吧:

Do you want to install from sources the package which needs compilation? (Yes/no/cancel) 

看意思就是,我们是否要从包里下源文件,下源文件这一点就让我这个小白没懂了。根据我在网上看到大佬们的信息了,确认了这里选择yes是下载源文件,选择no是下载一个普通的二进制文件,选择cancel才是真的取消。

所以其实我们在这里选择no就能把包下好了,然后为了演示,我再删一次~

> install.packages('VIM')

  There is a binary version available but the source
  version is later:
    binary source needs_compilation
VIM  6.1.0  6.1.1              TRUE

Do you want to install from sources the package which needs compilation? (Yes/no/cancel) n
trying URL 'https://cran.rstudio.com/bin/macosx/big-sur-arm64/contrib/4.1/VIM_6.1.0.tgz'
Warning in install.packages :
  URL 'https://cran.rstudio.com/bin/macosx/big-sur-arm64/contrib/4.1/VIM_6.1.0.tgz': status was 'SSL connect error'
Error in download.file(url, destfile, method, mode = "wb", ...) : 
  cannot open URL 'https://cran.rstudio.com/bin/macosx/big-sur-arm64/contrib/4.1/VIM_6.1.0.tgz'
Warning in install.packages :
  download of package ‘VIM’ failed

woc,发生甚么事了?没事,就是一个连接错误,~~开错门了,~~我们再来一次:

> install.packages('VIM')

  There is a binary version available but the source
  version is later:
    binary source needs_compilation
VIM  6.1.0  6.1.1              TRUE

Do you want to install from sources the package which needs compilation? (Yes/no/cancel) n
trying URL 'https://cran.rstudio.com/bin/macosx/big-sur-arm64/contrib/4.1/VIM_6.1.0.tgz'
Content type 'application/x-gzip' length 2655013 bytes (2.5 MB)
==================================================
downloaded 2.5 MB


The downloaded binary packages are in
	/var/folders/bj/w7w9z5vd3cz7vsrcfr7m0pz80000gn/T//Rtmph1ZFTh/downloaded_packages

立刻重来了一次,我们就成功了。

但是!我一开始也这样试过了,为啥我放弃了呢?因为我是用不了,而且我又没看懂报错。。。。Orz。。。:

> library(VIM)
Loading required package: colorspace
Loading required package: grid
Error: package or namespace load failed for ‘VIM’ in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]):
 there is no package called ‘vctrs’

wok,报错用不来哦,但其实这里没啥问题,看一下报错就知道了啊!就是没有’vctrs’包而已嘛,和下载源码文件的时候是一样的,没有就装啊:

> install.packages('vctrs')
trying URL 'https://cran.rstudio.com/bin/macosx/big-sur-arm64/contrib/4.1/vctrs_0.3.8.tgz'
Content type 'application/x-gzip' length 1450121 bytes (1.4 MB)
==================================================
downloaded 1.4 MB


The downloaded binary packages are in
	/var/folders/bj/w7w9z5vd3cz7vsrcfr7m0pz80000gn/T//Rtmph1ZFTh/downloaded_packages
> library(VIM)
VIM is ready to use.

Suggestions and bug-reports can be submitted at: https://github.com/statistikat/VIM/issues

Attaching package: ‘VIM’

The following object is masked from ‘package:datasets’:

    sleep

看,我们装好就能用了,所以这个报错就这样解决!

3. 关于我尚未解决的问题

其实和上面一样的报错,我这回是想下载链接数据库的包:‘RODBC’。

我一样先直接安装:

> install.packages('RODBC')
Package which is only available in source form, and
  may need compilation of C/C++/Fortran: ‘RODBC’
Do you want to attempt to install these from sources? (Yes/no/cancel) Y
installing the source package ‘RODBC’

trying URL 'https://cran.rstudio.com/src/contrib/RODBC_1.3-17.tar.gz'
Content type 'application/x-gzip' length 1171335 bytes (1.1 MB)
==================================================
downloaded 1.1 MB

* installing *source* package ‘RODBC’ ...
** package ‘RODBC’ successfully unpacked and MD5 sums checked
** using staged installation
checking for gcc... clang -arch arm64
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether clang -arch arm64 accepts -g... yes
checking for clang -arch arm64 option to accept ISO C89... none needed
checking how to run the C preprocessor... clang -arch arm64 -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... rm: conftest.dSYM: is a directory
rm: conftest.dSYM: is a directory
yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking sql.h usability... no
checking sql.h presence... no
checking for sql.h... no
checking sqlext.h usability... no
checking sqlext.h presence... no
checking for sqlext.h... no
configure: error: "ODBC headers sql.h and sqlext.h not found"
ERROR: configuration failed for package ‘RODBC’
* removing ‘/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/RODBC’
Warning in install.packages :
  installation of package ‘RODBC’ had non-zero exit status

The downloaded source packages are in
	‘/private/var/folders/bj/w7w9z5vd3cz7vsrcfr7m0pz80000gn/T/RtmpdQTPu2/downloaded_packages’

我们一样找老问题,不行我先试了一下下载二进制包,哦吼,没有二进制包。只能用yes解决了。。。

然后看这行:

configure: error: "ODBC headers sql.h and sqlext.h not found"
ERROR: configuration failed for package ‘RODBC’

看懂了就是,我们没有sql.h 和 sqlext.h 这两个头文件。缺失看懂了,但是我根据网上的各种方法试过了,下载了unixodbc,安装了好几种东西,还是没用。我就放弃了…Orz


就到这了,如果遇到了问题再更~

希望大家都能解决好问题,然后我就可以参考了QAQ

  • 9
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
要在Mac M1芯片上安装R语言,首先需要下载并安装R语言和RStudio。您可以从官方网站下载R语言Mac版本,然后按照安装向导进行安装。接下来,您可以从RStudio的官方网站下载RStudio,并按照相同的方式进行安装安装R语言和RStudio后,您可以在RStudio中创建一个新项目来开始使用R语言。在R语言中,您可以使用"#"符号来表示注释,这部分内容不会被编译。另外,您可以使用"="或"<-"符号来为变量赋值,但通常推荐使用"<-"符号,同时在符号前后留有空格。 在R语言中,常用的指令括查询的版本、安装和卸载。例如,使用"packageVersion"函数可以查询指定的版本,使用"install.packages"函数可以安装,使用"remove.packages"函数可以卸载。 对于Windows XP(括Windows 2000)系统的用户,您可以使用控制台命令来安装修复R语言。具体方法是将XP(2000)的光盘放入计算机,选择R进行修复。控制台命令是一种在系统出现意外情况时进行诊断、测试和恢复的工具。 总结起来,要在Mac M1芯片上安装R语言,您需要按照正确的顺序下载并安装R语言和RStudio,然后在RStudio中创建新项目开始使用R语言。如果您是Windows XP(括Windows 2000)用户,您可以使用控制台命令来进行R语言的修复。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [R语言(一):Mac系统M1芯片下安装R语言和RStudio教程R语言入门,namespace ‘Matrix’ 1.4-1 is already ...](https://blog.csdn.net/crist_meng/article/details/127747384)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [网管教程 从入门到精通软件篇.txt](https://download.csdn.net/download/a525235942/2284257)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值