安装非CRAN包时,需要将CRAN镜像作为参数传递给install.packages函数。例如:
install.packages("devtools")
library(devtools)
install_github("hadley/ggplot2")
在安装第3个包时,会得到一个警告消息,指出:
Installing github repo(s) ggplot2/master from hadley
Downloading github repo hadley/ggplot2@master
Installation of package hadley/ggplot2@master failed:
Installation of non-CRAN package requires CRAN mirror
要解决这个问题,需要指定一个CRAN镜像,例如:
install_github("hadley/ggplot2", dependencies = TRUE, repos = "http://cran.us.r-project.org")
在这个示例中,将CRAN镜像指定为"http://cran.us.r-project.org"。如果想使用其他的CRAN镜像,只要将repos选项设置为其他URL即可。