Skip to content

Commit 809dc73

Browse files
committed
Merge branch 'dev'
* dev: Skip test if offline Rebuild documentation Make lines shorter Reorganize code; Delete code no longer used Use markdown for documentation #235 Use markdown for documentation #235 Document newly exposed functions #209, #235 Use markdown in roxygen docs #235 Use markdown in roxygen docs #235
2 parents 9b9dd5b + d9b269d commit 809dc73

21 files changed

+265
-193
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
checkpoint.Rproj
55
.RData
66
inst/doc
7+
tests/testthat/framed.sty

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ Suggests:
3232
testthat(>= 0.9),
3333
MASS
3434
VignetteBuilder: knitr
35-
RoxygenNote: 5.0.1
35+
RoxygenNote: 6.0.1
36+
Roxygen: list(markdown = TRUE)

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export(checkpoint)
44
export(checkpointArchives)
55
export(checkpointRemove)
66
export(getValidSnapshots)
7+
export(mranUrl)
78
export(setSnapshot)
89
importFrom(utils,Stangle)
910
importFrom(utils,available.packages)

R/checkpoint-package.R

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22
#'
33
#' The goal of checkpoint is to solve the problem of package reproducibility in R. Specifically, checkpoint allows you to install packages as they existed on CRAN on a specific snapshot date as if you had a CRAN time machine.
44
#'
5-
#' To achieve reproducibility, the checkpoint() function installs the packages required or called by your project and scripts to a local library exactly as they existed at the specified point in time. Only those packages are available to your project, thereby avoiding any package updates that came later and may have altered your results. In this way, anyone using the checkpoint checkpoint() function can ensure the reproducibility of your scripts or projects at any time.
5+
#' To achieve reproducibility, the [checkpoint()] function installs the packages required or called by your project and scripts to a local library exactly as they existed at the specified point in time. Only those packages are available tot your project, thereby avoiding any package updates that came later and may have altered your results. In this way, anyone using the checkpoint [checkpoint()] function can ensure the reproducibility of your scripts or projects at any time.
66
#'
7-
#' To create the snapshot archives, once a day (at midnight UTC) we refresh the Austria CRAN mirror, on the checkpoint server (https://mran.microsoft.com/). Immediately after completion of the rsync mirror process, we take a snapshot, thus creating the archive. Snapshot archives exist starting from 2014-09-17.
7+
#' To create the snapshot archives, once a day (at midnight UTC) we refresh the Austria CRAN mirror, on the checkpoint server (https://mran.microsoft.com/). Immediately after completion of the `rsync`` mirror process, we take a snapshot, thus creating the archive. Snapshot archives exist starting from 2014-09-17.
88
#'
9-
#' checkpoint exposes only a single function:
9+
#' checkpoint exposes functions for:
1010
#'
11-
#' \describe{
12-
#' \item{\code{\link{checkpoint}}}{Configures R session to use packages as they existed on CRAN at time of snapshot.}
13-
#' }
11+
#' * [checkpoint()]: Configures R session to use packages as they existed on CRAN at time of snapshot.
12+
#' * [checkpointArchives()]: List checkpoint archives on disk.
13+
#' * [checkpointRemove()]: Remove checkpoint archive from disk.
14+
#' * [setSnapshot()]: Set default CRAN repository to MRAN snapshot date.
15+
#' * [getValidSnapshots()]: Read list of available snapshot dates from MRAN.
1416
#'
1517
#' @name checkpoint-package
1618
#' @docType package

R/checkpoint.R

Lines changed: 68 additions & 51 deletions
Large diffs are not rendered by default.

R/checkpoint_remove.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#'
55
#' @inheritParams checkpoint
66
#' @export
7-
#' @seealso checkpointRemove
7+
#' @family checkpoint functions
88
#' @example inst/examples/example_remove.R
99
checkpointArchives <- function(checkpointLocation = "~/"){
1010
z <- list.files(path = paste0(normalizePath(checkpointLocation), ".checkpoint"),
@@ -13,11 +13,12 @@ checkpointArchives <- function(checkpointLocation = "~/"){
1313
normalizePath(z, winslash = "/")
1414
}
1515

16+
1617
#' Remove checkpoint archive from disk.
1718
#'
1819
#' @inheritParams checkpoint
1920
#' @export
20-
#' @seealso checkpointArchives
21+
#' @family checkpoint functions
2122
#' @example inst/examples/example_remove.R
2223
checkpointRemove <- function(snapshotDate, checkpointLocation = "~/"){
2324
z <- list.files(path = paste0(normalizePath(checkpointLocation), ".checkpoint"),

R/mranUrl.R

Lines changed: 16 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,27 @@ stopIfInvalidDate <- function(snapshotDate, verbose = TRUE){
33
if(missing(snapshotDate) || is.null(snapshotDate))
44
stop("You have to specify a snapshotDate", call. = FALSE)
55
if(!grepl("^\\d{4}-\\d{2}-\\d{2}$", snapshotDate))
6-
stop("snapshotDate must be a valid date using format YYYY-MM-DD", call. = FALSE)
6+
stop("snapshotDate must be a valid date using format YYYY-MM-DD",
7+
call. = FALSE)
78
if(as.Date(snapshotDate) < as.Date("2014-09-17"))
89
stop("Snapshots are only available after 2014-09-17", call. = FALSE)
910
if(as.Date(snapshotDate) > Sys.Date())
1011
stop("snapshotDate can not be in the future!", call. = FALSE)
1112

12-
1313
validSnapshots <- tryCatch(as.Date(getValidSnapshots()), error=function(e)e)
1414
if(inherits(validSnapshots, "error")){
1515
mssg(verbose, "Unable to connect to MRAN. Skipping some date validations.")
1616
} else {
1717
if(!as.Date(snapshotDate) %in% validSnapshots) {
1818
i <- findInterval(as.Date(snapshotDate), validSnapshots)
1919
suggestions <- validSnapshots[c(i, i+1)]
20-
stop(sprintf("Snapshot does not exist on MRAN. Try %s or %s.", validSnapshots[i], validSnapshots[i+1]))
20+
stop(sprintf("Snapshot does not exist on MRAN. Try %s or %s.",
21+
validSnapshots[i],
22+
validSnapshots[i+1]))
2123
}
2224
}
23-
24-
2525
}
2626

27-
# testHttps <- function(https){
28-
# tf = tempfile()
29-
# dir.create(tf)
30-
# on.exit(unlink(tf))
31-
# testpkg = "memoise"
32-
# repos <- paste0(https, "snapshot/2014-09-12/")
33-
# tryCatch(suppressWarnings(utils::install.packages(testpkg, lib = tf,
34-
# repos = repos ,
35-
# dependencies = FALSE,
36-
# type = "source",
37-
# quiet = TRUE)))
38-
# if(testpkg %in% installed.packages(lib.loc = tf)[, "Package"]) {
39-
# TRUE
40-
# } else {
41-
# FALSE
42-
# }
43-
# }
4427

4528
mranUrlDefault <- function(){
4629
http = "http://mran.microsoft.com/"
@@ -63,30 +46,15 @@ isHttpsUrl <- function(url){
6346
grepl("^https://", url)
6447
}
6548

66-
# setDownloadOption <- function(mranUrl){
67-
#
68-
# download.method <- switch(
69-
# .Platform$OS.type,
70-
# windows = "wininet",
71-
# unix = if(capabilities("libcurl")) "libcurl" else "curl"
72-
# )
73-
# url.method <- switch(
74-
# .Platform$OS.type,
75-
# windows = "wininet",
76-
# unix = if(capabilities("libcurl")) "libcurl" else "internal"
77-
# )
78-
#
79-
# options(download.file.method = download.method,
80-
# url.method = url.method)
81-
# }
82-
#
83-
# resetDownloadOption <- function(opts){
84-
# options(opts)
85-
# }
86-
87-
88-
# ------------------------------------------------------------------------
8949

50+
#' Returns MRAN URL by querying options and defaults.
51+
#'
52+
#' The default MRAN URL is `http(s)://mran.microsoft.com/`, but you can override this by setting the `checkpoint.mranUrl` option.
53+
#'
54+
#'
55+
#' @export
56+
#' @return Character string with URL
57+
#' @family checkpoint functions
9058
mranUrl <- function(){
9159
url <- getOption("checkpoint.mranUrl")
9260
url <- if(is.null(url)) mranUrlDefault() else url
@@ -107,6 +75,9 @@ setCheckpointUrl <- function(url){
10775

10876

10977
tryUrl <- function(url){
78+
timeout <- getOption("timeout")
79+
on.exit(options(timeout = timeout))
80+
options(timeout = 5)
11081
con <- suppressWarnings(tryCatch(url(url), error = function(e)e))
11182
msg <- paste0(
11283
"Invalid value for mranRootUrl.\n",
@@ -118,29 +89,6 @@ tryUrl <- function(url){
11889
con
11990
}
12091

121-
#' Read list of available snapshot dates from MRAN url.
122-
#'
123-
#' @param mranRootUrl URL of MRAN root, e.g. \code{"https://mran.microsoft.com/snapshot/"} or \code{"file:///local/path"}
124-
#'
125-
#' @export
126-
getValidSnapshots <- function(mranRootUrl = mranUrl()){
127-
con <- tryUrl(mranRootUrl)
128-
on.exit(close(con))
129-
text <- if (inherits(con, "file")) {
130-
dir(summary(con)$description)
131-
} else {
132-
suppressWarnings(tryCatch(readLines(con, warn = TRUE), error = function(e) e))
133-
}
134-
if (inherits(text, "error")) {
135-
stop(sprintf("Unable to download from MRAN: %s",
136-
text$message))
137-
}
138-
ptn <- "\\d{4}-\\d{2}-\\d{2}"
139-
idx <- grep(ptn, text)
140-
gsub(sprintf("^<a href=.*?>(%s).*?</a>.*$", ptn),
141-
"\\1", text[idx])
142-
}
143-
14492

14593
# ------------------------------------------------------------------------
14694

R/setSnapshot.R

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#'
55
#' @export
66
#' @example /inst/examples/example_setSnapshot.R
7+
#'
8+
#' @family checkpoint functions
79
#'
810
setSnapshot <- function(snapshotDate){
911
if (missing(snapshotDate) || is.null(snapshotDate)) return(getOption("repos"))
@@ -14,3 +16,32 @@ setSnapshot <- function(snapshotDate){
1416
options(repos = c(CRAN = repoDate))
1517
message(paste("Using CRAN mirror at", repoDate))
1618
}
19+
20+
21+
#' Read list of available snapshot dates from MRAN.
22+
#'
23+
#' Returns vector of available dates from MRAN or local MRAN repository.
24+
#'
25+
#' @param mranRootUrl MRAN root. This can be a URL, e.g. `https://mran.microsoft.com/snapshot/` or the path to a local MRAN repository, e.g.`file:///local/path`
26+
#'
27+
#' @export
28+
#' @return Character vector with dates of valid snapshots
29+
#' @family checkpoint functions
30+
getValidSnapshots <- function(mranRootUrl = mranUrl()){
31+
con <- tryUrl(mranRootUrl)
32+
on.exit(close(con))
33+
text <- if (inherits(con, "file")) {
34+
dir(summary(con)$description)
35+
} else {
36+
suppressWarnings(tryCatch(readLines(con, warn = TRUE), error = function(e) e))
37+
}
38+
if (inherits(text, "error")) {
39+
stop(sprintf("Unable to download from MRAN: %s",
40+
text$message))
41+
}
42+
ptn <- "\\d{4}-\\d{2}-\\d{2}"
43+
idx <- grep(ptn, text)
44+
gsub(sprintf("^<a href=.*?>(%s).*?</a>.*$", ptn),
45+
"\\1", text[idx])
46+
}
47+

man/checkpoint-package.Rd

Lines changed: 9 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)