public
Last active

R Setup Script

  • Download Gist
setup.r
R
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
#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...")

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.