Skip to content

Instantly share code, notes, and snippets.

@andrie
Created November 18, 2014 08:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrie/17b7b8f31f461a1fdcb6 to your computer and use it in GitHub Desktop.
Save andrie/17b7b8f31f461a1fdcb6 to your computer and use it in GitHub Desktop.
Easily set a snapshot date on MRAN
setSnapshot <- function(date){
if(missing(date)) return(getOption("repos"))
repoDate <- paste0("http://mran.revolutionanalytics.com/snapshot/", date)
response <- tryCatch(
suppressWarnings(readLines(repoDate)),
error = function(e)e
)
if(inherits(response, "error")) stop(paste0("Invalid snapshot date."))
options(repos = c(CRAN = repoDate))
}
# Empty date field returns current repo
setSnapshot()
# Valid snapshot date
setSnapshot("2014-11-16")
# Invalid snapshot date (in future), returns error
setSnapshot("2024-11-16")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment