Skip to content

Commit e8da46c

Browse files
committed
Merge branch 'dev'
2 parents 2db8431 + fa6e97f commit e8da46c

File tree

14 files changed

+405
-140
lines changed

14 files changed

+405
-140
lines changed

DESCRIPTION

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@ Description: The goal of checkpoint is to solve the problem of package
1616
Immediately after completion of the rsync mirror process, the process takes a
1717
snapshot, thus creating the archive. Snapshot archives exist starting from
1818
2014-09-17.
19-
Version: 0.3.10
20-
Date: 2015-04-27
19+
Version: 0.3.11
20+
Date: 2015-08-04
2121
Author: Revolution Analytics
2222
Maintainer: Andrie de Vries <[email protected]>
2323
Copyright: Revolution Analytics
2424
License: GPL-2
2525
URL: http://projects.revolutionanalytics.com/documents/rrt/rrtpkgs/
2626
BugReports: http://www.github.com/RevolutionAnalytics/checkpoint/issues
2727
Imports:
28-
utils
28+
utils,
29+
xml2
2930
Depends:
3031
R(>= 3.1.1)
3132
Suggests:

NAMESPACE

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
# Generated by roxygen2 (4.1.0): do not edit by hand
1+
# Generated by roxygen2 (4.1.1): do not edit by hand
22

33
export(checkpoint)
4+
export(getValidSnapshots)
45
export(setSnapshot)
56
importFrom(utils,install.packages)
7+
importFrom(xml2,read_xml)
8+
importFrom(xml2,xml_find_all)
9+
importFrom(xml2,xml_text)

R/checkpoint-package.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#'
55
#' 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.
66
#'
7-
#' To create the snapshot archives, once a day (at midnight UTC) we refresh the Austria CRAN mirror, on the checkpoint server (http://mran.revolutionanalytics.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.revolutionanalytics.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
#'
99
#' checkpoint exposes only a single function:
1010
#'

R/checkpoint.R

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ checkpoint <- function(snapshotDate, project = getwd(), R.version, scanForPackag
4747
verbose=TRUE,
4848
use.knitr = system.file(package="knitr") != "") {
4949

50+
stopIfInvalidDate(snapshotDate)
51+
5052
if(!missing("R.version") && !is.null(R.version)){
5153
if(!correctR(as.character(R.version))){
5254
message <- sprintf("Specified R.version %s does not match current R (%s)",
@@ -66,7 +68,10 @@ checkpoint <- function(snapshotDate, project = getwd(), R.version, scanForPackag
6668
stop("Unable to create checkpoint folders at checkpointLocation = \"", checkpointLocation, "\"")
6769

6870

69-
snapshoturl <- getSnapshotUrl(snapshotDate=snapshotDate)
71+
mran <- mranUrl()
72+
opts <- setDownloadOption(mran)
73+
on.exit(options(opts))
74+
snapshoturl <- getSnapshotUrl(snapshotDate = snapshotDate)
7075

7176

7277
compiler.path <- system.file(package = "compiler", lib.loc = .Library[1])
@@ -127,6 +132,7 @@ checkpoint <- function(snapshotDate, project = getwd(), R.version, scanForPackag
127132

128133
# install missing packages
129134

135+
130136
if(length(packages.to.install) > 0) {
131137
mssg(verbose, "Installing packages used in this project ")
132138
for(pkg in packages.to.install){
@@ -135,7 +141,8 @@ checkpoint <- function(snapshotDate, project = getwd(), R.version, scanForPackag
135141
} else {
136142
mssg(verbose, " - Installing ", sQuote(pkg))
137143
suppressWarnings(
138-
utils::install.packages(pkgs = pkg, verbose = FALSE, quiet = TRUE)
144+
utils::install.packages(pkgs = pkg, verbose = FALSE, quiet = TRUE,
145+
INSTALL_opts = "--no-lock")
139146
)
140147
}
141148
}
@@ -171,31 +178,8 @@ setMranMirror <- function(snapshotDate, snapshotUrl = checkpoint:::getSnapShotUr
171178
setLibPaths <- function(checkpointLocation, libPath){
172179
assign(".lib.loc", c(libPath, checkpointBasePkgs(checkpointLocation)), envir = environment(.libPaths))}
173180

174-
mranUrl <- function()"http://mran.revolutionanalytics.com/snapshot/"
175181

176-
getSnapshotUrl <- function(snapshotDate, url = mranUrl()){
177-
mran.root = url(url)
178-
snapshot.url = paste(gsub("/$", "", url), snapshotDate, sep = "/")
179-
on.exit(close(mran.root))
180-
tryCatch(
181-
suppressWarnings(readLines(mran.root)),
182-
error =
183-
function(e) {
184-
warning(sprintf("Unable to reach MRAN: %s", e$message))
185-
return(snapshot.url)
186-
}
187-
)
188-
con = url(snapshot.url)
189-
on.exit(close(con), add = TRUE)
190-
tryCatch(
191-
suppressWarnings(readLines(con)),
192-
error =
193-
function(e) {
194-
warning("Unable to find snapshot on MRAN")
195-
return(snapshot.url)
196-
}
197-
)
198-
snapshot.url}
182+
199183

200184

201185
mssg <- function(x, ...) if(x) message(...)

R/detach.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ detachFromSearchPath <- function(p){
2626
for(to.detach in d){
2727
try({
2828
suppressWarnings(
29-
detach(name = makeDetachString(to.detach), unload = TRUE, force = TRUE, character.only = TRUE)
30-
)},
31-
silent = TRUE
29+
detach(name = makeDetachString(to.detach), unload = TRUE,
30+
force = TRUE, character.only = TRUE)
31+
)},
32+
silent = TRUE
3233
)
3334
}
3435
n <- n + 1

R/mranUrl.R

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
2+
stopIfInvalidDate <- function(snapshotDate){
3+
if(missing(snapshotDate) || is.null(snapshotDate))
4+
stop("You have to specify a snapshotDate", call. = FALSE)
5+
if(!grepl("^\\d{4}-\\d{2}-\\d{2}$", snapshotDate))
6+
stop("snapshotDate must be a valid date using format YYYY-MM-DD", call. = FALSE)
7+
if(as.Date(snapshotDate) < as.Date("2014-09-17"))
8+
stop("Snapshots are only available after 2014-09-17", call. = FALSE)
9+
if(as.Date(snapshotDate) > Sys.Date())
10+
stop("snapshotDate can not be in the future!", call. = FALSE)
11+
12+
}
13+
14+
testHttps <- function(https){
15+
tf = tempfile()
16+
dir.create(tf)
17+
on.exit(unlink(tf))
18+
testpkg = "memoise"
19+
repos <- paste0(https, "snapshot/2014-09-12/")
20+
tryCatch(utils::install.packages(testpkg, lib = tf,
21+
repos = repos ,
22+
dependencies = FALSE,
23+
type = "source",
24+
quiet = TRUE))
25+
if(testpkg %in% names(installed.packages(lib.loc = tf)[, "Package"])) {
26+
TRUE
27+
} else {
28+
FALSE
29+
}
30+
}
31+
32+
mranUrlDefault <- function(){
33+
http = "http://mran.revolutionanalytics.com/"
34+
https = gsub("http://", replacement = "https://", http)
35+
if(getRversion() >= "3.2.0") {
36+
if(testHttps(https)) https else http
37+
} else {
38+
http
39+
}
40+
}
41+
42+
getDownloadOption <- function(){
43+
getOption("download.file.method")
44+
}
45+
46+
47+
isHttpsUrl <- function(url){
48+
grepl("^https://", url)
49+
}
50+
51+
setDownloadOption <- function(mranUrl){
52+
53+
# is.recent = getRversion() >= "3.2.2"
54+
# is.unix = .Platform$OS.type == "unix"
55+
is.os.x = length(grep(pattern = "darwin", R.version$os)) > 0
56+
# is.win = .Platform$OS.type == "windows"
57+
58+
method <- if(isHttpsUrl(mranUrl)){
59+
switch(.Platform$OS.type,
60+
windows = "wininet",
61+
unix = if(capabilities("libcurl")) "libcurl" else "wget"
62+
)
63+
} else {
64+
switch(.Platform$OS.type,
65+
windows = {utils::setInternet2(TRUE); "wininet"},
66+
unix = if(is.os.x) "curl" else "wget"
67+
)
68+
}
69+
70+
options(download.file.method = method, url.method = method)
71+
}
72+
73+
resetDownloadOption <- function(opts){
74+
options(opts)
75+
}
76+
77+
78+
# ------------------------------------------------------------------------
79+
80+
mranUrl <- function(){
81+
url <- getOption("checkpoint.mranUrl")
82+
url <- if(is.null(url)) mranUrlDefault() else url
83+
url <- gsub("snapshot/*$", "", url)
84+
if(substring(url, nchar(url)) != "/") url <- paste0(url, "/")
85+
86+
paste0(url, "snapshot/")
87+
}
88+
89+
90+
91+
setCheckpointUrl <- function(url){
92+
options("checkpoint.mranUrl" = url)
93+
}
94+
95+
96+
# ------------------------------------------------------------------------
97+
98+
99+
100+
#' Read list of available snapshot dates from MRAN url.
101+
#'
102+
#' @param mranRootUrl URL of MRAN root, e.g. \code{"http://mran.revolutionanalytics.com/snapshot/"}
103+
#'
104+
#' @importFrom xml2 read_xml xml_find_all xml_text
105+
#' @export
106+
getValidSnapshots <- function(mranRootUrl = mranUrl()){
107+
opts <- setDownloadOption(mranRootUrl)
108+
on.exit(resetDownloadOption(opts))
109+
text <- tryCatch(suppressWarnings(read_xml(mranRootUrl, as_html = TRUE)), error=function(e)e)
110+
if(inherits(text, "error")) {
111+
stop(sprintf("Unable to download from MRAN: %s", text$message))
112+
}
113+
links <- xml_find_all(text, "//a")
114+
dates <- xml_text(links)
115+
idx <- grep("\\d{4}-\\d{2}-\\d{2}/", dates)
116+
gsub("/$", "", dates[idx])
117+
}
118+
119+
120+
# ------------------------------------------------------------------------
121+
122+
getSnapshotUrl <- function(snapshotDate, mranRootUrl = mranUrl()){
123+
124+
opts <- setDownloadOption(mranRootUrl)
125+
on.exit(resetDownloadOption(opts))
126+
mran.root = url(mranRootUrl)
127+
snapshot.url = paste(gsub("/$", "", mranRootUrl), snapshotDate, sep = "/")
128+
on.exit(close(mran.root))
129+
res <- tryCatch(
130+
suppressWarnings(readLines(mran.root)),
131+
error = function(e) e
132+
)
133+
if(inherits(res, "error")) {
134+
warning("Unable to reach MRAN root at ", mranRootUrl, call. = FALSE)
135+
return(snapshot.url)
136+
}
137+
138+
con = url(snapshot.url)
139+
on.exit(close(con), add = TRUE)
140+
res <- tryCatch(
141+
suppressWarnings(readLines(con)),
142+
error = function(e) e
143+
)
144+
if(inherits(res, "error")) {
145+
warning("Unable to find snapshot on MRAN at ", snapshot.url, call. = FALSE)
146+
return(snapshot.url)
147+
}
148+
snapshot.url
149+
}
150+

R/setSnapshot.R

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
#' Set default CRAN repository to MRAN snapshot date.
2-
#'
2+
#'
33
#' @inheritParams checkpoint
4-
#'
4+
#'
55
#' @export
66
#' @example /inst/examples/example_setSnapshot.R
7-
#'
7+
#'
88
setSnapshot <- function(snapshotDate){
99
if (missing(snapshotDate) || is.null(snapshotDate)) return(getOption("repos"))
10-
repoDate <- paste0("http://mran.revolutionanalytics.com/snapshot/", snapshotDate)
10+
mran <- mranUrl()
11+
repoDate <- paste0(mran, snapshotDate)
12+
setDownloadOption(mran)
1113
response <- tryCatch(
1214
suppressWarnings(readLines(repoDate)),
1315
error = function(e)e

man/checkpoint-package.Rd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% Generated by roxygen2 (4.1.0): do not edit by hand
1+
% Generated by roxygen2 (4.1.1): do not edit by hand
22
% Please edit documentation in R/checkpoint-package.R
33
\docType{package}
44
\name{checkpoint-package}
@@ -10,7 +10,7 @@ The goal of checkpoint is to solve the problem of package reproducibility in R.
1010
\details{
1111
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.
1212

13-
To create the snapshot archives, once a day (at midnight UTC) we refresh the Austria CRAN mirror, on the checkpoint server (http://mran.revolutionanalytics.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.
13+
To create the snapshot archives, once a day (at midnight UTC) we refresh the Austria CRAN mirror, on the checkpoint server (https://mran.revolutionanalytics.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.
1414

1515
checkpoint exposes only a single function:
1616

man/checkpoint.Rd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% Generated by roxygen2 (4.1.0): do not edit by hand
1+
% Generated by roxygen2 (4.1.1): do not edit by hand
22
% Please edit documentation in R/checkpoint.R
33
\name{checkpoint}
44
\alias{checkpoint}

man/getValidSnapshots.Rd

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
% Generated by roxygen2 (4.1.1): do not edit by hand
2+
% Please edit documentation in R/mranUrl.R
3+
\name{getValidSnapshots}
4+
\alias{getValidSnapshots}
5+
\title{Read list of available snapshot dates from MRAN url.}
6+
\usage{
7+
getValidSnapshots(mranRootUrl = mranUrl())
8+
}
9+
\arguments{
10+
\item{mranRootUrl}{URL of MRAN root, e.g. \code{"http://mran.revolutionanalytics.com/snapshot/"}}
11+
}
12+
\description{
13+
Read list of available snapshot dates from MRAN url.
14+
}
15+

0 commit comments

Comments
 (0)