User Tools

Site Tools


mbstring extension must be loaded in order to run mPDF
r_antsr_usage

This is an old revision of the document!


R

Managing Packages

Managing packages:

R can read packages from any of the locations listed in .libPaths(). This typically contains both a system directory (under /share/apps) and a user directory (under /home). Both of these can vary over time; the system packages may be upgraded, added, or removed. Further, individual users might run the same code with different local versions of the same library.

To avoid this, use the packrat package (https://rstudio.github.io/packrat/). This creates a private repository of packages specific to a particular project. This allows other users (or yourself at a later date) to reproduce results with a common set of packages.

Packages that don't affect the outcome of studies, like roxygen2 or ggplot2, can be defined as “external packages”, and loaded from another source. This is useful to avoid keeping multiple copies of such packages for multiple projects.

''unsupported URL scheme'' - package installation issue

When installing a package using an https URL, you may see this:

> install.packages("mclust", repos="https://cran.cnr.berkeley.edu/")
Installing package into ‘/share/apps/ANTsR/20140930-R3.1.1-lib’
(as ‘lib’ is unspecified)
Warning: unable to access index for repository https://cran.cnr.berkeley.edu/src/contrib:
  unsupported URL scheme

This seems to be an R issue relating to SSL/HTTPS connections. Here's a workaround:

options(download.file.method = "wget")

This will tell R to use the wget command for downloads.

ANTsR

Installing from R

(Thanks to Phil Cook! Updated 4/2017)

Setup in your .bash_profile file:

export PATH=/share/apps/R/<R version>/:$PATH  #note that this may already be defined in .bash_profile, check first

Then on chead

[...]# R

> install.packages("devtools", repos="http://cran.cnr.berkeley.edu/")
> library(devtools)
> install_github("stnava/ITKR")
> install_github("stnava/ANTsRCore")
> install_github("stnava/ANTsR")

NOTE about R_LIBS environment variable:

As of R 3.2, R should create a default location for local libraries (i.e. that you install on your own). Check using the .libPaths() command. It should be something like /home/<username>/R/x86_64-pc-linux-gnu-library/3.2. If you want to install packages somewhere other than the default, you can set R_LIBS.

r_antsr_usage.1491850845.txt.gz · Last modified: 2017/04/10 19:00 by mgstauff