R Packages: Difference between revisions

From Cheaha
Jump to navigation Jump to search
(First draft)
 
mNo edit summary
Line 17: Line 17:
</pre>
</pre>


""" NOTE:""" Having .Rprofile in the user's home directory (~/.Rprofile), allows you to have a consistent setting throughout the cluster, and is generally advised.
''' NOTE:''' Having .Rprofile in the user's home directory (~/.Rprofile), allows you to have a consistent setting throughout the cluster, and is generally advised.


==Installation==
==Installation==

Revision as of 15:43, 5 December 2017

R is an open source programming language and software environment for statistical computing and graphics that is supported by the R Foundation for Statistical Computing. [Wikipedia] Packages are the fundamental units of reproducible R code. They include reusable R functions, the documentation that describes how to use them, and sample data.

.Rprofile

.Rprofile file allows you to customize R for your environment. R looks for .Rprofile in your current working directory to source, on it's first try, and then checks in user's home directory. Some of the things that you can customize in .Rprofile are the following:

  • .libPaths allows you to add a directory to it's library path, where you want to install R packages.
.libPaths("~/R_LIBS")
  • Following code allows you to hard code a mirror repo for CRAN.
r = getOption("repos") # hard code the UK repo for CRAN
r["CRAN"] = "http://cran.uk.r-project.org"
options(repos = r)

NOTE: Having .Rprofile in the user's home directory (~/.Rprofile), allows you to have a consistent setting throughout the cluster, and is generally advised.

Installation

Once you have setup .Rprofile to point to the directory where you want R to save and install your packages, load a module of R that you need.

[ravi89@c0113 ~]$ module load R/
R/2.15.3-goolf-1.7.20             R/3.3.1-foss-2016b
R/3.0.1-goolf-1.4.10-bare         R/3.3.1-foss-2016b-no-X
R/3.2.0-goolf-1.7.20              R/3.3.1-intel-2016a-bare
R/3.2.1-goolf-1.7.20              R/3.3.3-intel-2017a-X11-20170314
R/3.2.3-foss-2016a-bare           R/3.4.1-intel-2017a-X11-20170314
R/3.2.3-intel-2016a-bare          

After that start R, and use install.packages() to install the required packages.

[ravi89@c0023 ~]$ module load R/3.4.1-intel-2017a-X11-20170314 
[ravi89@c0023 ~]$ R

R version 3.4.1 (2017-06-30) -- "Single Candle"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

.Rprofile: Setting UK repositoryn[Previously saved workspace restored]

> install.packages("GenABEL")
Installing package into ‘/home/ravi89/R_LIBS_RC’
(as ‘lib’ is unspecified)
also installing the dependency ‘GenABEL.data’

trying URL 'http://cran.uk.r-project.org/src/contrib/GenABEL.data_1.0.0.tar.gz'
Content type 'application/x-gzip' ..........
.
.
.