I have some code that I run that includes this part:

if (!require("yaml")) {
  install.packages("yaml") 
  library("yaml")
}

When I run in it rstudio, everything runs seamlessly and there are no bugs. However, when I try running my code on the command line, I get this error:

$ 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
Edit
Report