BwUniCluster2.0/Software/R: Difference between revisions
Line 141: | Line 141: | ||
By default R uses a version (and platform) specific path for personal libraries, such as |
By default R uses a version (and platform) specific path for personal libraries, such as |
||
"$HOME/R/x86_64-pc-linux-gnu-library/ |
"$HOME/R/x86_64-pc-linux-gnu-library/x.y" for R version x.y.z. This directory will be created automatically (after confirmation) when installing a personal package for the first time. |
||
Users |
Users can customize a common location of their personal library packages, e.g. ~/R_libs, rather than the default location. A customized directory must exist before installing a personal package for the first time, i.e. |
||
<pre> |
|||
⚫ | |||
$ mkdir -p ~/R_libs |
|||
</pre> |
|||
The location must also be defined in a configuration file ~/.Renviron within the home directory containing the following line: |
|||
<pre> |
|||
R_LIBS_USER="~/R_libs" |
|||
</pre> |
|||
By setting up a (fixed) custom location for personal library packages, any personal package installed into that directory will be visible for any R version. This may be advantageous if the packages are to be used with different (future) R versions. |
|||
⚫ | |||
As a downside, whenever switching to a new major R release, the personal library stack must be rebuild with that new R version. However, this is recommended anyway in order to ensure a consistent personal library stack for any specific R version in use. Mixing libraries built with different R versions is discouraged, as this may result in unpredictable errors. |
As a downside, whenever switching to a new major R release, the personal library stack must be rebuild with that new R version into the corresponding (version specific) library path. However, this is recommended anyway in order to ensure a consistent personal library stack for any specific R version in use. Mixing libraries built with different R versions is discouraged, as this may (or may not) result in unpredictable errors. This is especially true if several versions are used simultaneously, e.g. an older R version for one project and a newer R version for another project. |
||
Special care has to be taken by users who always load the default version, i.e. |
Special care has also to be taken by users who always load the default version, i.e. |
||
<pre> |
<pre> |
||
Line 155: | Line 167: | ||
</pre> |
</pre> |
||
as the default version may change any time. Is is therefore highly recommended to always load a specific version, e.g. |
as the default version number may change any time. Is is therefore highly recommended to always load a specific version, e.g. |
||
<pre> |
<pre> |
Revision as of 18:23, 27 August 2019
Description | Content |
---|---|
module load | math/R |
License | GPL |
Citing | n/a |
Links | Homepage | Documentation |
Graphical Interface | No |
Plugins | User dependent |
Description
R is a language and environment for statistical computing and graphics. It is a GNU project which is similar to the S language and environment which was developed at Bell Laboratories (formerly AT&T, now Lucent Technologies) by John Chambers and colleagues. R can be considered as a different implementation of S. There are some important differences, but much code written for S runs unaltered under R.
R provides a wide variety of statistical (linear and nonlinear modelling, classical statistical tests, time-series analysis, classification, clustering, …) and graphical techniques, and is highly extensible. The S language is often the vehicle of choice for research in statistical methodology, and R provides an Open Source route to participation in that activity.
One of R’s strengths is the ease with which well-designed publication-quality plots can be produced, including mathematical symbols and formulae where needed. Great care has been taken over the defaults for the minor design choices in graphics, but the user retains full control.
R is available as Free Software under the terms of the Free Software Foundation’s GNU General Public License in source code form. It compiles and runs on a wide variety of UNIX platforms and similar systems (including FreeBSD and Linux), Windows and MacOS.
Versions and Availability
A list of versions currently available on all bwHPC-C5-Clusters can be obtained from the
Cluster Information System CIS
{{#widget:Iframe
|url=https://cis-hpc.uni-konstanz.de/prod.cis/bwUniCluster/math/R
|width=99%
|height=280
}}
On the command line interface of any bwHPC cluster, a list of the available R versions using
$ module avail math/R
Usage
The R installation also provides the standalone library libRmath. This library allows you to access R routines from your own C or C++ programs (see section 9 of the 'R Installation and Administration' manual.)
Loading the module
You can load the default version of R with the command
$ module load math/R
The module will try to load modules it needs to function (e.g. compiler/intel). If loading the module fails, check if you have already loaded one of those modules, but not in the version needed for R.
If you wish to load a specific (older) version, you can do so using e.g.
$ module load math/R/3.2.1
to load the version 3.2.1.
Program Binaries
Standard usage:
Usage: R [options] [< infile] [> outfile] R CMD command [arguments] Example: R CMD BATCH script.R
Executing R in batch mode:
R CMD BATCH --no-save --no-restore <INPUT_FILE>.R
For help run
R --help
For command help run
R CMD command --help
Further information and help
Man pages: man R man Rscript Info pages. e.g.: info R-intro info R-FAQ Manuals: $R_DOC_DIR/manual
Multithreading in R
An easy way to use multiple cores on a single node in R is to use the doParallel package in combination with foreach.
Examples
As with all processes that require more than a few minutes to run, non-trivial compute jobs must be submitted to the cluster queuing system.
Example scripts are available in the directory $R_EXA_DIR:
$ module show math/R # show environment variables, which will be available after 'module load' $ module load math/R # load module $ ls $R_EXA_DIR # show content of directory $R_EXA_DIR $ cat $R_EXA_DIR/README # show examples README
Run a first simple example job
$ module load math/R # load module $ mkdir Rtest # create test directory $ cp $R_EXA_DIR/bwhpc-r.moab $R_EXA_DIR/fit.R Rtest/ # copy example files to test directory $ cd Rtest/ # change to directory $ nano bwhpc-r.moab # change job options, quit with 'CTRL+X' $ msub bwhpc-r.moab # submit job $ checkjob -v <JOBID> # check state of job $ ls # when job finishes the results will be visible in this directory
Installing R-Packages into your home folder
Since we cannot provide a software module for every R package, we recommend to install special R packages locally into your home folder. One possibility doing this is from within an interactive R session:
> install.packages('package_name', repos="http://cran.r-project.org") # Installing your R package and the dependencies > library(package_name) # Loading the package into you R instance
The package is now installed permanently in your home folder and is available every time you start R.
Note:
By default R uses a version (and platform) specific path for personal libraries, such as "$HOME/R/x86_64-pc-linux-gnu-library/x.y" for R version x.y.z. This directory will be created automatically (after confirmation) when installing a personal package for the first time.
Users can customize a common location of their personal library packages, e.g. ~/R_libs, rather than the default location. A customized directory must exist before installing a personal package for the first time, i.e.
$ mkdir -p ~/R_libs
The location must also be defined in a configuration file ~/.Renviron within the home directory containing the following line:
R_LIBS_USER="~/R_libs"
By setting up a (fixed) custom location for personal library packages, any personal package installed into that directory will be visible for any R version. This may be advantageous if the packages are to be used with different (future) R versions.
A version specific path, such as the default path, allows users to maintain multiple personal library stacks for different major R versions and does also prevent users from mixing their stack with libraries built with different R versions.
As a downside, whenever switching to a new major R release, the personal library stack must be rebuild with that new R version into the corresponding (version specific) library path. However, this is recommended anyway in order to ensure a consistent personal library stack for any specific R version in use. Mixing libraries built with different R versions is discouraged, as this may (or may not) result in unpredictable errors. This is especially true if several versions are used simultaneously, e.g. an older R version for one project and a newer R version for another project.
Special care has also to be taken by users who always load the default version, i.e.
$ module load math/R
as the default version number may change any time. Is is therefore highly recommended to always load a specific version, e.g.
$ module load math/R/3.5.3
Example builds for R-Packages
These examples(s) are for building R modules. Please write us a ticket if some instructions do not work for you or are outdated.
Version-Specific Information
For information specific to a single version, see the information available via the module system with the command
$ module help math/R
Installed R plugins