Skip to main content

R Packages Notes

We tend to install R with all the packages, so if you're finding one make sure that you are seeing the default install path. 

To see the installed packages (from an R prompt):

> installed.packages();

To find just one (one example of when it's there, another of when it's not):

> find.package("ggplot2")
[1] "/usr/lib64/R/library/ggplot2"

> find.package("ggplot3")
Error in find.package("ggplot3") : there is no package called ‘ggplot3’

To see the library paths:

> .libPaths()
[1] "/usr/lib64/R/library"                               
[2] "/usr/share/R/library"    

To add library paths:

libPaths(c( .libPaths(), "/usr/local/lib/R/site-library", "/usr/lib/R/site-library" ,"/usr/lib/R/library"))

To load the library (note, no quotes):

> library(data.table)
data.table 1.14.8 using 32 threads (see ?getDTthreads).  Latest news: r-datatable.com

 

Install a package to your user path

If there's a package you want that is not installed, you can add a user-specific path and install the package there. This setup allows the specified user to manage their own R packages independently of system-wide installations, and without needing administrative rights.

1) Set the Library Path in R: You can set the library path in your R session using the .libPaths() function. Add the following line to your R script or enter it in the R console:

.libPaths("~/Rlibs")

2) now install a package and specify where to install it

install.packages("ggplot2", lib="~/Rlibs")

When you want to use the packages, make sure that R knows where to find them. You may need to set the library path again in any new R session where you want to use these packages.