rstudio - Package error when running r code on command line -


i have code run includes part:

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

when run in rstudio, runs seamlessly , there no bugs. however, when try running code on command line, error:

$ rscript.exe file.r loading required package: yaml installing package(s) ‘/usr/lib/r/site-library’ (as ‘lib’ unspecified) error in contrib.url(repos, type) :   trying use cran without setting 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 no package called ‘yaml’ execution halted 

rstudio sets default repository when call install.packages within rstudio. when run script via command line, have tell r repository use (or set global default repository).

you can fix problem telling r use favorite repository.

for example, if want use rstudio's package repository, set repos="http://cran.rstudio.com/" inside install.packages call.

if (!require("yaml")) {   install.packages("yaml", repos="http://cran.rstudio.com/")    library("yaml") } 

this should work!


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -