R

R is a free statistical computing and graphics software.
It performs calculations written in a programming language called R and is widely used in the field of statistical analysis.


Usage

Currently, R version 4.3.3 is available on the login node and compute nodes. No module command is needed to use it.


Interactive use

Interactive is available by invoking R environment with R command as follows.

$ R

R version 4.3.3 (2024-02-29) -- "Angel Food Cake"
Copyright (C) 2024 The R Foundation for Statistical Computing
Platform: x86_64-redhat-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.

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.

> 1 + 2
[1] 3
> sin(pi/3)
[1] 0.8660254
> (1+2i) * (1-2i)
[1] 5+0i
> a <- 1
> a+2 -> b
> b
[1] 3
> q()
Save workspace image? [y/n/c]: n

Batch job

R scripts can be executed in job scripts of batch job by adding --slave --vanilla option as follows.

#!/bin/bash
#PJM -L rscgrp=a-batch
#PJM -L node=1
#PJM -L elapse=00:20:00
#PJM -j
#PJM -S

R --slave --vanilla < test.R

Install packages

When installing R packages using install.packages("Package_name") in R, you may get warnings or errors. Below are some cases that can be addressed.


Message '... is not writable' is displayed

In R, if you do not specify where to install the package, the following warning message is displayed when trying to install the package in a location that requires administrative privileges.

> install.packages("markdown")
  Installing package into '/usr/lib64/R/library'
  (as 'lib' is unspecified)
  Warning in install.packages("markdown") :
    'lib = "/usr/lib64/R/library"' is not writable
  Would you like to use a personal library instead? (yes/No/cancel)

If you are using R interactively, selecting yes here will suggest installing to your home directory, which you can follow to complete the installation.

On the other hand, there are two ways to specify where to install the package in advance.

  • Install the package in the same place every time
    For example, if you run the following, all packages will be installed in a directory called Rpackages in your home directory next time. This is usually recommended.
    $ mkdir ${HOME}/Rpackages
    $ echo R_LIBS_USER = ${HOME}/Rpackages > ${HOME}/.Renviron
        
  • Specify the place for each install.packages
    You can specify the installation place (in this example /home/pj24001603/ku40000105/Rpackages) for install.packages as follows.
    > install.packages("markdown",lib="/home/pj24001603/ku40000105/Rpackages")
        


Message 'Please select a CRAN mirror' is displayed

A CRAN mirror is a site that can be used as a download source for R packages. If you are using R interactively, you can select it on the spot if you have not specified it beforehand.

On the other hand, if you execute, for example, the following, from your next R usage the site you specify (in this example, https://ftp.yz.yamagata-u.ac.jp/pub/cran/) will be used automatically.

$ echo options(repos = structure(c(CRAN = "https://ftp.yz.yamagata-u.ac.jp/pub/cran/"))) > .Rprofile
  


Message '... does not seem to be installed on your platform' is displayed

Some packages require a separate tool to be installed, and if this tool is not found, the installation will fail with the following error message.

> install.packages("hdf5r")

...

configure: error: hdf5 does not seem to be installed on your platform.
  Please install the hdf5 library.

  ...

  ERROR: configuration failed for package ‘hdf5r’
  * removing ‘/home/pj24001604/ku40000114/local/R/libs/hdf5r’
  
  The downloaded source packages are in
  '/tmp/RtmpapinBQ/downloaded_packages'
  Warning message:
  In install.packages("hdf5r") :
  installation of package 'hdf5r' had non-zero exit status

For example, in the above error, the message "Please install the hdf5 library" indicates that the hdf5 tool is required.

If you see this, you usually need to install the tool, but it may already be installed in Genkai. Therefore, we recommend that you first check it out using the show_module command in Genkai.

For example, if you look for a tool with the keyword hdf5 in the software installed in Genkai, as in the following example, we see that it is installed with the module name hdf5/1.14.4. We also see that the gcc-toolset/12 module is also required to use this module.

$ show_module -k hdf5
ApplicationName                     ModuleName                      NodeGroup   BaseCompiler/MPI
------------------------------------------------------------------------------------------------
HDF5                                hdf5/1.14.4                     LoginNode   gcc-toolset/12

...

So, as shown in the following example, by loading these modules followed by R to install the package, the installation was successful.

$ module load gcc-toolset/12 hdf5
$ R

R version 4.3.3 (2024-02-29) -- "Angel Food Cake"
Copyright (C) 2024 The R Foundation for Statistical Computing
Platform: x86_64-redhat-linux-gnu (64-bit)
  ...
> install.packages("hdf5r")  

  ...

* DONE (hdf5r)

  The downloaded source packages are in
         ‘/tmp/Rtmpgo3uqC/downloaded_packages’
>
    

If you are not sure whether the tools necessary to install the package are included in Genkai, please contact the contact person. (Access/Contact)


Reference