选择最快的R镜像

12

https://mp.weixin.qq.com/s/JzTVIRg0pHeHrdMMmGVaNw

速度越快,越节省生命。看到y叔一篇推文,详细记录一下。

1.镜像源设置的优先级

可以在home目录或者rstudio设置里,进行镜像源设置。

~/.Rprofile 优于 Rstudio-tools-Global Options-Packages-Primary CRAN repository

即如果在~/.Rprofile中设置了,Rstudio设置中无论怎么调整都不管用。(应该是这样,没详细去检查)

2.选择最快的镜像源

#install.packages("mirrorselect")
library(mirrorselect)
# 查看中国镜像源
get_mirror(country = "cn") 
# 测速中国镜像源
mirrorselect(get_mirror(country = "cn"))
#                                        mirror speed
# 1            https://mirrors.pku.edu.cn/CRAN/ 0.194
# 2  https://mirrors.tuna.tsinghua.edu.cn/CRAN/ 0.196
# 3           https://mirrors.hust.edu.cn/CRAN/ 0.302
# 4           https://mirrors.ustc.edu.cn/CRAN/ 0.319
# 5        https://mirrors.sustech.edu.cn/CRAN/ 0.367
# 6            https://mirrors.nju.edu.cn/CRAN/ 0.370
# 7     https://mirrors.sjtug.sjtu.edu.cn/cran/ 0.411
# 8         https://mirrors.e-ducation.cn/CRAN/ 0.419
# 9            https://mirrors.zju.edu.cn/CRAN/ 0.439
# 10         https://mirrors.nwafu.edu.cn/cran/ 0.688
# 11          https://mirrors.bfsu.edu.cn/CRAN/ 0.746
# 12           https://mirrors.qlu.edu.cn/CRAN/ 2.830

# 可以看到北大第一,清华第二,虽然我在上海。

3.设置镜像源

home中还可以设置bioconductor的镜像源,Rstudio点一点虽然方便,但好像没有设置bioconductor的地方?所以还是麻烦一点在home里设置吧。

设置后重启R生效。

3.1 home目录中设置

vim ~/.Rprofile
# 键入以下内容
options(BioC_mirror="https://mirrors.pku.edu.cn/bioconductor")
options(repos = c(CRAN="https://mirrors.pku.edu.cn/CRAN/"))

3.2 Rstudio中点一点设置

Rstudio —— tools —— Global Options —— Packages —— Primary CRAN repository