R 更换package安装源

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/chang349276/article/details/79295821

有时候利用R安装R包,出现错误:

Warning in install.packages :
  unable to access index for repository https://cran.rstudio.com/src/contrib:
  cannot open URL 'https://cran.rstudio.com/src/contrib/PACKAGES'
Warning in install.packages :
  package ‘readxl’ is not available (for R version 3.4.1)

可能是因为国外的rstudio或者其他源链接不上,此时换成国内源即可解决问题,更换方法如下:

##1. 使用Rstudio
打开
tool -> Global options -> packages

##2. 使用终端

在使用终端命令行安装包的时候,可以直接指定源,命令如下:

install.packages(‘gdata’, repos = ‘https://mirrors.tuna.tsinghua.edu.cn/CRAN’)

##3. 更改配置文件
linux或mac系统下,安装速度过慢,更改为国内源方案,编辑~/.Rprofile, 指定国内CRAN源:

options(repos=structure(c(CRAN=“https://mirrors.tuna.tsinghua.edu.cn/CRAN/”)))

指定国内bioconductor源:

source(“http://bioconductor.org/biocLite.R”)
options(BioC_mirror=“http://mirrors.ustc.edu.cn/bioc/”)
biocLite(“clusterProfiler”)

通过Rprofile自定义函数:

扫描二维码关注公众号,回复: 6067915 查看本文章
source.bioconductor <- function(){
            source("http://bioconductor.org/biocLite.R")
            options(BioC_mirror="http://mirrors.ustc.edu.cn/bioc/") 
}

通过调用source.bioconductor()函数,改变源并安装包

猜你喜欢

转载自blog.csdn.net/chang349276/article/details/79295821