我有一些我运行的代码包括这部分:
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