Where Does R Store Packages

Where does R store packages?

The install.packages command looks through the .libPaths variable. Here's what mine defaults to on OSX:

> .libPaths()
[1] "/Library/Frameworks/R.framework/Resources/library"

I don't install packages there by default, I prefer to have them installed in my home directory. In my .Rprofile, I have this line:

.libPaths( "/Users/tex/lib/R" )

This adds the directory "/Users/tex/lib/R" to the front of the .libPaths variable.

Where are the installed R packages?

You can view the location by running the following:

.libPaths()
#[1] "C:/Users/ujjwal/Documents/R/win-library/3.1" "C:/Program Files/R/R-3.1.1/library"

R packages are installed into libraries, which are directories in the file system containing a subdirectory for each package installed there.

R comes with a single library, R_HOME/library which is the value of the R object .Library containing the standard and recommended packages. At the lowest level .libPaths() can be used to add paths to the collection of libraries or to report the current collection.

R will automatically make use of a site-specific library R_HOME/site-library if this exists. This location can be overridden by setting .Library.site in R_HOME/etc/Rprofile.site. For more details see here.

Where does R (for Windows) store packages before it installs them?

From the documentation for install.package :

destdir (parameter, default=NULL) : directory where downloaded packages are stored. If it is NULL (the default) a subdirectory downloaded_packages of the session temporary directory will be used (and the files will be deleted at the end of the session).

The session's temp dir mentioned above is given by tempdir() command

Where are objects stored in R packages?

Variables can also be created in a normal R script of the package with foo <- new.env() and then populated with content, e.g.

foo <- new.env()

foo <- data.frame(
x=1:10,
y <- rnorm(10)
)

It is also possible to make the internal data hidden, e.g. .foo. As an example CRAN package marelac uses this mechanism in files aaa.R, gas_schmidt.R and some others.

Another possibility is a file sysdata.rda that can be placed in the /Rfolder, see: https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Package-subdirectories

How do I change the default library path for R packages

See help(Startup) and help(.libPaths) as you have several possibilities where this may have gotten set. Among them are

  • setting R_LIBS_USER
  • assigning .libPaths() in .Rprofile or Rprofile.site

and more.

In this particular case you need to go backwards and unset whereever \\\\The library/path/I/don't/want is set.

To otherwise ignore it you need to override it use explicitly i.e. via

library("somePackage", lib.loc=.libPaths()[-1])

when loading a package.



Related Topics



Leave a reply



Submit