Skip to content

What is R

R is a language originally designed for statistical computing and graphics, but is also a general purpose programming language. It is used extensively in remote sensing research. The home page for R is at For an introduction see What is R? at the R project site.

To check the version of R installed do:

$ R --version
R version 4.2.2 (2022-10-31) -- "Innocent and Trusting"

Quick Help

> help(Startup)

When R starts (with default options), it loads the .Rprofile and .Renviron files in the working directory or user’s home directory.

Installing R Packages

It is best to install the R packages that you require into your own local R library.

By default R will install local R packages under the directory specified by the “R_LIBS_USER” environment variable. You can check what this is within an R session with > Sys.getenv("R_LIBS_USER"). The default setting for this is ~/R/x86_64-redhat-linux-gnu-library/. Under there you will find a directory for each version of R.

Some users prefer to set their own directory for R packages. A .Renviron file will override any defaults. Note that R is usually forwards-compatible with libraries installed from previous versions of R but not always.

$ mkdir ~/R/library 
$ echo 'R_LIBS_USER="~/R/library"' > $HOME/.Renviron

Notes: In the above I have used “~” as a shortcut for your HOME directory. You can also use the full path. But do not use $HOME within .Renviron as R does not expand $HOME - that’s surely a glitch in R. Also if you specify a path that does exist R will just ignore it but not tell you there is an error.

You can also install to a specific location using the “lib” option to the install.packages function.

$ R 
> install.packages("name-of-your-package", lib="~/R/library")

You can run from within R the command .libPaths() to show you where R will look for libraries.

Running R from PBS Submission Scripts

Below is the skeleton of a PBS submission script showing how you invoke your R script using “Rscript”.


# Place your #PBS directives here.
#PBS ......

# If you are not using an .Renviron file then you will need to export R_LIBS_USER e.g. 
export R_LIBS_USER=$HOME/R/library

# Run your R script using "Rscript". 
Rscript your_R_Script.r

Remember to use the /scratch directory if you are using lots of file input and output.

Useful References

Quick-R by DataCamp has some quick help on basic R topics. It’s a useful starting place.

Fun with .Rprofile and customizing R startup

Efficient R programming – This is the online version of the O’Reilly book “Efficient R Programming”.

R Installation and Administration

If you wish to find out if the not yet released versions have changed documentation then read and from there you can follow the “R-devel” link to find the docs for the next version of R. You can also go directly to Packages in the standard library and Documentation for package ‘base’ version.

Finally if you really do like R you should read the The R Inferno (PDF) by Patrick Burns. This is written in a satirical style after Dante’s Inferno.