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
Is There a Logical Way to Think About List Indexing
Deploying R Shiny App as a Standalone Application
How to Extract the Fill Colours from a Ggplot Object
Removing Multiple Columns from R Data.Table with Parameter for Columns to Remove
R Ggplot2 - How to Specify Out of Bounds Values' Colour
R Grep: Is There an and Operator
Shift Values in Single Column of Dataframe Up
How to Spread or Cast Multiple Values in R
Calculate Group Mean While Excluding Current Observation Using Dplyr
How to Convert Time (Mm:Ss) to Decimal Form in R
Add Percentage Labels to a Stacked Barplot
Passing Several Arguments to Fun of Lapply (And Others *Apply)
How to Document Data Sets with Roxygen
How to Get Unsaved Script Tabs
Reverse Datetime (Posixct Data) Axis in Ggplot
Rename Multiple Columns Given Character Vectors of Column Names and Replacement