Slightly less clunky handling of stringsAsFactors

This commit is contained in:
2023-11-29 17:02:38 +00:00
parent 092bcdd866
commit 2ddb8a0819
7 changed files with 34 additions and 16 deletions

View File

@@ -1,7 +1,7 @@
Package: Rpacman
Type: Package
Title: Very simple package manager for R
Version: 1.0.9
Version: 1.0.10
Date: 2022-05-31
Authors@R: person("Craig", "Williams", email = "craig@avsdev.uk", role = c("aut", "cre"))
URL: https://avsdev.uk/R/Rpacman

View File

@@ -2,10 +2,8 @@
#' Add a package to the project.
#'
#' @param packageName boolean Only refer to the pacman library, do not use
#' any user library paths
#' @param installOpts boolean Only refer to the pacman library, do not use
#' any user library paths
#' @param packageName character Name of the package to add
#' @param installOpts list Options for installing the package
#'
add_package <- function(packageName = NULL, installOpts = list(Ncpus = parallel::detectCores())) {
if (is.null(packageName)) {

View File

@@ -7,6 +7,9 @@
#' @import parallel
.solve_missing_imports <- function(missingImports, installOpts = list(Ncpus = parallel::detectCores())) {
old_opt <- options(stringsAsFactors = FALSE)
on.exit(options(old_opt))
importsFormat <- data.frame(list(
package_name = unlist(lapply(missingImports$package, format_str, width = 35)),
req_ver = unlist(lapply(missingImports$req_version, format_str, width = 12)),
@@ -66,17 +69,20 @@
)))
}
do.call(rbind, c(fixedImports, stringsAsFactors = FALSE))
do.call(rbind, fixedImports)
}
.install_order <- function(dependsTree) {
old_opt <- options(stringsAsFactors = FALSE)
on.exit(options(old_opt))
dependsPackages <- lapply(unique(dependsTree$package), function(p) {
package <- dependsTree[dependsTree$package == p,]
package <- package[package$generation == max(package$generation),]
package <- package[1,c("package", "version", "generation")]
return(package)
})
dependsPackages <- do.call(rbind, c(dependsPackages, stringsAsFactors = FALSE))
dependsPackages <- do.call(rbind, dependsPackages)
dependsOrder <- sort(dependsPackages$generation, index.return = T, decreasing = T)$ix
dependsOrder <- dependsPackages[dependsOrder,]
@@ -101,6 +107,9 @@
#' import sources.
#' @export
compile_imports <- function(custom_sources = empty_sources(), installOpts = list(Ncpus = parallel::detectCores())) {
old_opt <- options(stringsAsFactors = FALSE)
on.exit(options(old_opt))
CORE_PACKAGES <- c(
"base", "compiler", "datasets", "graphics", "grDevices", "grid", "methods",
"parallel", "splines", "stats", "stats4", "tcltk", "tools", "utils"
@@ -172,7 +181,7 @@ compile_imports <- function(custom_sources = empty_sources(), installOpts = list
# Cancelled
return(invisible(NULL))
}
customImports <- rbind(customImports, extraImports, stringsAsFactors = FALSE)
customImports <- rbind(customImports, extraImports)
}
coreDeps <- dependsSources[dependsSources$in_core,]

View File

@@ -1,18 +1,21 @@
# Requires utils.R
.process_dist_archive <- function(dist_fn, fn) {
old_opt <- options(stringsAsFactors = FALSE)
on.exit(options(old_opt))
dist_con <- gzfile(dist_fn, "rb")
on.exit(close(dist_con), add = TRUE)
archive <- readRDS(dist_con)
archive <- lapply(archive, function(pkg) {
packageVersions <- gsub("^([^/]+)/[^_]+_(.+).tar.gz", "\\1%%\\2", rownames(pkg))
packageVersions <- strsplit(packageVersions, "%%")
packageVersions <- do.call(rbind, c(packageVersions, stringsAsFactors = FALSE))
packageVersions <- do.call(rbind, packageVersions)
pkg[,c("package","version")] <- packageVersions
sortOrder <- sort(pkg$version, index.return = TRUE)$ix
pkg[sortOrder,c("package", "version")]
})
archive <- do.call(rbind, c(archive, stringsAsFactors = FALSE))
archive <- do.call(rbind, archive)
rownames(archive) <- 1:nrow(archive)
write_con <- gzfile(fn, "wb")
saveRDS(archive, write_con)

View File

@@ -1,5 +1,8 @@
.list_depends <- function(packages, gen) {
old_opt <- options(stringsAsFactors = FALSE)
on.exit(options(old_opt))
allPackages <- utils::installed.packages()
allPackages <- as.data.frame(allPackages, stringsAsFactors = FALSE)
packages <- allPackages[allPackages$Package %in% packages,]
@@ -39,7 +42,7 @@
dependsNext <- sort(unique(dependsNext))
if (length(dependsNext) > 0) {
packagesNext <- .list_depends(dependsNext, gen + 1)
packages <- rbind(packages, packagesNext, stringsAsFactors = FALSE)
packages <- rbind(packages, packagesNext)
}
return(packages)

View File

@@ -61,6 +61,9 @@
#' @import parallel
#' @export
restore <- function(totalIsolation = FALSE, installOpts = list(Ncpus = parallel::detectCores()), parallel = FALSE) {
old_opt <- options(stringsAsFactors = FALSE)
on.exit(options(old_opt))
activate(totalIsolation)
get_cran_repo()
@@ -80,9 +83,8 @@ restore <- function(totalIsolation = FALSE, installOpts = list(Ncpus = parallel:
simplePackages <- as.data.frame(
apply(
rbind(
do.call(rbind, c(requiredPackages$direct, stringsAsFactors = FALSE)),
do.call(rbind, c(requiredPackages$indirect, stringsAsFactors = FALSE)),
stringsAsFactors = FALSE
do.call(rbind, requiredPackages$direct),
do.call(rbind, requiredPackages$indirect)
),
2,
unlist
@@ -90,7 +92,7 @@ restore <- function(totalIsolation = FALSE, installOpts = list(Ncpus = parallel:
stringsAsFactors = FALSE
)
customPackages <- as.data.frame(
do.call(rbind, c(requiredPackages$custom, stringsAsFactors = FALSE)),
do.call(rbind, requiredPackages$custom),
stringsAsFactors = FALSE
)

View File

@@ -11,10 +11,13 @@
#' @import parallel
#' @export
snapshot_create <- function(installOpts = list(Ncpus = parallel::detectCores())) {
old_opt <- options(stringsAsFactors = FALSE)
on.exit(options(old_opt))
lastSnapshot <- snapshot_latest()
customSources <- empty_sources()
if (!is.null(lastSnapshot) && "custom" %in% names(lastSnapshot$packages)) {
customSources <- rbind(customSources, lastSnapshot$packages$custom, stringsAsFactors = FALSE)
customSources <- rbind(customSources, lastSnapshot$packages$custom)
}
packages <- compile_imports(customSources, installOpts)
names(packages) <- c("core", "direct", "indirect", "custom", "install_order")