R package installer

by chrisvoncsefalvay
0 deployments · 0 still active · last rev. 19 days ago

Universal R package installer. DO NOT RUN ON ITS OWN!

Provides the install_Rpkg() function, which takes any number of arguments, which are then treated as installable R functions. Requires R to be in PATH.

Compatible with: Arch Linux, CentOS 7, Debian 9, Fedora 27, Fedora 28, Gentoo 2018-04-06, openSUSE Leap 42.3, Slackware 14.2, Ubuntu 16.04 LTS, Ubuntu 18.04 LTS, CentOS 6.8, Debian 8, Fedora 26, Slackware 13.37, Slackware 14.1, Ubuntu 14.04 LTS, Ubuntu 17.10
						#!/usr/bin/env bash
#
# R Package Installer library
#
# (c) Chris von Csefalvay <chris@chrisvoncsefalvay.com>
#

install_Rpkg () {
  REXEC=$(which R)
  
  if [ -z ${REXEC} ]
  then
    echo "Can't access R. Please check if R is available, in the PATH and try again."
    echo "For reference, your PATH is:"
    echo $PATH
    exit 1
  fi
  
  for pkg in "$@"
  do
    echo "Installing R package $pkg..."
    echo "install.packages(\"${pkg}\", repos=\"https://cran.rstudio.com\")" | R --no-save
  done
}