I am trying to plan to deploy an R script that I have developed in RStudio for use at the Windows command line with Rscript and I am having problems with the libraries and library paths (presumably).
Is there a straightforward approach to handling this?
My scripts use: dplyr, pdftools, lubridate, and data.table libraries.
When I run it in RStudio, it seems to run fine.
When I try to run the straightforward approach to this code, I get:
C:\Users\...\Documents\Analytics\data2>Rscript HCCReport.R throw-away
Loading required package: pdftools
Loading required package: dplyr
Loading required package: lubridate
Error in library(pdftools) : there is no package called 'pdftools'
Calls: source ... eval -> source -> withVisible -> eval -> eval -> library
In addition: Warning messages:
1: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
there is no package called 'pdftools'
2: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
there is no package called 'dplyr'
3: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
there is no package called 'lubridate'
Execution halted
C:\Users\...\Documents\Analytics\data2>Rscript -e print(.Library)
[1] "C:/Users/.../Documents/Analytics/dist/R-Portable/App/R-Portable/library"
I have looked around online for different suggestions which seem to be along the lines of adding different R library paths to a library path. But when I try to put that code into the script it doesn't seem to make a difference:
.libPaths(c("C:/Users/.../Documents/Analytics/dist/R-Portable/App/R-Portable/library",
"C:/Users/.../Documents/R/R-3.4.4/library", .libPaths()))
print(.libPaths())
# [1] "C:/Users/.../Documents/Analytics/dist/R-Portable/App/R-Portable/library"
# [2] "C:/Users/.../Documents/R/R-3.4.4/library"
Run with Rscript at the command line I get:
C:\Users\...\Documents\Analytics\data2>Rscript HCCReport.R CCD_XXX_YYYY_2018-12-20.pdf
[1] "C:/Users/.../Documents/Analytics/dist/R-Portable/App/R-Portable/library"
[2] "C:/Users/.../Documents/R/R-3.4.4/library"
Loading required package: pdftools
Loading required package: dplyr
Loading required package: lubridate
Error in library(pdftools) : there is no package called 'pdftools'
Calls: source ... eval -> source -> withVisible -> eval -> eval -> library
In addition: Warning messages:
1: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
there is no package called 'pdftools'
2: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
there is no package called 'dplyr'
3: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
there is no package called 'lubridate'
Execution halted
Thanks in advance for your comments.