I have a foo.R file which contains
library("ggplot2")
cat("Its working")
I am trying to run foo.r via the command line using the Rscript commandRscript --default-packages=ggplot2 foo.R and it is giving me the following error:
1: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
there is no package called ‘ggplot2’
2: package ‘ggplot2’ in options("defaultPackages") was not found
Error in library("ggplot2") : there is no package called ‘ggplot2’
Execution halted
Any help on how to load packages while running "Rscript" is much appreciated.
Rscript -e 'cat(c(.libPaths(), installed.packages()[,1]), sep = "\n")'and compare it to what you get when running that in an interactive session. SometimesRscriptis using a different R backend and / or set of libraries than you expect. - nrussellRscript foo.Rwork? - cory