This is an old revision of the document!
R is available on the cluster. R can also be installed on your computer for free by visiting the R-project main page.
For more information about R, you might want to use the R manual or RSeek, the search engine for R related resources.
The default version of R on the cluster is 3.5.2. You can use it interactively with
R
You can also run a .R file in batch mode with
R CMD BATCH filename.R
To run your R command in the background, see Managing Jobs.
The cluster also has 4.0.2 version installed. To use it, run
/opt/R/4.0.2/bin/R
or
/opt/R/4.0.2/bin/R CMD BATCH filename.R
If you're planning to use this version often, you might want to assign an
alias to this long command (e.g. R4).
To install an R package, type in the interactive mode
install.packages("package_name")
Sometimes, the package won't be installed because of the outdated compiler (for example, stm). To solve this, before opening R, type in the terminal
source /opt/rh/devtoolset-8/enable
and then proceed with the installation.
The following section comes initially from an introductory talk on R given by Paul Bailey in February 2011. The data used in the examples is located at this link.
dat <- read.csv("MDemp.csv")
and general methods
dat <- read.table("MDemp.csv",sep=",")
?
??
summary(dat)summary(dat$num_child) table(dat$num_child)
[condition,] you can select rows:dat.lf <- dat[dat$emp %in% c("emp","unemp"),]
dat.hs <- dat.lf[dat.lf$educ==39,]
lm1 <- lm(weekly_earn ~ age + year,data=dat) summary(lm1)
dat$yearf <- as.factor(dat$year) lm2 <- lm(weekly_earn ~ age + yearf,data=dat) summary(lm2)
contrasts(dat$yearf) <- "contr.sum" lm3 <- lm(weekly_earn ~ age + yearf,data=dat) summary(lm3)
agg.hs <- aggregate(dat.hs$emps,by=list(dat.lf$yq),mean)
merged <- merge(data.a,data.b)
* Lots of options for this one
Some basic info can be found at the High Performance Computing CRAN view. You can use the “parallel” package (which merges both “snow” and “multicore”).
You can also use Rmpi and npRmpi packages. You have your choice of MPI2 libraries (both OpenMPI and MPICH2). You will have to install the packages in your userspace (requiring compilation).
| OpenMPI | MPICH2 | |
|---|---|---|
| Before anything (installation or usage) | >module load openmpi-x86_64 | >module load mpich2-x86_64 |
| Installation | R> install.packages(“<package>”, configure.args=“–with-Rmpi-include=/usr/lib64/openmpi/1.4-gcc/include –with-Rmpi-libpath=/usr/lib64/openmpi/1.4-gcc/lib –with-Rmpi-type=OPENMPI”) | R> install.packages(“<package>”, configure.args=“-with-Rmpi-include=/usr/include/mpich2-x86_64 –with-Rmpi-libpath=/usr/lib64/mpich2/lib –with-Rmpi-type=MPICH”) |
A good intro guide is npRmpi: A package for parallel distributed kernel estimation in R.
merge merges datasetsglm fits limited dependent variable models.optim minimizes / finds zeros