1
0
mirror of https://github.com/msberends/AMR.git synced 2024-12-26 07:26:13 +01:00

bye bye packrat

This commit is contained in:
dr. M.S. (Matthijs) Berends 2018-12-30 12:00:53 +01:00
parent df6b334c6f
commit 469b145d8c
6 changed files with 42 additions and 691 deletions

View File

@ -16,58 +16,58 @@
# GNU General Public License version 2.0 for more details. # # GNU General Public License version 2.0 for more details. #
# ==================================================================== # # ==================================================================== #
# https://r-posts.com/gitlab-ci-for-r-package-development/ # from https://stackoverflow.com/questions/51866926
# and https://github.com/jangorecki/r.gitlab.ci
# and https://docs.gitlab.com/ce/ci/yaml/README.html
# how the Docker+R images work: https://hub.docker.com/r/rocker/r-ver/
stages:
- build
- deploy
image: debian:buster-slim
image: rocker/r-base
before_script: before_script:
- apt-get update - apt-get update
# install dependencies for package # install dependencies for package
- apt-get -y install libxml2-dev libssl-dev libcurl4-openssl-dev zlib1g-dev - apt-get -y install libxml2-dev libssl-dev libcurl4-openssl-dev zlib1g-dev pandoc r-base
- Rscript -e 'install.packages(c("devtools", "rlang"), repos = "https://cran.rstudio.com")'
- Rscript -e 'devtools::install_dev_deps(repos = "https://cran.rstudio.com")'
stages: R 3:
- setup stage: build
- test allow_failure: true
- deploy
cache:
# Ommit key to use the same cache across all pipelines and branches
key: "$CI_COMMIT_REF_SLUG"
paths:
- packrat/lib/
setup:
stage: setup
script: script:
- R -e 'source("ci.R"); ci_setup()' # remove vignettes folder and get VignetteBuilder field out of DESCRIPTION file
- rm -rf vignettes
check: - Rscript -e 'd <- read.dcf("DESCRIPTION"); d[, colnames(d) == "VignetteBuilder"] <- NA; write.dcf(d, "DESCRIPTION")'
stage: test # build package
dependencies: - R CMD build . --no-build-vignettes --no-manual
- setup - PKG_FILE_NAME=$(ls -1t *.tar.gz | head -n 1)
when: on_success - R CMD check "${PKG_FILE_NAME}" --no-build-vignettes --no-manual --as-cran
script: # code coverage
- R -e 'source("ci.R"); ci_check()' - apt-get install --yes git
- Rscript -e 'cc <- covr::package_coverage(); covr::codecov(coverage = cc, token = "50ffa0aa-fee0-4f8b-a11d-8c7edc6d32ca"); cat("Code coverage:", covr::percent_coverage(cc))'
coverage:
stage: test
dependencies:
- setup
when: on_success
only:
- master
script:
- R -e 'source("ci.R"); ci_coverage()'
coverage: '/Code coverage: \d+\.\d+/' coverage: '/Code coverage: \d+\.\d+/'
artifacts:
paths:
- '*.Rcheck/*.log'
- '*.Rcheck/*.out'
# - '*.Rcheck/*.fail'
- '*.Rcheck/*.Rout'
name: 'Rcheck log'
expire_in: '1 month'
pages: pages:
stage: deploy stage: deploy
dependencies:
- setup
when: always
only:
- master
script: script:
- R -e 'source("ci.R"); ci_pages()' - Rscript -e "install.packages('pkgdown', repos = 'https://cran.rstudio.com')"
- Rscript -e "devtools::install(build = TRUE, upgrade = FALSE)"
# - R -e "pkgdown::build_favicon()"
- R -e "pkgdown::build_site(examples = FALSE, override = list(destination = 'public'))"
when: always
artifacts: artifacts:
paths: paths:
- public - public
only:
- master

View File

@ -1,6 +1,6 @@
Package: AMR Package: AMR
Version: 0.5.0.9008 Version: 0.5.0.9008
Date: 2018-12-29 Date: 2018-12-30
Title: Antimicrobial Resistance Analysis Title: Antimicrobial Resistance Analysis
Authors@R: c( Authors@R: c(
person( person(

50
ci.R
View File

@ -1,50 +0,0 @@
# ==================================================================== #
# TITLE #
# Antimicrobial Resistance (AMR) Analysis #
# #
# AUTHORS #
# Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
# #
# LICENCE #
# This package is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License version 2.0, #
# as published by the Free Software Foundation. #
# #
# This R package is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License version 2.0 for more details. #
# ==================================================================== #
install_if_needed <- function(package_to_install) {
package_path <- find.package(package_to_install, quiet = TRUE)
if(length(package_path) == 0){
# Only install if not present
install.packages(package_to_install, repos = "https://cran.rstudio.com/")
}
}
ci_setup <- function() {
install_if_needed("packrat")
packrat::restore()
}
ci_check <- function() {
install_if_needed("devtools")
install_if_needed("roxygen2")
devtools::check()
}
ci_coverage <- function() {
install_if_needed("covr")
devtools::install()
cc <- covr::package_coverage(type = c("tests", "examples"))
covr::codecov(coverage = cc, token = "50ffa0aa-fee0-4f8b-a11d-8c7edc6d32ca")
cat("Code coverage:", covr::percent_coverage(cc))
}
ci_pages <- function() {
install_if_needed("pkgdown")
pkgdown::build_site(examples = FALSE, override = list(destination = "public"))
}

View File

@ -1,226 +0,0 @@
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.5.0"
## -- 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")
}
})

View File

@ -1,354 +0,0 @@
PackratFormat: 1.4
PackratVersion: 0.5.0
RVersion: 3.5.2
Repos: CRAN=https://cloud.r-project.org
Package: BH
Source: CRAN
Version: 1.66.0-1
Hash: 4cc8883584b955ed01f38f68bc03af6d
Package: R6
Source: CRAN
Version: 2.3.0
Hash: 8eccabbf292b5aba632985cde6406fc3
Package: RColorBrewer
Source: CRAN
Version: 1.1-2
Hash: c0d56cd15034f395874c870141870c25
Package: Rcpp
Source: CRAN
Version: 1.0.0
Hash: c7273c0f0bc9f5e41f4c52a8cf571f0f
Package: assertthat
Source: CRAN
Version: 0.2.0
Hash: e8805df54c65ac96d50235c44a82615c
Package: backports
Source: CRAN
Version: 1.1.2
Hash: 5ae7b3466e529e4400951ca18c137e40
Package: base64enc
Source: CRAN
Version: 0.1-3
Hash: c590d29e555926af053055e23ee79efb
Package: cli
Source: CRAN
Version: 1.0.1
Hash: a742a3229dbf7085c3a737af10e5065b
Requires: assertthat, crayon
Package: colorspace
Source: CRAN
Version: 1.3-2
Hash: 0bf8618b585fa98eb23414cd3ab95118
Package: covr
Source: CRAN
Version: 3.2.1
Hash: b1dab7f44fae6114c222cee94d6acd63
Requires: crayon, digest, httr, jsonlite, rex, withr
Package: crayon
Source: CRAN
Version: 1.3.4
Hash: ff2840dd9b0d563fc80377a5a45510cd
Package: curl
Source: CRAN
Version: 3.2
Hash: 82a7cf5bb702ef52329b6d23ea6132a7
Package: data.table
Source: CRAN
Version: 1.11.8
Hash: 67c877937c790a0cadb71284febb6b34
Package: digest
Source: CRAN
Version: 0.6.18
Hash: 65f62365ec69ddd17230d2ffe891a6ab
Package: dplyr
Source: github
Version: 0.7.99.9000
Hash: 2ad5ae0fa33abb1278da08b574c03c74
Requires: BH, R6, Rcpp, assertthat, glue, magrittr, pkgconfig, plogr,
rlang, tibble, tidyselect
GithubRepo: dplyr
GithubUsername: tidyverse
GithubRef: master
GithubSha1: 45894214a543e63c01f66e8b1fb4cc77a5978f40
RemoteHost: api.github.com
RemoteRepo: dplyr
RemoteUsername: tidyverse
RemoteRef: master
RemoteSha: 45894214a543e63c01f66e8b1fb4cc77a5978f40
Package: evaluate
Source: CRAN
Version: 0.12
Hash: c32505adba4f6eca5aa20dd32300b019
Package: fansi
Source: CRAN
Version: 0.4.0
Hash: f147621f72b561485bfffcae78c4f5d5
Package: ggplot2
Source: CRAN
Version: 3.1.0
Hash: ef541b05dda10b209d509b5bbaf46ea3
Requires: digest, gtable, lazyeval, plyr, reshape2, rlang, scales,
tibble, viridisLite, withr
Package: glue
Source: CRAN
Version: 1.3.0
Hash: 1fbde6dec830370be696eee8ef31c9e4
Package: gtable
Source: CRAN
Version: 0.2.0
Hash: cd78381a9d3fea966ac39bd0daaf5554
Package: highr
Source: CRAN
Version: 0.7
Hash: 20757f5c393ed0ecf96c9e8e6d8d514c
Package: hms
Source: CRAN
Version: 0.4.2
Hash: b4096a4f6a6736138e9a825c2baaacf0
Requires: pkgconfig, rlang
Package: htmltools
Source: CRAN
Version: 0.3.6
Hash: 9707abea0a9b7406e98fb1242e97e1f6
Requires: Rcpp, digest
Package: httr
Source: CRAN
Version: 1.3.1
Hash: 2d32e01e53d532c812052e27a1021441
Requires: R6, curl, jsonlite, mime, openssl
Package: jsonlite
Source: CRAN
Version: 1.5
Hash: 9c51936d8dd00b2f1d4fe9d10499694c
Package: knitr
Source: CRAN
Version: 1.20
Hash: 9c6b215d1d02b97586c8232e94533e6a
Requires: evaluate, highr, markdown, stringr, yaml
Package: labeling
Source: CRAN
Version: 0.3
Hash: ecf589b42cd284b03a4beb9665482d3e
Package: lazyeval
Source: CRAN
Version: 0.2.1
Hash: 88926ad9c43581fd0822a37c8ed09f05
Package: magrittr
Source: CRAN
Version: 1.5
Hash: bdc4d48c3135e8f3b399536ddf160df4
Package: markdown
Source: CRAN
Version: 0.8
Hash: 045d7c594d503b41f1c28946d076c8aa
Requires: mime
Package: mime
Source: CRAN
Version: 0.6
Hash: 2ed8f98b8284ad733f3907fc6e2f1334
Package: munsell
Source: CRAN
Version: 0.5.0
Hash: 38d0efee9bb99bef143bde41c4ce715c
Requires: colorspace
Package: openssl
Source: CRAN
Version: 1.0.2
Hash: 12a42cbd5aecdb887782247856ccbafd
Package: packrat
Source: CRAN
Version: 0.5.0
Hash: 498643e765d1442ba7b1160a1df3abf9
Package: pillar
Source: CRAN
Version: 1.3.1
Hash: 9ed4c2a5d3047bfba3e852ad5e806d91
Requires: cli, crayon, fansi, rlang, utf8
Package: pkgconfig
Source: CRAN
Version: 2.0.2
Hash: b0fd6ed908e150b77e5f00c6478bd58c
Package: plogr
Source: CRAN
Version: 0.2.0
Hash: 81a8008a5e7858552503935f1abe48aa
Package: plyr
Source: CRAN
Version: 1.8.4
Hash: ec185c885aab7ec91693d78c20cb5d1a
Requires: Rcpp
Package: praise
Source: CRAN
Version: 1.0.0
Hash: 77da8f1df873a4b91e5c4a68fe2fb1b6
Package: purrr
Source: CRAN
Version: 0.2.5
Hash: 8b0c16db10c7e20b70cd37779a673a8b
Requires: magrittr, rlang, tibble
Package: reshape2
Source: CRAN
Version: 1.4.3
Hash: c950c8ac85b81209635acb3ce21b4cce
Requires: Rcpp, plyr, stringr
Package: rex
Source: CRAN
Version: 1.1.2
Hash: 57541aaae58f1a284a398f5c62c95097
Requires: lazyeval, magrittr
Package: rlang
Source: CRAN
Version: 0.3.0.1
Hash: 35fb7a51d5d756c56f793ed9c381fb84
Package: rmarkdown
Source: CRAN
Version: 1.10
Hash: 02f1aac33000c63986c6b5585e36e7ae
Requires: base64enc, evaluate, htmltools, jsonlite, knitr, mime,
rprojroot, stringr, tinytex, yaml
Package: rprojroot
Source: CRAN
Version: 1.3-2
Hash: a25c3f70c166fb3fbabc410eb32b6366
Requires: backports
Package: rstudioapi
Source: CRAN
Version: 0.8
Hash: 9ba7fe76dcaf96966c449527ca04bb78
Package: rvest
Source: CRAN
Version: 0.3.2
Hash: c69f7526520bad66fd2111ebe8b1364b
Requires: httr, magrittr, selectr, xml2
Package: scales
Source: CRAN
Version: 1.0.0
Hash: 7d9b717abcec656ae7c5c982d72b75e5
Requires: R6, RColorBrewer, Rcpp, labeling, munsell, viridisLite
Package: selectr
Source: CRAN
Version: 0.4-1
Hash: b12802c11e35dec9d16a74d30ed0f3ed
Requires: R6, stringr
Package: stringi
Source: CRAN
Version: 1.2.4
Hash: 03ab60ef7fa4627b38ad67c95ce6b04c
Package: stringr
Source: CRAN
Version: 1.3.1
Hash: 9f417a1d899ed1f080942ab36998e8b5
Requires: glue, magrittr, stringi
Package: testthat
Source: CRAN
Version: 2.0.1
Hash: 777eb6e94f5a62bf6320fecf0175bbbb
Requires: R6, cli, crayon, digest, magrittr, praise, rlang, withr
Package: tibble
Source: CRAN
Version: 1.4.2
Hash: 83895360ce4f8d2ce92eee00526b5b0b
Requires: cli, crayon, pillar, rlang
Package: tidyr
Source: CRAN
Version: 0.8.2
Hash: 9ff92b9b3c11dfcd94d179b75b85c668
Requires: Rcpp, dplyr, glue, magrittr, purrr, rlang, stringi, tibble,
tidyselect
Package: tidyselect
Source: CRAN
Version: 0.2.5
Hash: fad1cf10c5c4996fca6ca68e0716d2e6
Requires: Rcpp, glue, purrr, rlang
Package: tinytex
Source: CRAN
Version: 0.9
Hash: a4ffe98c58eace5a95644d8fd6ca5a50
Requires: xfun
Package: utf8
Source: CRAN
Version: 1.1.4
Hash: f3f97ce59092abc8ed3fd098a59e236c
Package: viridisLite
Source: CRAN
Version: 0.3.0
Hash: 78bb072c4f9e729a283d4c40ec93f9c6
Package: withr
Source: CRAN
Version: 2.1.2
Hash: d534108bcd5f34ec73e9eb523751ba20
Package: xfun
Source: CRAN
Version: 0.4
Hash: 76004125b45195c0330ec71904849995
Package: xml2
Source: CRAN
Version: 1.2.0
Hash: 3f00e5347a6d7ccad2237fe1bc1df6d0
Requires: Rcpp
Package: yaml
Source: CRAN
Version: 2.2.0
Hash: a5ad5616d83d89f8d84cbf3cf4034e13

View File

@ -1,19 +0,0 @@
auto.snapshot: TRUE
use.cache: FALSE
print.banner.on.startup: auto
vcs.ignore.lib: TRUE
vcs.ignore.src: TRUE
external.packages:
local.repos:
load.external.packages.on.startup: TRUE
ignored.packages:
ignored.directories:
data
inst
quiet.package.installation: TRUE
snapshot.recommended.packages: FALSE
snapshot.fields:
Imports
Depends
LinkingTo
symlink.system.packages: TRUE