Building of a snapshot completed and included

This commit is contained in:
2022-07-04 16:38:47 +01:00
parent e460aefcb4
commit b51273e82d
8 changed files with 367 additions and 16 deletions

42
R/snapshot_create.R Normal file
View File

@@ -0,0 +1,42 @@
# Requires snapshot_latest.R
# Requires utils.R
# Requires compile_imports.R
#' Create a snapshot of the project packages. Does not save the snapshot (see snapshot_save)
#'
#' @param installOpts list Installer options for use when installing CRAN
#' packages
#'
#' @return A list containing the current state of the project packages
#' @export
snapshot_create <- function(installOpts = list(Ncpus = parallel::detectCores())) {
lastSnapshot <- snapshot_latest()
customSources <- empty_sources()
if (!is.null(lastSnapshot) && "custom" %in% names(lastSnapshot$packages)) {
customSources <- rbind(customSources, lastSnapshot$packages$custom)
}
packages <- compile_imports(customSources, installOpts)
names(packages) <- c("core", "direct", "indirect", "custom")
if (nrow(packages$core) == 0) {
packages$core <- NULL
}
if (nrow(packages$direct) == 0) {
packages$direct <- NULL
}
if (nrow(packages$indirect) == 0) {
packages$indirect <- NULL
}
if (nrow(packages$custom) == 0) {
packages$custom <- NULL
}
description <- trimws(readline("Please provide a description for the snapshot (optional): "))
if (nchar(description) == 0) {
description <- NULL
}
return(list(
timestamp = Sys.time(),
description = description,
R_version = paste(R.version$major, R.version$minor, sep = "."),
packages = packages
))
}