我运行的一些代码包括以下部分:
if (!require("yaml")) {
install.packages("yaml")
library("yaml")
}
当我在rstudio中运行时,一切都无缝运行,没有bug.但是,当我try 在命令行上运行代码时,会出现以下错误:
$ 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