4

I am an "admin" for a shared server for statisticians on a research study.

I have a list of about 100 packages used by our senior statistician on the study. I would prefer to load and update them periodically from an R shell (versus inside RStudio Server).

I think using the default system location (/opt/R/4.2.0/lib/R/library) is the way to go. While the RStudio Server setup allows users to load their own, having a default group loaded per our statistician's ask seems wise.

The commands I was given which load these packages have the syntax below (only including a few lines of the script). They seem to install if the package doesn't already exist.

If I set an environment variable properly, then run R as root and issue all these commands, would the libraries be placed appropriately in the library folder that I set in the environment variable (in this example, it'd be /opt/R/4.2.0/lib/R/library)?

Since this is Linux, we would want to install from sources when appropriate, which I think is default loading for this OS.

Is there a better/easier way to do this?

if (!requireNamespace("markdown", quietly = TRUE)) install.packages("markdown")
if (!requireNamespace("devtools", quietly = TRUE)) install.packages("devtools")
# graphical/table output
if (!requireNamespace("igraph", quietly = TRUE)) install.packages("igraph")
if (!requireNamespace("ggplot2", quietly = TRUE)) install.packages("ggplot2")
# advanced regression
if (!requireNamespace("glmnet", quietly = TRUE)) install.packages("glmnet")
if (!requireNamespace("sm", quietly = TRUE)) install.packages("sm")

RStudio Server packageStatus():

enter image description here

Environment:

CentOS 8  
RStudio Server 1.4.1717-3  
R 4.2  (4.1.3, 3.6.3)
Mikael Jagan
  • 9,012
  • 2
  • 17
  • 48
RichPinder
  • 41
  • 2

1 Answers1

0

These are a lot of questions. Here's an attempt at some answers

I have a list of about 100 packages used by our senior Statistician on the study, and would prefer to load (AND UPDATE PERIODICALLY) them from an R shell directly (vs inside RStudioServer). I think using the default system location to add them ( /opt/R/4.2.0/lib/R/library) is the way to go.

We customize it to a shared network mount, but you certainly don't have to. If you ever need to, be aware of:

  • The R_PROFILE_USER env var, which can contain a path to a script running very early in every R startup sequence
  • The R_LIBS_USER env var, which can contain a new default package folder
  • The .libPaths R function, that can customize the used package folders from within an R script - either the one in R_PROFILE_USER or the per-user .Rprofile.

The RStudioServer setup, i think, still allows user to load their own (which is fine by me), but I thought having a default group loaded per our Statistician's ask... is wise.

I agree.

The commands I was given which load these packages have the syntax below (only including a few lines of the 90 line .sh script) - they seem to install if the package doesnt already exist.

Not sure I understand. The commands you pasted are R, not sh. Either place them in each of your users' .Rprofile, or in a centrally-accessible script and make R_PROFILE_USER include its path.

Also, about periodically updating - here's a simplified version of an R script I use:

instpk <- as.data.frame(installed.packages())
oldpk <- as.data.frame(old.packages(checkBuilt=TRUE))

# base/recommended packages are best installed alongside R:
# (https://stackoverflow.com/a/9705725/89706)
base.rec.packages <- instpk[!is.na(instpk$Priority),]$Package
updatePk <- setdiff(oldpk$Package, base.rec.packages)

update.packages(ask=FALSE, oldPkgs=updatePk)

(I customize some folders and env vars too, but maybe you won't need to).

HTH.

Ofek Shilon
  • 14,734
  • 5
  • 67
  • 101