Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@larsvilhuber
Created April 23, 2019 15:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save larsvilhuber/85026976027b58714c00420d75f04281 to your computer and use it in GitHub Desktop.
Save larsvilhuber/85026976027b58714c00420d75f04281 to your computer and use it in GitHub Desktop.
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