Skip to content
Create a gist now

Instantly share code, notes, and snippets.

R Setup Script
#List of most used R packages that we wish to install.
libraries = c('cacheSweave', 'Deducer', 'devtools', 'doBy', 'foreign', 'gdata',
'ggplot2', 'Hmisc', 'JGR', 'lubridate', 'maps', 'mapdata', 'mapproj',
'maptools', 'proto', 'psych', 'R2wd', 'RCurl', 'reshape',
'RODBC', 'roxygen2', 'seqinr', 'sm', 'sp', 'sqldf', 'survey',
'WriteXLS', 'XML', 'xtable')
#We will install packages from the main CRAN site
repos = ''
#Site provides some prebuilt binaries for Windows = ''
#URL for the R-Forge repository.
repos.rforge = ''
#Type of download for install.packages. Default to source
.type = 'source'
.libLoc = ''
if(['sysname'] == 'Windows') {
#TODO: Install Oracle client
#path = Sys.getenv('PATH')
#path = paste('c:\\instantclient_11_1;',path, sep='')
#system(paste('Setx PATH "', path, '"', sep=''))
oDrive = 'o:/'
memory.limit(size=4095) #Set to 4GB (for 64-bit Windows, this can be much larger)
#Set the R_LIBS environment varaible. This assumes the Setx program is installed
#(this is included with the Service Pack 2 Support Tools)
system(paste('Setx R_LIBS ', oDrive, 'R/library/Windows', sep=''))
#We will manually add to libPaths since the system variable will not take
#effect until R is restarted.
.libLoc = paste(oDrive, 'R/library/Windows', sep='')
repos = c(repos, #Add the Windows repos for use below
# Set system environment varaible R_PROFILE
system(paste('Setx R_PROFILE ', oDrive, 'R/Rprofile', sep=''))
.type = 'win.binary'
} else if(['sysname'] == 'Linux') {
oDrive = '/n01/OutcomesAssessment/'
file.copy(paste(oDrive, 'R/Rprofile', sep=''), '~/.Rprofile', overwrite=TRUE)
#.libPaths(paste(oDrive, 'R/library/Linux', sep=''))
.libLoc = paste(oDrive, 'R/library/Linux', sep='')
} else {
stop('Unsupported operating system!')
is_installed <- function(mypkg) is.element(mypkg, installed.packages()[,1])
#Only load packages that are not already installed.
for(l in libraries) {
if(!is_installed(l)) {
install.packages(l, repos=repos, dep=TRUE, lib=.libLoc, type=.type,
destdir=paste(oDrive, 'R/library/download', sep=''))
#Make sure we have the latest versions of the packages
update.packages(repos=repos, ask=FALSE, lib.loc=.libLoc,
destdir=paste(oDrive, 'R/library/download', sep=''))
#Load some packages from Github. We won't bother checking if they are already
#installed since these tend to change more often.
install_github('irutils', 'jbryer', lib.loc=.libLoc)
install_github('ruca', 'jbryer', lib.loc=.libLoc)
install_github('ipeds', 'jbryer', lib.loc=.libLoc)
install_github('makeR', 'jbryer', lib.loc=.libLoc)
install_github('qualtrics', 'jbryer', lib.loc=.libLoc)
#Install ecir package
install(paste(oDrive, 'R/ecir', sep=''), lib.loc=.libLoc)
message("Installation of R packages complete. Please restart R now...")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.