Installing R packages locally: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
m (<source> to <pre> to fix code blocks) |
||
Line 6: | Line 6: | ||
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): | 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" | 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. | 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 | If necessary, create a place for your R libraries | ||
< | <pre> | ||
mkdir ~/R ~/R/library # Only need do this once | mkdir ~/R ~/R/library # Only need do this once | ||
</ | </pre> | ||
Set your R library path | Set your R library path | ||
< | <pre> | ||
echo 'R_LIBS_USER="~/R/library"' > $HOME/.Renviron | echo 'R_LIBS_USER="~/R/library"' > $HOME/.Renviron | ||
</ | </pre> | ||
== Installing to a local library search location == | == Installing to a local library search location == | ||
Start up R: | Start up R: | ||
< | <pre> | ||
R # Invoke R | 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. | 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") | install.packages("name-of-your-package",lib="~/R/library") | ||
</ | </pre> | ||
== See also == | == See also == |
Revision as of 14:53, 15 June 2023
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):
R_LIBS_USER="~/R/library"
This specifies a keyword (R_LIBS_USER
) 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
mkdir ~/R ~/R/library # Only need do this once
Set your R library path
echo 'R_LIBS_USER="~/R/library"' > $HOME/.Renviron
Installing to a local library search location
Start up R:
R # Invoke R
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.
install.packages("name-of-your-package",lib="~/R/library")
See also
- Control R environment on the cluster using modules
- Using parallel R workloads under SLURM
- Bioinformatics tips, tricks, and workflows