R包安装报错的解决方法

无法下载

换源

install.packages("tidyverse",repo="https://mirrors.tuna.tsinghua.edu.cn/CRAN/")#清华镜像
#其他镜像
#http://mirrors.opencas.cn/cran/
#或直接
options(repos=structure(c(CRAN="https://mirrors.tuna.tsinghua.edu.cn/CRAN/")))

依赖包的问题

依赖包未安装

install.packages("tidyverse",dependencies=TRUE)

依赖包版本不对

install.packages("rlang")#相当于重新安装
update.packages("rlang")#更新包
installed.packages()["rlang",c('Package','Version')]#查看当前版本

通过以上方式依然版本不对,观察binary和source的版本是否不一样,默认是binary安装,若source版本比较新,需要手动通过source安装

install.packages("rlang",type="source")

因为只有不含“C/C++/Fortran”代码的R包能够通过source安装,当R包含有“C/C++/Fortran”代码时,提示编译失败,如果是Windows系统,需要安装Rtools。建议不要更改默认路径,不然之后还得报错。

检查Rtools是否已经安装

system('g++ -v')
system('where make')

不行再看看环境变量,是不是3个都加上去了,然后再重启电脑。
在这里插入图片描述在这里插入图片描述

依赖包与当前R版本不匹配

典型报错信息

packages ‘locfit’ are not available (for R version 3.4.3)

然后可以去看看 cran 上面最新的版本对 R 的要求是不是比较高

解决方法

  1. 安装旧版本
install.packages("https://cran.r-project.org/src/contrib/Archive/locfit/locfit_1.5-9.2.tar.gz",repos = NULL)
  1. 更新R
library(installr)
updateR()

猜你喜欢

转载自blog.csdn.net/Alleine/article/details/103625553
今日推荐