• Skip to secondary menu
  • Skip to main content
  • Skip to primary sidebar

Python and R Tips

Learn Data Science with Python and R

  • Home
  • Python
  • Pandas
    • Pandas 101
  • tidyverse
    • tidyverse 101
  • R
  • Linux
  • Conferences
  • Python Books
  • About
    • Privacy Policy
You are here: Home / R / How To Install a R Package Locally and Load it Easily?

How To Install a R Package Locally and Load it Easily?

May 17, 2012 by cmdlinetips


R LogoR has been one of the popular languages for anything to do with large amount of data. There are loads of useful packages that let you get started immediately in using a wide realm of statistical/computational tools. Installing an R package is easy. Typically, R Packages can be downloaded as “tar.gz” file for Mac OS X from CRAN sources. The command to install a R package to all users in your machine is

R CMD INSTALL -l  myRPackage.tar.gz 

Local Installation of R Packages

Sometimes you might want to install a R package locally, either because you may not have root access to install a package globally or you may just want to try out a new package before installing globally. Here is how to install a R package locally from the terminal.

To install a R package locally, specify the local directory where you want to install by using the “-l” option in the “R CMD INSTALL” command. For example, to install the R package in the local directory “/usr/me/localR/library”, use the “R CMD INSTALL” as follows.

R CMD INSTALL -l /usr/me/localR/library myRPackage.tar.gz 

How to Load a Locally Installed R Package and Use it?

Installing R Packages at a local directory is only a first step. There are a few ways to load the locally installed R packages and use them. One option is to specify the local path to the R package while loading the library. The R command to load a general package is

library("RPackage")

To load a locally installed R package, use the library command with parameter lib.loc as

library("myRPackage", lib.loc="/usr/me/local/R/library")

Another option is to instruct your .bashrc file to add the the path to local R library. This option lets you load the package without specifying the local every time. To enable this add the following to your .bashrc

if [ -n $R_LIBS ]; then
   export R_LIBS=/usr/me/local/R/library:$R_LIBS
else
   export R_LIBS=/usr/me/local/R/library
fi

After adding you can check if the local R package directory in the R library path using the R command “.libPaths()“. Typing “.libPaths()” in R, will show all the R library paths. If your local R library path is not added properly, you will only see one general path to R library, like “/opt/R/2.11.1/lib64/R/library”.

Share this:

  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on X (Opens in new window) X

Related posts:

Default ThumbnailHow to Install Packages from the Jupyter Notebook? Learn to make a simple R packageHow to Make a R Package from Scratch using RStudio Default Thumbnailvega_datasets: A Python Package for Datasets Default ThumbnailInstalling Python 3 from Python 2 with Anaconda

Filed Under: R, R Local Package, R Tips Tagged With: Install R Local Package, R, R Tips

Primary Sidebar

Subscribe to Python and R Tips and Learn Data Science

Learn Pandas in Python and Tidyverse in R

Tags

Altair Basic NumPy Book Review Data Science Data Science Books Data Science Resources Data Science Roundup Data Visualization Dimensionality Reduction Dropbox Dropbox Free Space Dropbox Tips Emacs Emacs Tips ggplot2 Linux Commands Linux Tips Mac Os X Tips Maximum Likelihood Estimation in R MLE in R NumPy Pandas Pandas 101 Pandas Dataframe Pandas Data Frame pandas groupby() Pandas select columns Pandas select_dtypes Python Python 3 Python Boxplot Python Tips R rstats R Tips Seaborn Seaborn Boxplot Seaborn Catplot Shell Scripting Sparse Matrix in Python tidy evaluation tidyverse tidyverse 101 Vim Vim Tips

RSS RSS

  • How to convert row names to a column in Pandas
  • How to resize an image with PyTorch
  • Fashion-MNIST data from PyTorch
  • Pandas case_when() with multiple examples
  • An Introduction to Statistical Learning: with Applications in Python Is Here
  • 10 Tips to customize ggplot2 title text
  • 8 Plot types with Matplotlib in Python
  • PCA on S&P 500 Stock Return Data
  • Linear Regression with Matrix Decomposition Methods
  • Numpy’s random choice() function

Copyright © 2025 · Lifestyle Pro on Genesis Framework · WordPress · Log in

Go to mobile version