# ------------------------------------------------------------------- # Creation of a defined CRAN snapshot to be made available on # https://cran.intiquan.com # # Run script from its location on the server! # # Snapshots are currently copied from MRAN (https://cran.microsoft.com/). # # This will continue as long as MRAN is up-to-date and continues its # service. If at any point in time the MRAN service becomes unavailable, # snapshots will be taken from CRAN whenever these are needed. # ------------------------------------------------------------------- scriptPath <- setwd(IQRtools::aux_fileparts(rstudioapi::getActiveDocumentContext()$path)$pathname) setwd(scriptPath) # ---------------------------------- # Define the (MRAN) snapshot to be copied # Define both folders with "/" at the end # ---------------------------------- SNAPSHOT <- "snapshot/2021-12-13/src/contrib/" SNAPSHOT_OLDER <- "snapshot/2021-12-13/src/contrib/Older/" # ---------------------------------- # Check # ---------------------------------- if (file.exists(SNAPSHOT)) stop("Snapshot already present") # ---------------------------------- # Main Repo # ---------------------------------- # Define the MRAN URL to copy it from MRAN_REPO <- paste0("https://cran.microsoft.com/",SNAPSHOT) # Create folder to download all packages IQRtools::aux_mkdir(SNAPSHOT) # Get names of all source package files download.file(url = MRAN_REPO,destfile = "content.txt",method = "libcurl") content <- IQRtools::aux_fileread("content.txt",collapserows = FALSE) content <- content[grepl(".tar.gz",content)] unlink("content.txt") m <- gregexpr('">(.*?)',content) matches <- unlist(regmatches(content,m)) matches <- gsub('">|',"",matches) # Download all source packages parallel::mclapply(seq_along(matches), function (k) { download.file(url = paste0(MRAN_REPO,matches[k]),destfile = paste0(SNAPSHOT,matches[k]),quiet = TRUE,method = "libcurl") },mc.cores = ifelse(.Platform$OS.type=="windows",1,64),mc.preschedule = FALSE) # ---------------------------------- # Older R Version Repo # ---------------------------------- # Define the MRAN URL to copy it from MRAN_REPO_OLDER <- paste0("https://cran.microsoft.com/",SNAPSHOT_OLDER) # Create folder to download all packages IQRtools::aux_mkdir(SNAPSHOT_OLDER) # Get names of all source package files download.file(url = MRAN_REPO_OLDER,destfile = "content.txt",method = "libcurl") content <- IQRtools::aux_fileread("content.txt",collapserows = FALSE) content <- content[grepl(".tar.gz",content)] unlink("content.txt") m <- gregexpr('">(.*?)',content) matches <- unlist(regmatches(content,m)) matches <- gsub('">|',"",matches) # Download all source packages parallel::mclapply(seq_along(matches), function (k) { download.file(url = paste0(MRAN_REPO_OLDER,matches[k]),destfile = paste0(SNAPSHOT_OLDER,matches[k]),quiet = TRUE,method = "libcurl") },mc.cores = ifelse(.Platform$OS.type=="windows",1,64),mc.preschedule = FALSE) # ---------------------------------- # Generate repo information and end # ---------------------------------- # Write the PACKAGES files setwd(SNAPSHOT) tools::write_PACKAGES(".",type = "source") # Change folder back setwd(scriptPath) # Final message message("Copying CRAN snapshot completed!")