Rscript: There Is No Package Called ...

Rscript: There is no package called ...?

In short, the value returned by calling Sys.getenv('R_LIBS_USER') in R.exe needs to be the same as the value returned by calling this at the command line:

Rscript.exe -e "Sys.getenv('R_LIBS_USER')"

and the above value needs to be included in this command line call:

Rscript.exe -e ".libPaths()"

Note that the values of R_LIBS_USER may be differ between R.exe and Rscript.exe if the value of R_USER is changed, either in the .Rprofile or the in target field of user's shortcut to R.exe, and in general, I find that the user library (i.e. .libPaths()[2]) is simply not set in Rscript.exe

Since I'm fond of setting R_USER to my USERPROFILE, I include the following block in at the top of .R files that I wish to run on mulitiple computers or in Rscript.exe's .Rprofile (i.e. Rscript -e "path.expand('~/.Rprofile')"):

# =====================================================================
# For compatibility with Rscript.exe:
# =====================================================================
if(length(.libPaths()) == 1){
# We're in Rscript.exe
possible_lib_paths <- file.path(Sys.getenv(c('USERPROFILE','R_USER')),
"R","win-library",
paste(R.version$major,
substr(R.version$minor,1,1),
sep='.'))
indx <- which(file.exists(possible_lib_paths))
if(length(indx)){
.libPaths(possible_lib_paths[indx[1]])
}
# CLEAN UP
rm(indx,possible_lib_paths)
}
# =====================================================================

Error: there is no package called ... and trying to use install.packages to solve it


Error in library(readr) : there is no package called 'readr'

This means that you don't have the package readr installed on your computer.

You then installed it with

install.packages('readr', dependencies = TRUE, repos='http://cran.rstudio.com/')

which is good. Most packages are not "stand-alone", they use other packages too, called dependencies. Because you used the default dependencies = TRUE, all the dependencies (and their dependencies) were also installed.

You can look at the CRAN page for readr: https://CRAN.R-project.org/package=readr to see its dependencies (anything in the "Depends" or "Imports" fields is required). And of course you need the dependencies of those dependencies, etc. Now that readr is installed along with its dependencies, you can run library(readr) to load it.



Related Topics



Leave a reply



Submit