R代码里面,当我有一些代码,我运行,其中包括这一部分:包的错误运行在命令行
if (!require("yaml")) {
install.packages("yaml")
library("yaml")
}
当我在它rstudio运行,一切都无缝地运行,并没有错误。然而,当我尝试在命令行中运行我的代码,我得到这个错误:
$ Rscript.exe file.R
Loading required package: yaml
Installing package(s) into ‘/usr/lib/R/site-library’
(as ‘lib’ is unspecified)
Error in contrib.url(repos, type) :
trying to use CRAN without setting a mirror
Calls: install.packages -> grep -> contrib.url
In addition: Warning message:
In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
there is no package called ‘yaml’
Execution halted
阅读此处:'尝试在'install.packages'中不使用镜像'并且特别是'repos'参数来使用CRAN。 –