Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I install an R package under another name?

Tags:

installation

r

I'm using R 3.4.1 on Red Hat Enterprise Linux 6. I have version 3.0 of package asreml installed under /tools/bioinfo/app/R-3.4.1/lib64/R/library.

> library(asreml)
Loading required package: lattice
Checking for license <redacted>

> .libPaths()
[1] "/tools/bioinfo/app/R-3.4.1/lib64/R/library"

Version 4 of that package has now come out, but we would like to compare the results of version 3 with version 4. To that end, we would like to have version4 installed on our system as asreml4. I have downloaded the *tar.gz file with the latest version, but if I do

R CMD INSTALL asreml_4.1.0.93.tar.gz

it installs it in the asreml folder, overwriting the old version. That's not what I want.

I've also tried to install it in another place, rename the folder to asreml4, and copy that folder to /tools/bioinfo/app/R-3.4.1/lib64/R/library and then tried to load it, but then it loads the wrong version:

> library(asreml, lib.loc="/tools/bioinfo/app/R-3.4.1/lib64/R/library/asreml4")
> packageVersion("asreml")
[1] ‘3.0.1’

So, how do I install it in an asreml4folder in such a way that I can call it with library(asreml4)?

like image 331
BioGeek Avatar asked Sep 21 '18 15:09

BioGeek


People also ask

How do I change where R packages are installed?

R uses a single package library for each installed version of R on your machine. Fortunately it is easy to modify the path where R installs your packages. To do this, you simply call the function . libPaths() and specify the library location.


1 Answers

1) edit DESCRIPTION Download the source, edit the DESCRIPTION file to have a different name and then build and install it.

2) separate library Alternately install the new version into a separate library and then use one of these to get the desired version:

library(asreml, lib = ...)
library(asreml)

2a) .libPaths A variation of this is to use .libPaths(new) to change the default library path, issue

library(asreml)

and then change it back.

2b) dev_mode An easy way to accomplish the library switching is to use dev_mode() without arguments (from the devtools package). After the first dev_mode() command is issued the default library becomes ~/R-dev . At that point install the new version of asrmel using an ordinary install.packages command without specifying lib= and it will be installed into ~/R-dev. Loading it using library without specifying a library will cause it to look into ~/R-dev first. Then test it out and finally when you are ready to switch back to the original library and original asreml issue dev_mode() again. dev_mode() manipulates the default library paths so you can use .libPaths() without arguments at any time to check what the current default is.

library(devtools)
dev_mode() # ~/R-dev now default library
# ...
dev_mode() # restore usual default library
like image 173
G. Grothendieck Avatar answered Oct 03 '22 21:10

G. Grothendieck