Skip to content
This repository has been archived by the owner on Dec 30, 2023. It is now read-only.

Commit

Permalink
add packrat
Browse files Browse the repository at this point in the history
  • Loading branch information
kamclean committed Feb 16, 2020
1 parent a0eede1 commit 1e24e6e
Show file tree
Hide file tree
Showing 195 changed files with 1,462 additions and 25 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
^.*\.Rproj$
^\.Rproj\.user$
^\.Rprofile$
^packrat/
3 changes: 3 additions & 0 deletions .Rprofile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#### -- Packrat Autoloader (version 0.4.9-3) -- ####
source("packrat/init.R")
#### -- End Packrat Autoloader -- ####
2 changes: 1 addition & 1 deletion .Rproj.user/C9AE6405/pcs/find-in-files.pper
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"filePatterns" : [
],
"path" : "~",
"query" : "ASCII",
"query" : "var_id.rd",
"regex" : false
}
}
2 changes: 1 addition & 1 deletion .Rproj.user/C9AE6405/pcs/source-pane.pper
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"activeTab" : 0
"activeTab" : 2
}
12 changes: 6 additions & 6 deletions .Rproj.user/C9AE6405/pcs/windowlayoutstate.pper
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"left" : {
"panelheight" : 675,
"splitterpos" : 204,
"panelheight" : 729,
"splitterpos" : 221,
"topwindowstate" : "NORMAL",
"windowheight" : 748
"windowheight" : 803
},
"right" : {
"panelheight" : 675,
"splitterpos" : 260,
"panelheight" : 729,
"splitterpos" : 281,
"topwindowstate" : "NORMAL",
"windowheight" : 748
"windowheight" : 803
}
}
7 changes: 4 additions & 3 deletions .Rproj.user/C9AE6405/persistent-state
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
activeClientUrl="https://argonaut.is.ed.ac.uk/s/3b4b3e1b2674a2ac72186/"
build-last-errors="[]"
build-last-errors-base-dir="~/impactr/"
build-last-outputs="[{\"output\":\"==> R CMD INSTALL --no-multiarch --with-keep.source impactr\\n\\n\",\"type\":0},{\"output\":\"* installing to library ‘/home/kmclean/R/x86_64-pc-linux-gnu-library/3.4’\\n\",\"type\":1},{\"output\":\"* installing *source* package ‘impactr’ ...\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"** R\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"** preparing package for lazy loading\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"Warning: replacing previous import ‘dplyr::intersect’ by ‘lubridate::intersect’ when loading ‘impactr’\\n\",\"type\":2},{\"output\":\"Warning: replacing previous import ‘dplyr::union’ by ‘lubridate::union’ when loading ‘impactr’\\n\",\"type\":2},{\"output\":\"Warning: replacing previous import ‘dplyr::setdiff’ by ‘lubridate::setdiff’ when loading ‘impactr’\\n\",\"type\":2},{\"output\":\"Warning: replacing previous import ‘magrittr::set_names’ by ‘purrr::set_names’ when loading ‘impactr’\\n\",\"type\":2},{\"output\":\"\",\"type\":1},{\"output\":\"Warning: replacing previous import ‘magrittr::extract’ by ‘tidyr::extract’ when loading ‘impactr’\\n\",\"type\":2},{\"output\":\"\",\"type\":1},{\"output\":\"** help\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"*** installing help indices\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"*** copying figures\\n\",\"type\":1},{\"output\":\"** building package indices\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"** installing vignettes\\n\",\"type\":1},{\"output\":\"** testing if installed package can be loaded\\n\",\"type\":1},{\"output\":\"\",\"type\":1},{\"output\":\"Warning: replacing previous import ‘dplyr::intersect’ by ‘lubridate::intersect’ when loading ‘impactr’\\n\",\"type\":2},{\"output\":\"Warning: replacing previous import ‘dplyr::union’ by ‘lubridate::union’ when loading ‘impactr’\\n\",\"type\":2},{\"output\":\"Warning: replacing previous import ‘dplyr::setdiff’ by ‘lubridate::setdiff’ when loading ‘impactr’\\n\",\"type\":2},{\"output\":\"Warning: replacing previous import ‘magrittr::set_names’ by ‘purrr::set_names’ when loading ‘impactr’\\n\",\"type\":2},{\"output\":\"Warning: replacing previous import ‘magrittr::extract’ by ‘tidyr::extract’ when loading ‘impactr’\\n\",\"type\":2},{\"output\":\"\",\"type\":1},{\"output\":\"* DONE (impactr)\\n\",\"type\":1},{\"output\":\"\",\"type\":1}]"
build-last-errors-base-dir=""
build-last-outputs="[]"
compile_pdf_state="{\"errors\":[],\"output\":\"\",\"running\":false,\"tab_visible\":false,\"target_file\":\"\"}"
files.monitored-path=""
find-in-files-state="{\"handle\":\"\",\"input\":\"\",\"path\":\"\",\"regex\":true,\"results\":{\"file\":[],\"line\":[],\"lineValue\":[],\"matchOff\":[],\"matchOn\":[]},\"running\":false}"
imageDirtyState="0"
portToken="c597faf203a3"
packratEnabled="1"
portToken="98c62d446885"
saveActionState="0"
4 changes: 2 additions & 2 deletions .Rproj.user/C9AE6405/sources/prop/E8A726A2
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"cursorPosition" : "28,12",
"scrollLine" : "10"
"cursorPosition" : "11,0",
"scrollLine" : "5"
}
2 changes: 1 addition & 1 deletion .Rproj.user/C9AE6405/sources/s-2ac72186/lock_file
Original file line number Diff line number Diff line change
@@ -1 +1 @@
56016
42801
6 changes: 1 addition & 5 deletions .Rproj.user/shared/notebooks/paths
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
/home/kmclean/collaborator/vignettes/vignette_summary.Rmd="EF3F5101"
/home/kmclean/collaborator/vignettes/vignette_user_2_assign.Rmd="8E6C362"
/home/kmclean/impactr/.Rbuildignore="D18365D3"
/home/kmclean/impactr/.Rprofile="BD03410E"
/home/kmclean/impactr/.gitignore="D609B0B1"
/home/kmclean/impactr/DESCRIPTION="22AFEF46"
/home/kmclean/impactr/NAMESPACE="CFE2FF95"
Expand All @@ -39,11 +40,6 @@
/home/kmclean/impactr/R/score_alm.R="C0E2D5F6"
/home/kmclean/impactr/README.md="49EA9396"
/home/kmclean/impactr/man/comb_name_size.Rd="C7D70E07"
/home/kmclean/impactr/vignettes/vignette_1_extract.Rmd="AB149A52"
/home/kmclean/impactr/vignettes/vignette_2_cite.Rmd="3B9971DE"
/home/kmclean/impactr/vignettes/vignette_3_traditional.Rmd="1578E6D7"
/home/kmclean/impactr/vignettes/vignette_4_author.Rmd="2AB4D9BA"
/home/kmclean/impactr/vignettes/vignette_5_altmetric.Rmd="9029258"
/home/kmclean/starsurg_impact/app/impact/app.R="53B9CA75"
/home/kmclean/starsurg_impact/app/impact/starsurg_altmetric.Rmd="ADC030BC"
/home/kmclean/starsurg_impact/app/impact/starsurg_citation.Rmd="743B1039"
Expand Down
2 changes: 1 addition & 1 deletion .Rproj.user/shared/users/2ac72186.lock
Original file line number Diff line number Diff line change
@@ -1 +1 @@
56016
42801
2 changes: 1 addition & 1 deletion .Rproj.user/shared/users/2ac72186.user
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"client_id":"5d8f7237-833a-4d7c-ab78-791223abf371","color":"#45e6b0","current_edit_id":"","currently_editing":"","last_seen":1581873308,"session_id":"2ac72186","time_since_last_seen":0,"username":"kmclean"}
{"client_id":"cd962f00-5f96-4de4-899c-c1d83ddfcaa3","color":"#45e6b0","current_edit_id":"","currently_editing":"","last_seen":1581876691,"session_id":"2ac72186","time_since_last_seen":0,"username":"kmclean"}
8 changes: 4 additions & 4 deletions .Ruserdata/kmclean/.Rhistory
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
x$ISSN <- x$ISSN[1]
x$page <- paste(unique(x$page), collapse="-")
df_na <- NULL
if(length(extract_var[which(extract_var %ni% names(x))])>0){
df_na <- rbind.data.frame(rep(NA, length(extract_var[which(extract_var %ni% names(x))])))
colnames(df_na) <- extract_var[which(extract_var %ni% names(x))]}
y <- tibble::as_tibble(x)
Expand Down Expand Up @@ -510,3 +506,7 @@ theme_bw(base_size = 13)
ggsave(plot_cite_time, filename = "~/impactr/vignettes/plot/plot_cite_time.png",
height = 5.76*0.75, width = 9.60*0.75)
library(impactr)
library(impactr)
devtools::document()
devtools::document()
library(impactr)
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.Rhistory
.RData
.Ruserdata
packrat/lib*/
19 changes: 19 additions & 0 deletions man/extract_impact_factor.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

226 changes: 226 additions & 0 deletions packrat/init.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
local({

## Helper function to get the path to the library directory for a
## given packrat project.
getPackratLibDir <- function(projDir = NULL) {
path <- file.path("packrat", "lib", R.version$platform, getRversion())

if (!is.null(projDir)) {

## Strip trailing slashes if necessary
projDir <- sub("/+$", "", projDir)

## Only prepend path if different from current working dir
if (!identical(normalizePath(projDir), normalizePath(getwd())))
path <- file.path(projDir, path)
}

path
}

## Ensure that we set the packrat library directory relative to the
## project directory. Normally, this should be the working directory,
## but we also use '.rs.getProjectDirectory()' if necessary (e.g. we're
## rebuilding a project while within a separate directory)
libDir <- if (exists(".rs.getProjectDirectory"))
getPackratLibDir(.rs.getProjectDirectory())
else
getPackratLibDir()

## Unload packrat in case it's loaded -- this ensures packrat _must_ be
## loaded from the private library. Note that `requireNamespace` will
## succeed if the package is already loaded, regardless of lib.loc!
if ("packrat" %in% loadedNamespaces())
try(unloadNamespace("packrat"), silent = TRUE)

if (suppressWarnings(requireNamespace("packrat", quietly = TRUE, lib.loc = libDir))) {

# Check 'print.banner.on.startup' -- when NA and RStudio, don't print
print.banner <- packrat::get_opts("print.banner.on.startup")
if (print.banner == "auto" && is.na(Sys.getenv("RSTUDIO", unset = NA))) {
print.banner <- TRUE
} else {
print.banner <- FALSE
}
return(packrat::on(print.banner = print.banner))
}

## Escape hatch to allow RStudio to handle bootstrapping. This
## enables RStudio to provide print output when automagically
## restoring a project from a bundle on load.
if (!is.na(Sys.getenv("RSTUDIO", unset = NA)) &&
is.na(Sys.getenv("RSTUDIO_PACKRAT_BOOTSTRAP", unset = NA))) {
Sys.setenv("RSTUDIO_PACKRAT_BOOTSTRAP" = "1")
setHook("rstudio.sessionInit", function(...) {
# Ensure that, on sourcing 'packrat/init.R', we are
# within the project root directory
if (exists(".rs.getProjectDirectory")) {
owd <- getwd()
setwd(.rs.getProjectDirectory())
on.exit(setwd(owd), add = TRUE)
}
source("packrat/init.R")
})
return(invisible(NULL))
}

## Bootstrapping -- only performed in interactive contexts,
## or when explicitly asked for on the command line
if (interactive() || "--bootstrap-packrat" %in% commandArgs(TRUE)) {

needsRestore <- "--bootstrap-packrat" %in% commandArgs(TRUE)

message("Packrat is not installed in the local library -- ",
"attempting to bootstrap an installation...")

## We need utils for the following to succeed -- there are calls to functions
## in 'restore' that are contained within utils. utils gets loaded at the
## end of start-up anyhow, so this should be fine
library("utils", character.only = TRUE)

## Install packrat into local project library
packratSrcPath <- list.files(full.names = TRUE,
file.path("packrat", "src", "packrat")
)

## No packrat tarballs available locally -- try some other means of installation
if (!length(packratSrcPath)) {

message("> No source tarball of packrat available locally")

## There are no packrat sources available -- try using a version of
## packrat installed in the user library to bootstrap
if (requireNamespace("packrat", quietly = TRUE) && packageVersion("packrat") >= "0.2.0.99") {
message("> Using user-library packrat (",
packageVersion("packrat"),
") to bootstrap this project")
}

## Couldn't find a user-local packrat -- try finding and using devtools
## to install
else if (requireNamespace("devtools", quietly = TRUE)) {
message("> Attempting to use devtools::install_github to install ",
"a temporary version of packrat")
library(stats) ## for setNames
devtools::install_github("rstudio/packrat")
}

## Try downloading packrat from CRAN if available
else if ("packrat" %in% rownames(available.packages())) {
message("> Installing packrat from CRAN")
install.packages("packrat")
}

## Fail -- couldn't find an appropriate means of installing packrat
else {
stop("Could not automatically bootstrap packrat -- try running ",
"\"'install.packages('devtools'); devtools::install_github('rstudio/packrat')\"",
"and restarting R to bootstrap packrat.")
}

# Restore the project, unload the temporary packrat, and load the private packrat
if (needsRestore)
packrat::restore(prompt = FALSE, restart = TRUE)

## This code path only reached if we didn't restart earlier
unloadNamespace("packrat")
requireNamespace("packrat", lib.loc = libDir, quietly = TRUE)
return(packrat::on())

}

## Multiple packrat tarballs available locally -- try to choose one
## TODO: read lock file and infer most appropriate from there; low priority because
## after bootstrapping packrat a restore should do the right thing
if (length(packratSrcPath) > 1) {
warning("Multiple versions of packrat available in the source directory;",
"using packrat source:\n- ", shQuote(packratSrcPath))
packratSrcPath <- packratSrcPath[[1]]
}


lib <- file.path("packrat", "lib", R.version$platform, getRversion())
if (!file.exists(lib)) {
dir.create(lib, recursive = TRUE)
}

message("> Installing packrat into project private library:")
message("- ", shQuote(lib))

surround <- function(x, with) {
if (!length(x)) return(character())
paste0(with, x, with)
}


## Invoke install.packages() in clean R session
peq <- function(x, y) paste(x, y, sep = " = ")
installArgs <- c(
peq("pkgs", surround(packratSrcPath, with = "'")),
peq("lib", surround(lib, with = "'")),
peq("repos", "NULL"),
peq("type", surround("source", with = "'"))
)

fmt <- "utils::install.packages(%s)"
installCmd <- sprintf(fmt, paste(installArgs, collapse = ", "))

## Write script to file (avoid issues with command line quoting
## on R 3.4.3)
installFile <- tempfile("packrat-bootstrap", fileext = ".R")
writeLines(installCmd, con = installFile)
on.exit(unlink(installFile), add = TRUE)

fullCmd <- paste(
surround(file.path(R.home("bin"), "R"), with = "\""),
"--vanilla",
"--slave",
"-f",
surround(installFile, with = "\"")
)
system(fullCmd)

## Tag the installed packrat so we know it's managed by packrat
## TODO: should this be taking information from the lockfile? this is a bit awkward
## because we're taking an un-annotated packrat source tarball and simply assuming it's now
## an 'installed from source' version

## -- InstallAgent -- ##
installAgent <- "InstallAgent: packrat 0.4.9-3"

## -- InstallSource -- ##
installSource <- "InstallSource: source"

packratDescPath <- file.path(lib, "packrat", "DESCRIPTION")
DESCRIPTION <- readLines(packratDescPath)
DESCRIPTION <- c(DESCRIPTION, installAgent, installSource)
cat(DESCRIPTION, file = packratDescPath, sep = "\n")

# Otherwise, continue on as normal
message("> Attaching packrat")
library("packrat", character.only = TRUE, lib.loc = lib)

message("> Restoring library")
if (needsRestore)
packrat::restore(prompt = FALSE, restart = FALSE)

# If the environment allows us to restart, do so with a call to restore
restart <- getOption("restart")
if (!is.null(restart)) {
message("> Packrat bootstrap successfully completed. ",
"Restarting R and entering packrat mode...")
return(restart())
}

# Callers (source-erers) can define this hidden variable to make sure we don't enter packrat mode
# Primarily useful for testing
if (!exists(".__DONT_ENTER_PACKRAT_MODE__.") && interactive()) {
message("> Packrat bootstrap successfully completed. Entering packrat mode...")
packrat::on()
}

Sys.unsetenv("RSTUDIO_PACKRAT_BOOTSTRAP")

}

})
Loading

0 comments on commit 1e24e6e

Please sign in to comment.