I have some code that I run that includes this part:
if (!require(\"yaml\")) {
install.packages(\"yaml\")
library(\"yaml\")
}
When I run i
RStudio sets a default repository when you call install.packages
from within RStudio. When you run the script via the command line, you have to tell R which repository to use (or set a global default repository).
You can easily fix this problem by telling R to use your favorite repository.
For example, if you want to use RStudio's package repository, set repos="http://cran.rstudio.com/"
inside the install.packages
call.
if (!require("yaml")) {
install.packages("yaml", repos="http://cran.rstudio.com/")
library("yaml")
}
This should work!