Skip to content

Commit 7c083a7

Browse files
committed
Merge branch 'dev'
2 parents bb0508f + 1c9f35e commit 7c083a7

File tree

12 files changed

+186
-76
lines changed

12 files changed

+186
-76
lines changed

DESCRIPTION

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ Description: The goal of checkpoint is to solve the problem of package
1111
updates that came later and may have altered your results. In this way,
1212
anyone using checkpoint's checkpoint() can ensure the reproducibility of
1313
your scripts or projects at any time. To create the snapshot archives, once
14-
a day (at midnight UTC) we refresh the Austria CRAN mirror, on the "Managed
14+
a day (at midnight UTC) Revolution Analytics refreshes the Austria CRAN mirror, on the "Managed
1515
R Archived Network" server (http://mran.revolutionanalytics.com/).
16-
Immediately after completion of the rsync mirror process, we take a
16+
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.9
20-
Date: 2015-03-17
19+
Version: 0.3.10
20+
Date: 2015-04-27
2121
Author: Revolution Analytics
2222
Maintainer: Andrie de Vries <[email protected]>
2323
Copyright: Revolution Analytics

NAMESPACE

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

33
export(checkpoint)
4+
export(setSnapshot)
45
importFrom(utils,install.packages)

R/checkpoint.R

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ checkpoint <- function(snapshotDate, project = getwd(), R.version, scanForPackag
4646
checkpointLocation = "~/",
4747
verbose=TRUE,
4848
use.knitr = system.file(package="knitr") != "") {
49-
49+
5050
if(!missing("R.version") && !is.null(R.version)){
5151
if(!correctR(as.character(R.version))){
5252
message <- sprintf("Specified R.version %s does not match current R (%s)",
@@ -57,41 +57,39 @@ checkpoint <- function(snapshotDate, project = getwd(), R.version, scanForPackag
5757
stop(message)
5858
}
5959
}
60-
60+
6161
checkpointLocation = authorizeFileSystemUse(checkpointLocation)
62-
62+
6363
fixRstudioBug()
64-
64+
6565
if(!createFolders(snapshotDate = snapshotDate, checkpointLocation = checkpointLocation))
6666
stop("Unable to create checkpoint folders at checkpointLocation = \"", checkpointLocation, "\"")
67-
68-
67+
68+
6969
snapshoturl <- getSnapshotUrl(snapshotDate=snapshotDate)
70-
71-
70+
71+
7272
compiler.path <- system.file(package = "compiler", lib.loc = .Library[1])
73-
# set repos
74-
setMranMirror(snapshotUrl = snapshoturl)
75-
73+
7674
libPath <- checkpointPath(snapshotDate, type = "lib", checkpointLocation = checkpointLocation)
7775
installMissingBasePackages(checkpointLocation = checkpointLocation)
78-
76+
7977
# Set lib path
8078
setLibPaths(checkpointLocation = checkpointLocation, libPath = libPath)
81-
79+
8280
# Scan for packages used
8381
exclude.packages = c("checkpoint", # this very package
8482
c("base", "compiler", "datasets", "graphics", "grDevices", "grid",
8583
"methods", "parallel", "splines", "stats", "stats4", "tcltk",
8684
"tools", "utils")) # all base priority packages, not on CRAN or MRAN
8785
packages.installed <- unname(installed.packages()[, "Package"])
88-
86+
8987
if(isTRUE(scanForPackages)){
9088
mssg(verbose, "Scanning for packages used in this project")
9189
pkgs <- projectScanPackages(project, use.knitr = use.knitr)
9290
packages.detected <- pkgs[["pkgs"]]
9391
mssg(verbose, "- Discovered ", length(packages.detected), " packages")
94-
92+
9593
if(length(pkgs[["error"]]) > 0){
9694
files.not.parsed <- pkgs[["error"]]
9795
mssg(verbose, "Unable to parse ", length(pkgs[["error"]]), " files:")
@@ -103,18 +101,20 @@ checkpoint <- function(snapshotDate, project = getwd(), R.version, scanForPackag
103101
packages.detected <- character(0)
104102
files.not.parsed <- character(0)
105103
}
106-
107-
104+
105+
108106
packages.to.install <- setdiff(packages.detected, c(packages.installed, exclude.packages))
109-
107+
110108
# detach checkpointed pkgs already loaded
111-
109+
112110
packages.in.search <- findInSearchPath(packages.to.install)
113111
detachFromSearchPath(packages.in.search)
114-
112+
115113
# check if packages are available in snapshot
116-
114+
117115
if(length(packages.to.install) > 0) {
116+
# set repos
117+
setMranMirror(snapshotUrl = snapshoturl)
118118
not.available <- !packages.to.install %in% available.packages()[, "Package"]
119119
if(sum(not.available > 0)){
120120
mssg(verbose, "Packages not available in repository and won't be installed:")
@@ -124,9 +124,9 @@ checkpoint <- function(snapshotDate, project = getwd(), R.version, scanForPackag
124124
} else {
125125
not.available <- character(0)
126126
}
127-
127+
128128
# install missing packages
129-
129+
130130
if(length(packages.to.install) > 0) {
131131
mssg(verbose, "Installing packages used in this project ")
132132
for(pkg in packages.to.install){
@@ -144,15 +144,15 @@ checkpoint <- function(snapshotDate, project = getwd(), R.version, scanForPackag
144144
} else {
145145
if(isTRUE(scanForPackages)) mssg(verbose, "No packages found to install")
146146
}
147-
147+
148148
# Reload detached packages
149149
if(length(packages.in.search > 0)){
150150
lapply(packages.in.search, library, character.only = TRUE, quietly = TRUE)
151151
}
152-
152+
153153
mssg(verbose, "checkpoint process complete")
154154
mssg(verbose, "---")
155-
155+
156156
z <- list(
157157
files_not_scanned = files.not.parsed,
158158
pkgs_found = packages.detected,
@@ -161,30 +161,40 @@ checkpoint <- function(snapshotDate, project = getwd(), R.version, scanForPackag
161161
)
162162
invisible(z)}
163163

164+
165+
# ------------------------------------------------------------------------
166+
167+
164168
setMranMirror <- function(snapshotDate, snapshotUrl = checkpoint:::getSnapShotUrl(snapshotDate)){
165169
options(repos = snapshotUrl)}
166170

167171
setLibPaths <- function(checkpointLocation, libPath){
168-
assign(".lib.loc", c(libPath, checkpointBasePkgs(checkpointLocation)), envir = environment(.libPaths))}
172+
assign(".lib.loc", c(libPath, checkpointBasePkgs(checkpointLocation)), envir = environment(.libPaths))}
169173

170174
mranUrl <- function()"http://mran.revolutionanalytics.com/snapshot/"
171175

172176
getSnapshotUrl <- function(snapshotDate, url = mranUrl()){
173177
mran.root = url(url)
178+
snapshot.url = paste(gsub("/$", "", url), snapshotDate, sep = "/")
174179
on.exit(close(mran.root))
175180
tryCatch(
176181
suppressWarnings(readLines(mran.root)),
177182
error =
178183
function(e) {
179-
stop(sprintf("Unable to reach MRAN: %s", e$message))})
180-
snapshot.url = paste(gsub("/$", "", url), snapshotDate, sep = "/")
184+
warning(sprintf("Unable to reach MRAN: %s", e$message))
185+
return(snapshot.url)
186+
}
187+
)
181188
con = url(snapshot.url)
182189
on.exit(close(con), add = TRUE)
183190
tryCatch(
184191
suppressWarnings(readLines(con)),
185192
error =
186193
function(e) {
187-
stop("Unable to find snapshot on MRAN")})
194+
warning("Unable to find snapshot on MRAN")
195+
return(snapshot.url)
196+
}
197+
)
188198
snapshot.url}
189199

190200

R/checkpoint_paths.R

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ checkpointPath <- function(snapshotDate, checkpointLocation,
88
if(type == "base") return(
99
normalizePath(
1010
file.path(rootPath, paste0("R-", getRversion())),
11-
winslash = "/", mustWork = FALSE)
11+
winslash = "/", mustWork = FALSE)
1212
)
1313
snapshotPath <- file.path(rootPath, snapshotDate)
1414
libPath <- file.path(snapshotPath, "lib", R.version$platform, base::getRversion())
@@ -45,9 +45,14 @@ authorizeFileSystemUse =
4545
else {
4646
if(interactive()) {
4747
answer = readline(paste("Can I create directory", checkpointRoot, "for internal checkpoint use?(y/n)\n"))
48-
if(answer != "y")
48+
if(tolower(answer) != "y")
4949
stop("Cannot proceed without access to checkpoint directory")}
5050
else {
51-
warning("Will have to use a temporary directory for internal use. All information will be lost at the end of session")
52-
checkpointLocation = tempdir()}}
53-
checkpointLocation}
51+
stop(paste(
52+
"The .checkpoint folder does not exist. Please try again after creating the folder at",
53+
normalizePath(checkpointRoot)
54+
))
55+
}
56+
}
57+
checkpointLocation
58+
}

R/setSnapshot.R

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#' Set default CRAN repository to MRAN snapshot date.
2+
#'
3+
#' @inheritParams checkpoint
4+
#'
5+
#' @export
6+
#' @example /inst/examples/example_setSnapshot.R
7+
#'
8+
setSnapshot <- function(snapshotDate){
9+
if (missing(snapshotDate) || is.null(snapshotDate)) return(getOption("repos"))
10+
repoDate <- paste0("http://mran.revolutionanalytics.com/snapshot/", snapshotDate)
11+
response <- tryCatch(
12+
suppressWarnings(readLines(repoDate)),
13+
error = function(e)e
14+
)
15+
if(inherits(response, "error")) stop(paste0("Invalid snapshot date."))
16+
options(repos = c(CRAN = repoDate))
17+
message(paste("Using CRAN mirror at", repoDate))
18+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Empty date field returns current repo
2+
3+
oldRepos <- getOption("repos")
4+
setSnapshot()
5+
6+
# Valid snapshot date
7+
setSnapshot("2014-11-16")
8+
9+
# Invalid snapshot date (in future), returns error
10+
\dontrun{
11+
setSnapshot("2100-01-01")
12+
}
13+
14+
options(repos = oldRepos)

man/checkpoint-package.Rd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
% Generated by roxygen2 (4.0.2): do not edit by hand
1+
% Generated by roxygen2 (4.1.0): do not edit by hand
2+
% Please edit documentation in R/checkpoint-package.R
23
\docType{package}
34
\name{checkpoint-package}
45
\alias{checkpoint-package}

man/checkpoint.Rd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
% Generated by roxygen2 (4.0.2): do not edit by hand
1+
% Generated by roxygen2 (4.1.0): do not edit by hand
2+
% Please edit documentation in R/checkpoint.R
23
\name{checkpoint}
34
\alias{checkpoint}
45
\title{Configures R session to use packages as they existed on CRAN at time of snapshot.}

man/setSnapshot.Rd

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
% Generated by roxygen2 (4.1.0): do not edit by hand
2+
% Please edit documentation in R/setSnapshot.R
3+
\name{setSnapshot}
4+
\alias{setSnapshot}
5+
\title{Set default CRAN repository to MRAN snapshot date.}
6+
\usage{
7+
setSnapshot(snapshotDate)
8+
}
9+
\arguments{
10+
\item{snapshotDate}{Date of snapshot to use in \code{YYYY-MM-DD} format,e.g. \code{"2014-09-17"}. Specify a date on or after \code{"2014-09-17"}. MRAN takes one snapshot per day.}
11+
}
12+
\description{
13+
Set default CRAN repository to MRAN snapshot date.
14+
}
15+
\examples{
16+
# Empty date field returns current repo
17+
18+
oldRepos <- getOption("repos")
19+
setSnapshot()
20+
21+
# Valid snapshot date
22+
setSnapshot("2014-11-16")
23+
24+
# Invalid snapshot date (in future), returns error
25+
\dontrun{
26+
setSnapshot("2100-01-01")
27+
}
28+
29+
options(repos = oldRepos)
30+
}
31+

tests/testthat/test-0-snapshots.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ context("MRAN snapshots")
22

33
test_that("snapshot functions return correct results", {
44
skip_on_cran()
5-
expect_error(
5+
expect_warning(
66
getSnapshotUrl("1972-01-01"))
77

88
dd <- "2014-09-08"

0 commit comments

Comments
 (0)