Skip to content

Instantly share code, notes, and snippets.

@oganm
Last active April 7, 2020 14:27
Show Gist options
  • Save oganm/a401ef9eaeec3ac82ea733fdfcfb9831 to your computer and use it in GitHub Desktop.
Save oganm/a401ef9eaeec3ac82ea733fdfcfb9831 to your computer and use it in GitHub Desktop.
install arbitrary packages from command line
#!/usr/bin/Rscript
# Rscript install.R packageName
# point of this is to be able to install arbitrary packages from CRAN, github, bioconductor, etc from command line
# used for my remote server where I use the root library to share packages between my user and the shiny user
# sudo install.R glue oganm/ogbox bioc::3.6/affy
library(dplyr)
library(ogbox)
print(.libPaths())
userID = Sys.getenv('USER')
# print(userID)
if(userID == 'root'){
print('Installing to root library')
lib = "/usr/local/lib/R/site-library"
} else{
print('Installing to user library')
lib = .libPaths()[1]
}
args <- commandArgs(trailingOnly = TRUE)
args %>% sapply(function(x){
ogbox::generic_install(x,lib = lib)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment