我有一些代码需要运行,其中包括以下部分:
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