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。 –