Skip to content

Commit 294b931

Browse files
committed
Merge branch 'dev'
2 parents 863f697 + 3eea7f9 commit 294b931

File tree

9 files changed

+262
-40
lines changed

9 files changed

+262
-40
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
.Rproj.user
44
checkpoint.Rproj
55
.RData
6+
inst/doc

DESCRIPTION

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ Description: The goal of checkpoint is to solve the problem of package
1616
Immediately after completion of the rsync mirror process, we take a
1717
snapshot, thus creating the archive. Snapshot archives exist starting from
1818
2014-09-17.
19-
Version: 0.3.3
20-
Date: 2014-10-01
19+
Version: 0.3.4
20+
Date: 2015-01-14
2121
Author: Revolution Analytics
2222
Maintainer: Andrie de Vries <[email protected]>
2323
Copyright: Revolution Analytics
@@ -30,3 +30,4 @@ Imports:
3030
knitr
3131
Suggests:
3232
testthat(>= 0.9)
33+
VignetteBuilder: knitr

R/checkpoint.R

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,20 @@ checkpoint <- function(snapshotDate, project = getwd(), verbose=TRUE) {
4040
snapshoturl <- getSnapshotUrl(snapshotDate=snapshotDate)
4141

4242

43-
compiler.path= system.file(package = "compiler")
43+
compiler.path <- system.file(package = "compiler", lib.loc = .Library[1])
4444
# set repos
4545
setMranMirror(snapshotUrl = snapshoturl)
4646

4747
# Set lib path
4848
setLibPaths(snapshotDate)
4949

50-
if(.Platform$OS.type != "windows")
50+
if(.Platform$OS.type == "windows"){
51+
dir.create(file.path(.libPaths(), "compiler"), showWarnings = FALSE)
52+
file.copy(to = .libPaths(), from = compiler.path, recursive = TRUE)
53+
} else {
5154
install.packages(repos = NULL, pkgs = compiler.path, type = "source")
52-
55+
}
56+
5357
mssg(verbose, "Scanning for loaded pkgs")
5458

5559
# Scan for packages used
@@ -58,30 +62,28 @@ checkpoint <- function(snapshotDate, project = getwd(), verbose=TRUE) {
5862
c("base", "compiler", "datasets", "graphics", "grDevices", "grid",
5963
"methods", "parallel", "splines", "stats", "stats4", "tcltk",
6064
"tools", "utils")) # all base priority packages, not on CRAN or MRAN
61-
packages.to.install = setdiff(projectScanPackages(project), exclude.packages)
65+
packages.to.install <- setdiff(projectScanPackages(project), exclude.packages)
6266

67+
# detach checkpointed pkgs already loaded
68+
69+
packages.in.search <- findInSearchPath(packages.to.install)
70+
detachFromSearchPath(packages.in.search)
71+
6372
# install missing packages
6473

6574
if(length(packages.to.install) > 0) {
6675
mssg(verbose, "Installing packages used in this project ")
67-
utils::install.packages(pkgs = packages.to.install, verbose=FALSE, quiet=TRUE)
76+
utils::install.packages(pkgs = packages.to.install, verbose = FALSE, quiet = TRUE)
6877
} else {
6978
mssg(verbose, "No packages found to install")
7079
}
7180

72-
# detach and reload checkpointed pkgs already loaded
73-
search.path = search()
74-
lapply(
75-
unlist(
76-
lapply(
77-
packages.to.install,
78-
grep,
79-
x = search.path)),
80-
function(x) {
81-
detach(x, unload = TRUE, force = TRUE)
82-
library(search.path[x], character.only = TRUE)})
83-
84-
NULL}
81+
# Reload detached packages
82+
if(length(packages.in.search > 0)){
83+
lapply(packages.in.search, library, character.only = TRUE, quietly = TRUE)
84+
}
85+
86+
invisible(NULL)}
8587

8688
setMranMirror <- function(snapshotDate, snapshotUrl = checkpoint:::getSnapShotUrl(snapshotDate)){
8789
options(repos = snapshotUrl)}

R/detach.R

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Given a character vector with package names, construct regular expression that matches search()
2+
makeSearchString <- function(pkg, search = TRUE) {
3+
regex <- "package:%s"
4+
if(search) regex <- paste0(regex, "$")
5+
paste(sprintf(regex, pkg), collapse="|")
6+
}
7+
8+
makeDetachString <- function(pkg) makeSearchString(pkg, search = FALSE)
9+
10+
# Determine if package is in search()
11+
findInSearchPath <- function(pkg){
12+
s <- search()
13+
z <- unlist(
14+
regmatches(s, gregexpr(makeSearchString(pkg), s))
15+
)
16+
setdiff(gsub("package:", "", z), "")
17+
}
18+
19+
# Detach package from search()
20+
detachFromSearchPath <- function(p){
21+
max.n <- 1 + length(p) # Prevent endless loop as a failsafe
22+
n <- 0
23+
repeat {
24+
d <- findInSearchPath(p)
25+
if(length(d) == 0) break # Stop if all packages unloaded
26+
for(to.detach in d){
27+
try({
28+
detach(name = makeDetachString(to.detach), unload = TRUE, force = TRUE, character.only = TRUE)
29+
},
30+
silent = TRUE
31+
)
32+
}
33+
n <- n + 1
34+
if(n > max.n) break
35+
}
36+
}

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ This means the remainder of your script will run with the packages from a specif
3434
Sharing your script to be reproducible is as easy as:
3535

3636
- Load the `checkpoint` package using `library(checkpoint)`
37-
- Ensure you specify `checkpoint()` with your checkpoint date, e.g. `checkpoint("2014-09-17")`
37+
- Ensure you specify `checkpoint()` with your checkpoint date, e.g. `checkpoint("2014-10-01")`
3838

3939
Then send this script to your collaborators. When they run this script on their machine, `checkpoint` will perform the same steps of installing the necessary packages, creating the `checkpoint` snapshot folder and producing the same results.
4040

@@ -67,7 +67,7 @@ cat("library(MASS)", "library(foreach)",
6767
# Create a checkpoint by specifying a snapshot date
6868
6969
library(checkpoint)
70-
checkpoint("2014-09-17")
70+
checkpoint("2014-10-01")
7171
7272
# Check that CRAN mirror is set to MRAN snapshot
7373
getOption("repos")
@@ -98,7 +98,7 @@ To install `checkpoint` directly from github, use the `devtools` package. In yo
9898

9999
```
100100
install.packages("devtools")
101-
devtools::install_github("RevolutionAnalytics/checkpoint", ref="v0.3.3")
101+
devtools::install_github("RevolutionAnalytics/checkpoint", ref="v0.3.4")
102102
library("checkpoint")
103103
```
104104

tests/testthat/test-1-checkpoint.R

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,73 @@
11
# tests for initialize
22
context("checkpoint")
33

4+
Sys.setenv("R_TESTS" = "") # Configure Travis for tests https://github.com/RevolutionAnalytics/checkpoint/issues/139
5+
46
MRAN.start = as.Date("2014-09-17")
57
MRAN.default = as.Date("2014-10-01")
68
MRAN.dates = as.Date(MRAN.start:(Sys.Date()-1), origin = as.Date("1970-01-01"))
9+
10+
packages.to.test = c("MASS", "plyr", "XML", "httr","checkpoint", "stats", "stats4", "compiler")
11+
712
for(snap_date in as.character(c(MRAN.default, MRAN.dates[sample(length(MRAN.dates), 10, replace = FALSE)]))) {
813
project_root <- file.path(tempfile(), "checkpointtemp")
914
dir.create(project_root, recursive = TRUE)
10-
11-
test_that("snapshot functions return correct results", {
15+
16+
test_that(paste("snapshot functions work correctly with snapshot", snap_date), {
1217
skip_on_cran()
13-
Sys.setenv("R_TESTS" = "") # Need this line to configure Travis for tests https://github.com/RevolutionAnalytics/checkpoint/issues/139
14-
18+
message("\n", "Snapshot date: ", snap_date)
19+
1520
checkpoint:::cleanCheckpointFolder(snap_date)
16-
21+
1722
expect_equal(
1823
checkpoint:::getSnapshotUrl(snap_date),
1924
file.path("http://mran.revolutionanalytics.com/snapshot", snap_date))
20-
25+
2126
expect_message(
2227
checkpoint(snap_date, project = project_root),
2328
"No packages found to install")
24-
29+
2530
# Write dummy code file to project
26-
packages.to.test = c("MASS", "plyr", "XML", "httr","checkpoint", "stats", "stats4")
2731
code = paste("library('", packages.to.test, "')", sep ="", collapse ="\n")
2832
cat(code, file = file.path(project_root, "code.R"))
29-
33+
3034
expect_message(
3135
checkpoint(snap_date, project = project_root),
3236
"Installing packages used in this project")
33-
34-
x <- installed.packages(fields = "Date/Publication")
35-
expect_equivalent(
36-
sort(x[, "Package"]),
37-
sort(c("bitops", "digest", "httr", "jsonlite", "MASS", "plyr", "Rcpp",
38-
"RCurl", "stringr", "XML")))
37+
38+
x <- installed.packages(fields = "Date/Publication", noCache = TRUE)
39+
40+
base.packages <- unname(installed.packages(priority = "base", lib.loc = .Library)[, "Package"])
41+
packages.expected <- sort(unique(unlist(
42+
43+
sapply(setdiff(packages.to.test, c("checkpoint", base.packages)), function(p){
44+
z <- tools::pkgDepends(p)
45+
c(z$Depends, z$Imports)
46+
}, USE.NAMES = FALSE)
47+
)))
48+
49+
expect_true(
50+
all(setdiff(packages.to.test, c("checkpoint", base.packages)) %in% unname(x[, "Package"])))
51+
52+
expect_true(
53+
all(setdiff(packages.expected, c("checkpoint", base.packages)) %in% unname(x[, "Package"])))
3954

4055
expect_true(
4156
all(
4257
na.omit(
4358
x[, "Date/Publication"]) <=
4459
as.POSIXct(snap_date, tz="UTC")))
4560

61+
expect_true(
62+
all(sapply(setdiff(packages.to.test, "checkpoint"), require, character.only = TRUE, quietly = TRUE)))
63+
4664
expect_equal(
4765
getOption("repos"),
4866
file.path("http://mran.revolutionanalytics.com/snapshot", snap_date))
49-
67+
5068
expect_equal(
5169
checkpoint:::checkpointPath(snap_date, "lib"),
5270
normalizePath(.libPaths()[1]))})
5371
# cleanup
5472
checkpoint:::cleanCheckpointFolder(snap_date)
55-
}
73+
}

vignettes/checkpoint-pkg.png

29.2 KB
Loading

vignettes/checkpoint-server.png

20.6 KB
Loading

0 commit comments

Comments
 (0)