Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install R packages
####################################
# global libraries used everywhere #
####################################
# Package lock in - optional
MRAN.snapshot <- "2019-01-01"
options(repos = c(CRAN = paste0("https://mran.revolutionanalytics.com/snapshot/",MRAN.snapshot)))
pkgTest <- function(x)
{
if (!require(x,character.only = TRUE))
{
install.packages(x,dep=TRUE)
if(!require(x,character.only = TRUE)) stop("Package not found")
}
return("OK")
}
global.libraries <- c("dplyr","devtools","rprojroot","tictoc")
results <- sapply(as.list(global.libraries), pkgTest)
# ###########################
# CONFIG: define paths and filenames for later reference
# ###########################
# Change the basepath depending on your system
basepath <- rprojroot::find_rstudio_root_file()
# Main directories
dataloc <- file.path(basepath, "data","replication_data")
interwrk <- file.path(basepath, "data","interwrk")
Outputs <- file.path(basepath, "analysis" )
programs <- file.path(basepath,"programs")
for ( dir in list(dataloc,interwrk,Outputs)){
if (file.exists(dir)){
} else {
dir.create(file.path(dir))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.