Installing R packages locally: Difference between revisions

From HPCwiki
Jump to navigation Jump to search
No edit summary
Phase 1 § 5 P1.5.6: content merged into R (via update-page on MediaWiki MCP Server)
Tag: New redirect
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 
#REDIRECT [[R#Local package library]]
 
== Specifying a local library search location ==
 
Specify a local library search location.
 
You can use several library trees of add-on packages. The easiest way to tell R to use these via a 'dotfile' by creating the following file '$HOME/.Renviron' (watch the quotes and ~ character):
<pre>
  R_LIBS_USER="~/R/library"
</pre>
This specifies a keyword (<code>R_LIBS_USER</code>) which points to a colon-separated list of directories at which R library trees are rooted. You do not have to specify the default tree for R packages.
 
If necessary, create a place for your R libraries
<pre>
  mkdir ~/R ~/R/library        # Only need do this once
</pre>
Set your R library path
<pre>
  echo 'R_LIBS_USER="~/R/library"' >  $HOME/.Renviron
</pre>
== Installing to a local library search location ==
 
Start up R:
 
<pre>
  R                    # Invoke R
</pre>
Then, from the R environment, install the packages you require while pointing at the root R-package directory of choice. This example will install from CRAN.
<pre>
install.packages("name-of-your-package",lib="~/R/library")
</pre>
== Installing and using a local library from a JuPyteR notebook ==
 
[[File:R_libpaths.png]]
== See also ==
* [[Control_R_environment_using_modules | Control R environment on the cluster using modules]]
* [[Parallel_R_code_on_SLURM | Using parallel R workloads under SLURM]]
* [[Bioinformatics_tips_tricks_workflows | Bioinformatics tips, tricks, and workflows]]
 
== External links ==
[http://csg.sph.umich.edu/docs/R/localpackages.html source for material for this aricle]
 
[http://cran-mirror.cs.uu.nl CRAN homepage]
 
[http://en.wikipedia.org/wiki/R_(programming_language) R article from Wikipedia]

Latest revision as of 14:08, 16 June 2026