Skip to content

Instantly share code, notes, and snippets.

@jbryer
Created March 7, 2012 16:14
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jbryer/1994082 to your computer and use it in GitHub Desktop.
Save jbryer/1994082 to your computer and use it in GitHub Desktop.
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 = 'http://cran.r-project.org'
#Site provides some prebuilt binaries for Windows
repos.win = 'http://www.stats.ox.ac.uk/pub/RWin'
#URL for the R-Forge repository.
repos.rforge = 'http://r-forge.r-project.org'
#Type of download for install.packages. Default to source
.type = 'source'
.libLoc = ''
if(Sys.info()['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, repos.win) #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(Sys.info()['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!')
}
.libPaths(.libLoc)
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.
library(devtools)
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