Skip to content

Commit a7ed932

Browse files
committed
packify
1 parent 8e67266 commit a7ed932

33 files changed

+385
-0
lines changed

.Rprofile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#### -- Packrat Autoloader (version 0.4.6-1) -- ####
2+
source("packrat/init.R")
3+
#### -- End Packrat Autoloader -- ####

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.Rhistory
33
.RData
44
.DS_Store
5+
packrat/lib*/

packrat/init.R

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
local({
2+
3+
## Helper function to get the path to the library directory for a
4+
## given packrat project.
5+
getPackratLibDir <- function(projDir = NULL) {
6+
path <- file.path("packrat", "lib", R.version$platform, getRversion())
7+
8+
if (!is.null(projDir)) {
9+
10+
## Strip trailing slashes if necessary
11+
projDir <- sub("/+$", "", projDir)
12+
13+
## Only prepend path if different from current working dir
14+
if (!identical(normalizePath(projDir), normalizePath(getwd())))
15+
path <- file.path(projDir, path)
16+
}
17+
18+
path
19+
}
20+
21+
## Ensure that we set the packrat library directory relative to the
22+
## project directory. Normally, this should be the working directory,
23+
## but we also use '.rs.getProjectDirectory()' if necessary (e.g. we're
24+
## rebuilding a project while within a separate directory)
25+
libDir <- if (exists(".rs.getProjectDirectory"))
26+
getPackratLibDir(.rs.getProjectDirectory())
27+
else
28+
getPackratLibDir()
29+
30+
## Unload packrat in case it's loaded -- this ensures packrat _must_ be
31+
## loaded from the private library. Note that `requireNamespace` will
32+
## succeed if the package is already loaded, regardless of lib.loc!
33+
if ("packrat" %in% loadedNamespaces())
34+
try(unloadNamespace("packrat"), silent = TRUE)
35+
36+
if (suppressWarnings(requireNamespace("packrat", quietly = TRUE, lib.loc = libDir))) {
37+
38+
# Check 'print.banner.on.startup' -- when NA and RStudio, don't print
39+
print.banner <- packrat::get_opts("print.banner.on.startup")
40+
if (print.banner == "auto" && is.na(Sys.getenv("RSTUDIO", unset = NA))) {
41+
print.banner <- TRUE
42+
} else {
43+
print.banner <- FALSE
44+
}
45+
return(packrat::on(print.banner = print.banner))
46+
}
47+
48+
## Escape hatch to allow RStudio to handle bootstrapping. This
49+
## enables RStudio to provide print output when automagically
50+
## restoring a project from a bundle on load.
51+
if (!is.na(Sys.getenv("RSTUDIO", unset = NA)) &&
52+
is.na(Sys.getenv("RSTUDIO_PACKRAT_BOOTSTRAP", unset = NA))) {
53+
Sys.setenv("RSTUDIO_PACKRAT_BOOTSTRAP" = "1")
54+
setHook("rstudio.sessionInit", function(...) {
55+
# Ensure that, on sourcing 'packrat/init.R', we are
56+
# within the project root directory
57+
if (exists(".rs.getProjectDirectory")) {
58+
owd <- getwd()
59+
setwd(.rs.getProjectDirectory())
60+
on.exit(setwd(owd), add = TRUE)
61+
}
62+
source("packrat/init.R")
63+
})
64+
return(invisible(NULL))
65+
}
66+
67+
## Bootstrapping -- only performed in interactive contexts,
68+
## or when explicitly asked for on the command line
69+
if (interactive() || "--bootstrap-packrat" %in% commandArgs(TRUE)) {
70+
71+
message("Packrat is not installed in the local library -- ",
72+
"attempting to bootstrap an installation...")
73+
74+
## We need utils for the following to succeed -- there are calls to functions
75+
## in 'restore' that are contained within utils. utils gets loaded at the
76+
## end of start-up anyhow, so this should be fine
77+
library("utils", character.only = TRUE)
78+
79+
## Install packrat into local project library
80+
packratSrcPath <- list.files(full.names = TRUE,
81+
file.path("packrat", "src", "packrat")
82+
)
83+
84+
## No packrat tarballs available locally -- try some other means of installation
85+
if (!length(packratSrcPath)) {
86+
87+
message("> No source tarball of packrat available locally")
88+
89+
## There are no packrat sources available -- try using a version of
90+
## packrat installed in the user library to bootstrap
91+
if (requireNamespace("packrat", quietly = TRUE) && packageVersion("packrat") >= "0.2.0.99") {
92+
message("> Using user-library packrat (",
93+
packageVersion("packrat"),
94+
") to bootstrap this project")
95+
}
96+
97+
## Couldn't find a user-local packrat -- try finding and using devtools
98+
## to install
99+
else if (requireNamespace("devtools", quietly = TRUE)) {
100+
message("> Attempting to use devtools::install_github to install ",
101+
"a temporary version of packrat")
102+
library(stats) ## for setNames
103+
devtools::install_github("rstudio/packrat")
104+
}
105+
106+
## Try downloading packrat from CRAN if available
107+
else if ("packrat" %in% rownames(available.packages())) {
108+
message("> Installing packrat from CRAN")
109+
install.packages("packrat")
110+
}
111+
112+
## Fail -- couldn't find an appropriate means of installing packrat
113+
else {
114+
stop("Could not automatically bootstrap packrat -- try running ",
115+
"\"'install.packages('devtools'); devtools::install_github('rstudio/packrat')\"",
116+
"and restarting R to bootstrap packrat.")
117+
}
118+
119+
# Restore the project, unload the temporary packrat, and load the private packrat
120+
packrat::restore(prompt = FALSE, restart = TRUE)
121+
122+
## This code path only reached if we didn't restart earlier
123+
unloadNamespace("packrat")
124+
requireNamespace("packrat", lib.loc = libDir, quietly = TRUE)
125+
return(packrat::on())
126+
127+
}
128+
129+
## Multiple packrat tarballs available locally -- try to choose one
130+
## TODO: read lock file and infer most appropriate from there; low priority because
131+
## after bootstrapping packrat a restore should do the right thing
132+
if (length(packratSrcPath) > 1) {
133+
warning("Multiple versions of packrat available in the source directory;",
134+
"using packrat source:\n- ", shQuote(packratSrcPath))
135+
packratSrcPath <- packratSrcPath[[1]]
136+
}
137+
138+
139+
lib <- file.path("packrat", "lib", R.version$platform, getRversion())
140+
if (!file.exists(lib)) {
141+
dir.create(lib, recursive = TRUE)
142+
}
143+
lib <- normalizePath(lib, winslash = "/")
144+
145+
message("> Installing packrat into project private library:")
146+
message("- ", shQuote(lib))
147+
148+
surround <- function(x, with) {
149+
if (!length(x)) return(character())
150+
paste0(with, x, with)
151+
}
152+
153+
## The following is performed because a regular install.packages call can fail
154+
peq <- function(x, y) paste(x, y, sep = " = ")
155+
installArgs <- c(
156+
peq("pkgs", surround(packratSrcPath, with = "'")),
157+
peq("lib", surround(lib, with = "'")),
158+
peq("repos", "NULL"),
159+
peq("type", surround("source", with = "'"))
160+
)
161+
installCmd <- paste(sep = "",
162+
"utils::install.packages(",
163+
paste(installArgs, collapse = ", "),
164+
")")
165+
166+
fullCmd <- paste(
167+
surround(file.path(R.home("bin"), "R"), with = "\""),
168+
"--vanilla",
169+
"--slave",
170+
"-e",
171+
surround(installCmd, with = "\"")
172+
)
173+
system(fullCmd)
174+
175+
## Tag the installed packrat so we know it's managed by packrat
176+
## TODO: should this be taking information from the lockfile? this is a bit awkward
177+
## because we're taking an un-annotated packrat source tarball and simply assuming it's now
178+
## an 'installed from source' version
179+
180+
## -- InstallAgent -- ##
181+
installAgent <- 'InstallAgent: packrat 0.4.6-1'
182+
183+
## -- InstallSource -- ##
184+
installSource <- 'InstallSource: source'
185+
186+
packratDescPath <- file.path(lib, "packrat", "DESCRIPTION")
187+
DESCRIPTION <- readLines(packratDescPath)
188+
DESCRIPTION <- c(DESCRIPTION, installAgent, installSource)
189+
cat(DESCRIPTION, file = packratDescPath, sep = "\n")
190+
191+
# Otherwise, continue on as normal
192+
message("> Attaching packrat")
193+
library("packrat", character.only = TRUE, lib.loc = lib)
194+
195+
message("> Restoring library")
196+
restore(restart = FALSE)
197+
198+
# If the environment allows us to restart, do so with a call to restore
199+
restart <- getOption("restart")
200+
if (!is.null(restart)) {
201+
message("> Packrat bootstrap successfully completed. ",
202+
"Restarting R and entering packrat mode...")
203+
return(restart())
204+
}
205+
206+
# Callers (source-erers) can define this hidden variable to make sure we don't enter packrat mode
207+
# Primarily useful for testing
208+
if (!exists(".__DONT_ENTER_PACKRAT_MODE__.") && interactive()) {
209+
message("> Packrat bootstrap successfully completed. Entering packrat mode...")
210+
packrat::on()
211+
}
212+
213+
Sys.unsetenv("RSTUDIO_PACKRAT_BOOTSTRAP")
214+
215+
}
216+
217+
})

packrat/packrat.lock

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
PackratFormat: 1.4
2+
PackratVersion: 0.4.6.1
3+
RVersion: 3.2.3
4+
Repos: BioCsoft=http://bioconductor.org/packages/3.1/bioc,
5+
BioCann=http://bioconductor.org/packages/3.1/data/annotation,
6+
BioCexp=http://bioconductor.org/packages/3.1/data/experiment,
7+
BioCextra=http://bioconductor.org/packages/3.1/extra,
8+
CRAN=https://cran.rstudio.com/
9+
10+
Package: R6
11+
Source: CRAN
12+
Version: 2.1.1
13+
Hash: 20a88b2c9c84aecff2702789a4d102f5
14+
15+
Package: bitops
16+
Source: CRAN
17+
Version: 1.0-6
18+
Hash: 67d0775189fd0041d95abca618c5c07e
19+
20+
Package: caTools
21+
Source: CRAN
22+
Version: 1.17.1
23+
Hash: 97cb6f6293cd18d17df77a6383cc6763
24+
Requires: bitops
25+
26+
Package: curl
27+
Source: CRAN
28+
Version: 0.9.5
29+
Hash: 03562aad7537914f516bd67e9bba28b1
30+
31+
Package: devtools
32+
Source: CRAN
33+
Version: 1.10.0
34+
Hash: 11261bd97eda1c73da7136c4e2031e97
35+
Requires: digest, git2r, httr, jsonlite, memoise, rstudioapi, whisker,
36+
withr
37+
38+
Package: digest
39+
Source: CRAN
40+
Version: 0.6.9
41+
Hash: fd55d5a024f160fc001a5ece1e27782d
42+
43+
Package: evaluate
44+
Source: CRAN
45+
Version: 0.8
46+
Hash: aac00bd789bac10970b50e3b7e0cab04
47+
Requires: stringr
48+
49+
Package: formatR
50+
Source: CRAN
51+
Version: 1.2.1
52+
Hash: 54c730c712edd6087972ecf99bf87c55
53+
54+
Package: git2r
55+
Source: CRAN
56+
Version: 0.13.1
57+
Hash: 10b695e315f922046c7d56b9dc7150db
58+
59+
Package: highr
60+
Source: CRAN
61+
Version: 0.5.1
62+
Hash: 114ef5abcf58bebbf6ac083b9cacbbd8
63+
64+
Package: htmltools
65+
Source: CRAN
66+
Version: 0.3
67+
Hash: 7ccc01f4d22d73d0d9b0d2a7781e7ff6
68+
Requires: digest
69+
70+
Package: httr
71+
Source: CRAN
72+
Version: 1.0.0
73+
Hash: 165c156aaf69073f9a1f8a4211c626d9
74+
Requires: R6, curl, digest, jsonlite, mime, stringr
75+
76+
Package: jsonlite
77+
Source: CRAN
78+
Version: 0.9.19
79+
Hash: 4a983f753b6e88ae0f5a6ac152d8cc32
80+
81+
Package: knitr
82+
Source: CRAN
83+
Version: 1.12.3
84+
Hash: d537760d13021cf23fa2446381d9e0b2
85+
Requires: digest, evaluate, formatR, highr, markdown, stringr, yaml
86+
87+
Package: magrittr
88+
Source: CRAN
89+
Version: 1.5
90+
Hash: bdc4d48c3135e8f3b399536ddf160df4
91+
92+
Package: markdown
93+
Source: CRAN
94+
Version: 0.7.7
95+
Hash: fea2343a1119d61b0cc5c0a950d103a3
96+
Requires: mime
97+
98+
Package: memoise
99+
Source: CRAN
100+
Version: 0.2.1
101+
Hash: 812e6a1dd77a0ca4da41f3239de8e447
102+
Requires: digest
103+
104+
Package: mime
105+
Source: CRAN
106+
Version: 0.4
107+
Hash: b08c52dae92a0a11e64a4deea032ec33
108+
109+
Package: packrat
110+
Source: CRAN
111+
Version: 0.4.6-1
112+
Hash: 29eacc43b096c5b1a82c8d54a49b030b
113+
114+
Package: rmarkdown
115+
Source: github
116+
Version: 0.9.5
117+
Hash: 2703577fe6ec63d5a2f829318ebd2deb
118+
Requires: caTools, htmltools, knitr, yaml
119+
GithubRepo: rmarkdown
120+
GithubUsername: rstudio
121+
GithubRef: master
122+
GithubSha1: 1304494b8610e7d4abf8548fbb9abdd134d8fb7d
123+
124+
Package: rstudioapi
125+
Source: CRAN
126+
Version: 0.5
127+
Hash: f942db72a8f51e968b061f28058e2c57
128+
129+
Package: stringi
130+
Source: CRAN
131+
Version: 1.0-1
132+
Hash: cf342bc407bd5daec77ed1009d5244e1
133+
134+
Package: stringr
135+
Source: CRAN
136+
Version: 1.0.0
137+
Hash: 2676dd5f88890910962b733b0f9540e1
138+
Requires: magrittr, stringi
139+
140+
Package: whisker
141+
Source: CRAN
142+
Version: 0.3-2
143+
Hash: 803d662762e532705c2c066a82d066e7
144+
145+
Package: withr
146+
Source: CRAN
147+
Version: 1.0.0
148+
Hash: f48f79f631cdcb7e45250c5da49174cd
149+
150+
Package: yaml
151+
Source: CRAN
152+
Version: 2.1.13
153+
Hash: 4854ccabebc225e8a7309fb4a74980de

packrat/packrat.opts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
auto.snapshot: TRUE
2+
use.cache: FALSE
3+
print.banner.on.startup: auto
4+
vcs.ignore.lib: TRUE
5+
vcs.ignore.src: FALSE
6+
external.packages:
7+
local.repos:
8+
load.external.packages.on.startup: TRUE
9+
ignored.packages:
10+
quiet.package.installation: TRUE
11+
snapshot.recommended.packages: FALSE

packrat/src/R6/R6_2.1.1.tar.gz

142 KB
Binary file not shown.
8.53 KB
Binary file not shown.
61.9 KB
Binary file not shown.

packrat/src/curl/curl_0.9.5.tar.gz

255 KB
Binary file not shown.
178 KB
Binary file not shown.

0 commit comments

Comments
 (0)