Skip to content

[newbie] scripting remote check for R package

7 messages · Tom Roche, Gergely Daróczi

#
summary: e.g., how to replace '<query R for package=package_name>'
in the following:

for RSERVER in 'foo' 'bar' 'baz' ; do
  ssh ${RSERVER} '<query R for package=package_name>'
done

or is there a better way to script checking for an R package?

details:

For my work I need a few non-standard R packages. I do that work on 2
clusters. One uses environment modules, so any given server on that
cluster can provide (via `module add`) pretty much the same resources.

The other cluster, on which I must also unfortunately work, has
servers managed individually, so I get in the habit of doing, e.g.,

EXEC_NAME='whatever'
for S in 'foo' 'bar' 'baz' ; do
  ssh ${RSERVER} "${EXEC_NAME} --version"
done

periodically. I'm wondering, what incantation to utter (bash preferred)
via ssh to query a given server's R for a given package?

TIA, Tom Roche <Tom_Roche at pobox.com>
1 day later
#
https://stat.ethz.ch/pipermail/r-help/2012-September/322985.html
https://stat.ethz.ch/pipermail/r-help/2012-September/323000.html
Thanks! but ...

While that works great on _my_ linux boxes (on which I installed R),
on the cluster where I need to run this (where I do *not* have root)

me at foo:~ $ which Rscript
me at foo:~ $ find /share -name 'Rscript' | wc -l
me at foo:~ $ which R
So I'm wondering:

1 Is there a way to do `Rscript -e` with plain, commandline R?

2 What should my admin have done to install both Rscript and R?
  (Alternatively, what should I tell my admin to do in order to make
  both Rscript and R available?)

3 Is there any reason to install R without Rscript? (Alternatively,
  when I ask my admin to install Rscript, is there any objection
  I should anticipate?)

thanks again, Tom Roche <Tom_Roche at pobox.com>
#
https://stat.ethz.ch/pipermail/r-help/2012-September/322985.html
https://stat.ethz.ch/pipermail/r-help/2012-September/323000.html
https://stat.ethz.ch/pipermail/r-help/2012-September/323024.html
I learned how to use `R CMD BATCH`. It's definitely more painful than
`Rscript -e`, but at least the following works:

EXEC_DIR='/share/linux86_64/bin' # on foo, at least
# EXEC_NAME='Rscript'
EXEC_NAME='R'
EXEC_PATH="${EXEC_DIR}/${EXEC_NAME}"
BATCH_INPUT_PATH="./junk.r"      # presumably in home dir
BATCH_OUTPUT_PATH="./junk.r.out" # ditto
for RSERVER in 'foo' 'bar' 'baz' ; do
  echo -e "${RSERVER}:"
# The following 3 commands attempted to debug a
# separate but related problem; about which, see
# http://serverfault.com/questions/424027/ssh-foo-command-not-loading-remote-aliases
#  ssh ${RSERVER} "${EXEC_NAME} --version | head -n 1"
#  ssh ${RSERVER} "grep -nHe 'bashrc' ~/.bash_profile"
#  ssh ${RSERVER} "grep -nHe '\W${EXEC_NAME}\W' ~/.bashrc"
  ssh ${RSERVER} "${EXEC_PATH} --version | head -n 1"
  ssh ${RSERVER} "echo -e 'as.numeric(suppressWarnings(suppressPackageStartupMessages(require(M3))))\n' > ${BATCH_INPUT_PATH}"
  ssh ${RSERVER} "rm ${BATCH_OUTPUT_PATH}"
  ssh ${RSERVER} "ls -al ${BATCH_INPUT_PATH}"
  ssh ${RSERVER} "cat ${BATCH_INPUT_PATH}"
  ssh ${RSERVER} "${EXEC_PATH} CMD BATCH --slave --no-timing ${BATCH_INPUT_PATH} ${BATCH_OUTPUT_PATH}"
  ssh ${RSERVER} "ls -al ${BATCH_OUTPUT_PATH}"
  ssh ${RSERVER} "head -n 1 ${BATCH_OUTPUT_PATH}"
  echo # newline
done

Given the pain, I'd still like to know:
your assistance is appreciated, Tom Roche <Tom_Roche at pobox.com>
#
https://stat.ethz.ch/pipermail/r-help/2012-September/322985.html
https://stat.ethz.ch/pipermail/r-help/2012-September/323000.html
https://stat.ethz.ch/pipermail/r-help/2012-September/323024.html
Incorporating Gergely Dar?czi's last suggestion (k?sz?n?m!) I get

# the package for which to check that has the most dependencies
APEX_PKG='M3' # substitute yours
for RSERVER in 'foo' 'bar' 'baz' ; do
  echo -e "${RSERVER} has:"
  ssh ${RSERVER} "R --version | head -n 1"
  ssh ${RSERVER} "echo -e ${RSERVER} has ${APEX_PKG}:"
  ssh ${RSERVER} "R --slave -e 'as.logical(suppressWarnings(suppressPackageStartupMessages(require(${APEX_PKG}))))'"
  echo # newline
done

which works. I'd still like to know:
your assistance is appreciated, Tom Roche <Tom_Roche at pobox.com>
#
As described in the thread beginning @

https://stat.ethz.ch/pipermail/r-help/2012-September/322985.html

I work (as a user, without root) on a cluster that has several servers
on which R is installed but not Rscript. I'd like to know

1 What should I tell my admin to do in order to make both Rscript and
  R available? (FWIW I believe the boxes are running CentOS, though
  possibly RHEL 5 or 6.)

2 Is there any reason to install R without Rscript? Alternatively,
  when I ask my admin to install Rscript, is there any objection
  I should anticipate?

TIA, Tom Roche <Tom_Roche at pobox.com>