From 00136e2de8fc259d86e6ac987afd53cb9d3c8cd4 Mon Sep 17 00:00:00 2001 From: hsonne Date: Sun, 30 May 2021 11:37:54 +0200 Subject: [PATCH 01/90] Consider that a CRAN package was removed --- R/archivedCranVersions.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/archivedCranVersions.R b/R/archivedCranVersions.R index d277a5f..9ec7764 100644 --- a/R/archivedCranVersions.R +++ b/R/archivedCranVersions.R @@ -35,7 +35,9 @@ currentCranVersion <- function(name) { src <- readLinesFromUrl(getUrl("cran_package", package = name)) - if (is.null(src)) { + was_removed_pattern <- "was removed from the CRAN repository" + + if (is.null(src) || any(grepl(was_removed_pattern, src))) { return(kwb.utils::noFactorDataFrame( package = character(0L), version = character(0L), From 404fdcc6f3dcb223aa68c3580019a8dbae6dec2c Mon Sep 17 00:00:00 2001 From: hsonne Date: Sun, 30 May 2021 11:38:17 +0200 Subject: [PATCH 02/90] Add argument "dbg" to cranVersions() --- R/archivedCranVersions.R | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/R/archivedCranVersions.R b/R/archivedCranVersions.R index 9ec7764..ad74576 100644 --- a/R/archivedCranVersions.R +++ b/R/archivedCranVersions.R @@ -5,12 +5,18 @@ isOnCran <- function(name) } # cranVersions ----------------------------------------------------------------- -cranVersions <- function(name) +cranVersions <- function(name, dbg = TRUE) { current <- currentCranVersion(name) if (nrow(current) == 0L) { - message(sprintf("Package '%s' does not seem to be on CRAN.", name)) + + if (dbg) { + message(sprintf( + "Package '%s' does not seem to be on CRAN.", name + )) + } + return(NULL) } From 84e1f8538bd3e03949a205c5a6d37098d48ea255 Mon Sep 17 00:00:00 2001 From: hsonne Date: Sun, 30 May 2021 11:39:46 +0200 Subject: [PATCH 03/90] Do not use isOnCran() to avoid duplicated calls --- R/loadDescriptionFromWeb.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/loadDescriptionFromWeb.R b/R/loadDescriptionFromWeb.R index 28d63f3..aef66ae 100644 --- a/R/loadDescriptionFromWeb.R +++ b/R/loadDescriptionFromWeb.R @@ -4,9 +4,9 @@ loadDescriptionFromWeb <- function( ) { #name = "sema.berlin";version = "1.6.1";github_user = "KWB-R" - if (isOnCran(name)) { - - versions <- cranVersions(name) + versions <- cranVersions(name, dbg = FALSE) + + if (! is.null(versions)) { version <- kwb.utils::defaultIfNA(version, rev(versions$version)[1L]) From 146e140401e93bbeb720454ea5588378c841f09b Mon Sep 17 00:00:00 2001 From: hsonne Date: Sun, 30 May 2021 11:40:22 +0200 Subject: [PATCH 04/90] Cache DESCRIPTION files in tempdir() --- R/loadDescriptionFromArchiveUrl.R | 40 ++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/R/loadDescriptionFromArchiveUrl.R b/R/loadDescriptionFromArchiveUrl.R index 98a779c..34dd4e7 100644 --- a/R/loadDescriptionFromArchiveUrl.R +++ b/R/loadDescriptionFromArchiveUrl.R @@ -1,12 +1,36 @@ # loadDescriptionFromArchiveUrl ------------------------------------------------ -loadDescriptionFromArchiveUrl <- function(url) +loadDescriptionFromArchiveUrl <- function(url, destdir = tempdir()) { stopifnot(endsWith(url, ".tar.gz")) - - destfile <- tempfile() - - utils::download.file(url, destfile) - on.exit(unlink(destfile)) - - remotes:::load_pkg_description(destfile) + + filename_tar <- basename(url) + filename_desc <- paste0(filename_tar, "_DESCRIPTION") + path_desc <- file.path(tempdir(), filename_desc) + + if (file.exists(path_desc)) { + + message("Reading from existing ", filename_desc) + + } else { + + # Download .tar.gz file + destfile <- file.path(destdir, filename_tar) + utils::download.file(url, destfile) + on.exit(unlink(destfile)) + + # Extract DESCRIPTION from downloaded .tar.gz file + # see remotes:::load_pkg_description + dir <- tempfile() + path_desc_tmp <- remotes:::untar_description(destfile, dir = dir) + on.exit(unlink(dir, recursive = TRUE), add = TRUE) + + # Keep only the DESCRIPTION in a .tar.gz.DESCRIPTION file + file.copy(path_desc_tmp, path_desc) + } + + # see remotes:::load_pkg_description + desc <- remotes:::read_dcf(path_desc) + names(desc) <- tolower(names(desc)) + desc$path <- path_desc + desc } From 007aa162106adf4679b6d293254ed9b815e6cc29 Mon Sep 17 00:00:00 2001 From: hsonne Date: Mon, 22 Jan 2024 13:59:16 +0100 Subject: [PATCH 05/90] Refactor loadDescriptionFromArchiveUrl() - rename arg "destdir" to "path" - extract untarDescriptionFromUrl() - extract pathDescription() --- R/loadDescriptionFromArchiveUrl.R | 70 ++++++++++++++++++------------- R/utils.R | 3 +- 2 files changed, 44 insertions(+), 29 deletions(-) diff --git a/R/loadDescriptionFromArchiveUrl.R b/R/loadDescriptionFromArchiveUrl.R index fb6f2c1..6f8c190 100644 --- a/R/loadDescriptionFromArchiveUrl.R +++ b/R/loadDescriptionFromArchiveUrl.R @@ -4,38 +4,52 @@ #' @noMd #' @keywords internal #' @importFrom utils download.file -loadDescriptionFromArchiveUrl <- function(url, destdir = tempdir()) +loadDescriptionFromArchiveUrl <- function(url, path = tempfile()) { - stopifnot(endsWith(url, ".tar.gz")) + untarDescriptionFromUrl(url, path) - filename_tar <- basename(url) - filename_desc <- paste0(filename_tar, "_DESCRIPTION") - path_desc <- file.path(tempdir(), filename_desc) + # see remotes:::load_pkg_description + desc <- remotes:::read_dcf(path) + names(desc) <- tolower(names(desc)) + desc$path <- path + + desc +} - if (file.exists(path_desc)) { - - message("Reading from existing ", filename_desc) - - } else { +# untarDescriptionFromUrl ------------------------------------------------------ +untarDescriptionFromUrl <- function(url, target = NULL, destdir = tempdir()) +{ + stopifnot(endsWith(url, ".tar.gz")) + + tarname <- basename(url) - # Download .tar.gz file - destfile <- file.path(destdir, filename_tar) - utils::download.file(url, destfile) - on.exit(unlink(destfile)) + # Download .tar.gz file + destfile <- file.path(destdir, tarname) + utils::download.file(url, destfile) + on.exit(unlink(destfile)) + + # Extract DESCRIPTION from downloaded .tar.gz file + # see remotes:::load_pkg_description + dir <- tempfile() + target_tmp <- remotes:::untar_description(destfile, dir = dir) + on.exit(unlink(dir, recursive = TRUE), add = TRUE) + + # Keep only the DESCRIPTION in a .tar.gz.DESCRIPTION file + target <- kwb.utils::defaultIfNULL(target, pathDescription(tarname, destdir)) - # Extract DESCRIPTION from downloaded .tar.gz file - # see remotes:::load_pkg_description - dir <- tempfile() - path_desc_tmp <- remotes:::untar_description(destfile, dir = dir) - on.exit(unlink(dir, recursive = TRUE), add = TRUE) - - # Keep only the DESCRIPTION in a .tar.gz.DESCRIPTION file - file.copy(path_desc_tmp, path_desc) - } + file.copy(target_tmp, target) + + target +} - # see remotes:::load_pkg_description - desc <- remotes:::read_dcf(path_desc) - names(desc) <- tolower(names(desc)) - desc$path <- path_desc - desc +# pathDescription -------------------------------------------------------------- +pathDescription <- function(name, version, tarname, destdir = tempdir()) +{ + #name <- gsub("\\.tar\\.gz$", "", tarname) + #file.path(destdir, sprintf("DESCRIPTION_%s.txt", name)) + #path <- pathDescription(tarname) + file.path(destdir, getUrl( + "cached_desc", package = name, version = version + )) + } diff --git a/R/utils.R b/R/utils.R index a0e12e6..2604438 100644 --- a/R/utils.R +++ b/R/utils.R @@ -17,7 +17,8 @@ getUrl <- function(key, ...) github_api = "https://api.github.com/repos/", github_desc = "//DESCRIPTION", github_releases = "/releases", - github_tags = "/tags" + github_tags = "/tags", + cached_desc = "DESCRIPTION__.txt" )) kwb.utils::selectElements(urls, key) From d504ed3d89abdf38d807f3d793cb50bed076b20c Mon Sep 17 00:00:00 2001 From: hsonne Date: Mon, 22 Jan 2024 14:03:12 +0100 Subject: [PATCH 06/90] Refactor readGithubPackageDescription() - add arg "destdir" - Use package name and version in file name --- R/readGithubPackageDescription.R | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/R/readGithubPackageDescription.R b/R/readGithubPackageDescription.R index be87c7c..b9e1d76 100644 --- a/R/readGithubPackageDescription.R +++ b/R/readGithubPackageDescription.R @@ -5,7 +5,7 @@ #' @importFrom gh gh #' @importFrom kwb.utils selectElements readGithubPackageDescription <- function( - repo, sha, auth_token = remotes:::github_pat() + repo, sha, auth_token = remotes:::github_pat(), destdir = tempdir() ) { endpoint <- getUrl("github_desc", repo = repo, sha = sha) @@ -15,18 +15,21 @@ readGithubPackageDescription <- function( return(NULL) } - txt <- kwb.utils::selectElements(content, "message") - - # Read DESCRIPTION from character instead of file - read_dcf <- function(...) { - con <- textConnection(txt) - on.exit(close(con)) - read.dcf(con, ...) - } + # Save to local DESCRIPTION file + file <- tempfile() + on.exit(unlink(file)) - # See remotes:::read_dcf - fields <- colnames(read_dcf()) - desc <- as.list(read_dcf(keep.white = fields)[1L, ]) + writeLines(kwb.utils::selectElements(content, "message"), file) + + # Read local DESCRIPTION file + desc <- remotes:::read_dcf(file) + + # Use package name and version to generate a name for the cached + # DESCRIPTION file. Copy the DESCRITPION file to a file of that name. + get <- kwb.utils::createAccessor(desc) + file.copy(file, file.path(destdir, getUrl( + "cached_desc", package = get("Package"), version = get("Version") + ))) # See remotes:::load_pkg_description names(desc) <- tolower(names(desc)) From 0aa59ee90a671b061f7d0d8b83958d556ecdcd0c Mon Sep 17 00:00:00 2001 From: hsonne Date: Mon, 22 Jan 2024 14:07:14 +0100 Subject: [PATCH 07/90] Improve loadDescriptionFromWeb() - add args "destdir", "cache" - look in the cache first --- R/loadDescriptionFromWeb.R | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/R/loadDescriptionFromWeb.R b/R/loadDescriptionFromWeb.R index 2f2d333..c61a828 100644 --- a/R/loadDescriptionFromWeb.R +++ b/R/loadDescriptionFromWeb.R @@ -5,12 +5,31 @@ #' @importFrom kwb.utils defaultIfNA selectColumns #' @importFrom gh gh loadDescriptionFromWeb <- function( - name, version = NA_character_, github_user = "KWB-R" + name, + version = NA, + github_user = "KWB-R", + destdir = tempdir(), + cache = list(descriptions = list(), versions = list()) ) { + # Try to load DESCRIPTION from cache #name = "sema.berlin";version = "1.6.1";github_user = "KWB-R" - versions <- cranVersions(name, dbg = FALSE) - + key <- paste(name, version, sep = ":") + description <- cache$descriptions[[key]] + + if (! is.null(description)) { + return(description) + } + + # Try to load package versions from cache + versions <- cache$versions[[name]] + + if (! is.null(versions)) { + description <- select_version(cran_versions) + } else { + cran_versions <- cranVersions(name, dbg = FALSE) + } + if (! is.null(versions)) { version <- kwb.utils::defaultIfNA(version, rev(versions$version)[1L]) @@ -21,7 +40,7 @@ loadDescriptionFromWeb <- function( url <- versions$package_source_url[versions$version == version] - return(loadDescriptionFromArchiveUrl(url)) + return(loadDescriptionFromArchiveUrl(url, path)) } # Look on KWB's Github account From cf2c248e9c53cbaf21a5e671e2afd0a500d74a5d Mon Sep 17 00:00:00 2001 From: hsonne Date: Mon, 22 Jan 2024 14:09:07 +0100 Subject: [PATCH 08/90] Add (undocumented) function allDeps() --- R/allDeps.R | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 R/allDeps.R diff --git a/R/allDeps.R b/R/allDeps.R new file mode 100644 index 0000000..b5f2df4 --- /dev/null +++ b/R/allDeps.R @@ -0,0 +1,41 @@ +# allDeps ---------------------------------------------------------------------- +allDeps <- function( + name, + version = NA, + depth = 1L, + max_depth = 9L, + cache = list() +) +{ + pkg <- loadDescriptionFromWeb(name, version) + + stopifnot(is.na(version) || identical(version, pkg$version)) + + deps <- parsePackageDeps(pkg) + + if (inherits(deps, "try-error") || nrow(deps) == 0L) { + return(NULL) + } + + message("depth: ", depth) + + deps$depth <- depth + deps$namever <- paste(name, version, sep = ":") + + if (depth == max_depth) { + message("maximum depth (", max_depth, ") reached.") + return(deps) + } + + child_deps <- lapply(seq_len(nrow(deps)), function(i) { + allDeps(deps$name[i], deps$version[i], depth + 1L, max_depth) + }) + + child_deps <- kwb.utils::excludeNULL(child_deps, dbg = FALSE) + + if (length(child_deps) > 0L) { + deps <- rbind(deps, do.call(rbind, child_deps)) + } + + deps +} From fa0add3f4ad219cb7877692a18b7aa806ce00bc4 Mon Sep 17 00:00:00 2001 From: hsonne Date: Mon, 22 Jan 2024 14:09:40 +0100 Subject: [PATCH 09/90] Add plot.package_versions() --- R/plot_package_versions.R | 97 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 R/plot_package_versions.R diff --git a/R/plot_package_versions.R b/R/plot_package_versions.R new file mode 100644 index 0000000..248f867 --- /dev/null +++ b/R/plot_package_versions.R @@ -0,0 +1,97 @@ +# plot.package_versions -------------------------------------------------------- +plot.package_versions <- function( + versions, r_range = c(1, 10), rmax = 1.1 * r_range[2L], dphi = NULL, + ticklen = 1 +) +{ + #r_range=c(1,10);rmax = 1.1 * r_range[2L] + old_par <- graphics::par(mar = c(2, 2, 1, 1)) + on.exit(graphics::par(old_par)) + + versions$r <- map_to_range( + x = as.integer(kwb.utils::selectColumns(versions, "date")), + y_range = r_range + ) + + X <- split(versions, kwb.utils::selectColumns(versions, "package")) + + phis <- seq_rad_len(length(X)) + + lim <- c(-rmax, rmax) + graphics::plot(0, 0, xlim = lim, ylim = lim, asp = 1, axes = FALSE) + + # Draw circles around the centre + draw_circles(r = r_range, n_corners = length(X)) + + dphi <- kwb.utils::defaultIfNULL(dphi, seq_rad_len(3 * length(X))[2L]) + + for (i in seq_along(X)) { + x <- X[[i]] + #points(polar_to_xy(phi = phis[i], r = x$r), cex = 0.5) + xy <- polar_to_xy(phi = phis[i], r = x$r) + + dx <- ticklen * sin(phis[i]) + dy <- ticklen * cos(phis[i]) + + xy_0 <- cbind(xy[, 1L] - dx, xy[, 2L] + dy) + xy_1 <- cbind(xy[, 1L] + dx, xy[, 2L] - dy) + + graphics::segments( + x0 = xy_0[, 1L], + x1 = xy_1[, 1L], + y0 = xy_0[, 2L], + y1 = xy_1[, 2L] + ) + + xy <- polar_to_xy(phi = phis[i], r = c(min(x$r), r_range[2L])) + + graphics::segments( + x0 = xy[1L, 1L], + y0 = xy[1L, 2L], + x1 = xy[2L, 1L], + y1 = xy[2L, 2L] + ) + + xy <- polar_to_xy(phi = phis[i], r = 1.04 * r_range[2L]) + + graphics::text( + xy[, 1L], + xy[, 2L], + label = x$package[1L], + srt = phis[i] / pi * 180, + cex = 0.8, + adj = 0 + ) + } +} + +# map_to_range ----------------------------------------------------------------- +map_to_range <- function(x, y_range, x_range = range(x)) +{ + y_range[1L] + (x - x_range[1L]) / diff(x_range) * diff(y_range) +} + +# seq_rad_len ------------------------------------------------------------------ +seq_rad_len <- function(n) +{ + kwb.package::gradToRad(kwb.package::equidistantAngles(n)) +} + +# draw_circles ----------------------------------------------------------------- +draw_circles <- function(r, n_corners = 36L, col = "lightgrey") +{ + phis <- seq_rad_len(n_corners) + + for (ri in r) { + xy <- do.call(rbind, lapply(c(phis, phis[1L]), polar_to_xy, r = ri)) + graphics::lines(xy, col = col) + } +} + +# polar_to_xy ------------------------------------------------------------------ +polar_to_xy <- function(phi, r) +{ + data <- c(cos(phi) * r, sin(phi) * r) + + matrix(data, ncol = 2L, dimnames = list(NULL, c("x", "y"))) +} From 4a07220f4fd28c6bec3b6796a4f857379eaf5eb7 Mon Sep 17 00:00:00 2001 From: hsonne Date: Mon, 22 Jan 2024 14:10:29 +0100 Subject: [PATCH 10/90] Improve variable names (correct spelling!) --- R/detach.R | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/R/detach.R b/R/detach.R index f80e019..b083cac 100644 --- a/R/detach.R +++ b/R/detach.R @@ -82,34 +82,34 @@ sortedDependencies <- function(package, pattern = ".*", dbg = FALSE) dependencies <- packageDependencies(dependingOn, recursive = FALSE) - allLeafs <- character() + allLeaves <- character() while (length(dependencies) > 0) { - numberOfDependencies <- sapply(dependencies, FUN = function(x) { + nDependencies <- sapply(dependencies, FUN = function(x) { length(grep(pattern, x)) }) printAndWaitIf(dbg, list( dependencies = dependencies, - numberOfDependencies = numberOfDependencies + nDependencies = nDependencies )) - # Extract the "leafs" from the dependencies - leafs <- names(dependencies)[numberOfDependencies == 0] - dependencies <- dependencies[numberOfDependencies > 0] + # Extract the "leaves" from the dependencies + leaves <- names(dependencies)[nDependencies == 0] + dependencies <- dependencies[nDependencies > 0] dependencies <- sapply( dependencies, - function(x) {setdiff(x, leafs)}, + function(x) {setdiff(x, leaves)}, simplify = FALSE ) - # Add the leafs at the beginning of the vector of all leafs - allLeafs <- c(leafs, allLeafs) + # Add the leaves at the beginning of the vector of all leaves + allLeaves <- c(leaves, allLeaves) } - c(package, allLeafs) + c(package, allLeaves) } # packageDependencies ---------------------------------------------------------- From f1e1fbd14606b380ab04d440adf36259db79fe1c Mon Sep 17 00:00:00 2001 From: hsonne Date: Mon, 22 Jan 2024 14:41:12 +0100 Subject: [PATCH 11/90] Bring function definitions into lexical order --- R/utils.R | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/R/utils.R b/R/utils.R index 2604438..ac7c335 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,3 +1,9 @@ +# dirPackageZips --------------------------------------------------------------- +dirPackageZips <- function(package, path) +{ + dir(path, paste0("^", package, "_"), full.names = TRUE) +} + # getUrl ----------------------------------------------------------------------- #' @noMd #' @noRd @@ -66,8 +72,3 @@ stop_ <- function(...) stop(..., call. = FALSE) } -# dirPackageZips --------------------------------------------------------------- -dirPackageZips <- function(package, path) -{ - dir(path, paste0("^", package, "_"), full.names = TRUE) -} From df7897ac1258c9b009d118446b91cf72873a5c6c Mon Sep 17 00:00:00 2001 From: hsonne Date: Mon, 22 Jan 2024 14:42:42 +0100 Subject: [PATCH 12/90] Provide local functions with getFromNamespace() --- R/githubPackageVersions.R | 4 ++-- R/loadDescriptionFromArchiveUrl.R | 4 ++-- R/parsePackageDeps.R | 2 +- R/readGithubPackageDescription.R | 4 ++-- R/utils.R | 12 ++++++++++++ 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/R/githubPackageVersions.R b/R/githubPackageVersions.R index c13eae8..619ee18 100644 --- a/R/githubPackageVersions.R +++ b/R/githubPackageVersions.R @@ -18,7 +18,7 @@ githubVersions <- function(name, github_user = "KWB-R") # Haukes version of github_packages_versions() githubPackageVersions <- function( repo, - auth_token = remotes:::github_pat(), + auth_token = remotes_github_pat(), verbose = TRUE, reduced = TRUE ) @@ -87,7 +87,7 @@ githubPackageVersions <- function( #' @importFrom kwb.utils noFactorDataFrame removeColumns selectElements #' @importFrom gh gh getGithubReleaseInfo <- function( - repo, reduced = TRUE, auth_token = remotes:::github_pat() + repo, reduced = TRUE, auth_token = remotes_github_pat() ) { # Shortcut diff --git a/R/loadDescriptionFromArchiveUrl.R b/R/loadDescriptionFromArchiveUrl.R index 6f8c190..d516e37 100644 --- a/R/loadDescriptionFromArchiveUrl.R +++ b/R/loadDescriptionFromArchiveUrl.R @@ -9,7 +9,7 @@ loadDescriptionFromArchiveUrl <- function(url, path = tempfile()) untarDescriptionFromUrl(url, path) # see remotes:::load_pkg_description - desc <- remotes:::read_dcf(path) + desc <- remotes_read_dcf(path) names(desc) <- tolower(names(desc)) desc$path <- path @@ -31,7 +31,7 @@ untarDescriptionFromUrl <- function(url, target = NULL, destdir = tempdir()) # Extract DESCRIPTION from downloaded .tar.gz file # see remotes:::load_pkg_description dir <- tempfile() - target_tmp <- remotes:::untar_description(destfile, dir = dir) + target_tmp <- remotes_untar_description(destfile, dir = dir) on.exit(unlink(dir, recursive = TRUE), add = TRUE) # Keep only the DESCRIPTION in a .tar.gz.DESCRIPTION file diff --git a/R/parsePackageDeps.R b/R/parsePackageDeps.R index 86bbf37..e34e98c 100644 --- a/R/parsePackageDeps.R +++ b/R/parsePackageDeps.R @@ -6,6 +6,6 @@ parsePackageDeps <- function(pkg, dependencies = NA) { deps <- tolower(remotes::standardise_dep(dependencies)) - parsed <- lapply(pkg[intersect(deps, names(pkg))], remotes:::parse_deps) + parsed <- lapply(pkg[intersect(deps, names(pkg))], remotes_parse_deps) kwb.utils::rbindAll(parsed, nameColumn = "type") } diff --git a/R/readGithubPackageDescription.R b/R/readGithubPackageDescription.R index b9e1d76..0087b36 100644 --- a/R/readGithubPackageDescription.R +++ b/R/readGithubPackageDescription.R @@ -5,7 +5,7 @@ #' @importFrom gh gh #' @importFrom kwb.utils selectElements readGithubPackageDescription <- function( - repo, sha, auth_token = remotes:::github_pat(), destdir = tempdir() + repo, sha, auth_token = remotes_github_pat(), destdir = tempdir() ) { endpoint <- getUrl("github_desc", repo = repo, sha = sha) @@ -22,7 +22,7 @@ readGithubPackageDescription <- function( writeLines(kwb.utils::selectElements(content, "message"), file) # Read local DESCRIPTION file - desc <- remotes:::read_dcf(file) + desc <- remotes_read_dcf(file) # Use package name and version to generate a name for the cached # DESCRIPTION file. Copy the DESCRITPION file to a file of that name. diff --git a/R/utils.R b/R/utils.R index ac7c335..d6fa059 100644 --- a/R/utils.R +++ b/R/utils.R @@ -54,6 +54,18 @@ packageInDestdir <- function(package, destdir, verbose = TRUE) structure(file_exists, path = if (file_exists) kwb.utils::lastElement(files)) } +# remotes_github_pat ----------------------------------------------------------- +remotes_github_pat <- getFromNamespace("github_pat", "remotes") + +# remotes_parse_deps ----------------------------------------------------------- +remotes_parse_deps <- getFromNamespace("untar_description", "remotes") + +# remotes_read_dcf ------------------------------------------------------------- +remotes_read_dcf <- getFromNamespace("read_dcf", "remotes") + +# remotes_untar_description ---------------------------------------------------- +remotes_untar_description <- getFromNamespace("untar_description", "remotes") + # readLinesFromUrl ------------------------------------------------------------- readLinesFromUrl <- function(url, silent = TRUE) { From 326b3ad7cc80aae414a9e9e8ea89a041fe14141d Mon Sep 17 00:00:00 2001 From: hsonne Date: Mon, 22 Jan 2024 14:43:06 +0100 Subject: [PATCH 13/90] Do not import packages that are not used (any more?) --- DESCRIPTION | 2 -- 1 file changed, 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 286744e..20e5372 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -19,9 +19,7 @@ License: MIT + file LICENSE URL: https://github.com/kwb-r/kwb.package BugReports: https://github.com/kwb-r/kwb.package/issues Imports: - devtools, gh, - jsonlite, kwb.utils (>= 0.5.0), mvbutils, networkD3, From 6c23fb87e44de31709840b4eef1a9ea13571f263 Mon Sep 17 00:00:00 2001 From: hsonne Date: Mon, 22 Jan 2024 14:43:37 +0100 Subject: [PATCH 14/90] Function is exported, no need for ":::" --- R/loadDescriptionFromWeb.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/loadDescriptionFromWeb.R b/R/loadDescriptionFromWeb.R index c61a828..c45b57b 100644 --- a/R/loadDescriptionFromWeb.R +++ b/R/loadDescriptionFromWeb.R @@ -35,7 +35,7 @@ loadDescriptionFromWeb <- function( version <- kwb.utils::defaultIfNA(version, rev(versions$version)[1L]) if (! version %in% versions$version) { - stop_(kwb.utils:::noSuchElements(version, versions$version, "version")) + stop_(kwb.utils::noSuchElements(version, versions$version, "version")) } url <- versions$package_source_url[versions$version == version] @@ -56,7 +56,7 @@ loadDescriptionFromWeb <- function( shas <- kwb.utils::selectColumns(versions, c("version", "sha")) if (! version %in% shas$version) { - stop_(kwb.utils:::noSuchElements(version, shas$version, "version")) + stop_(kwb.utils::noSuchElements(version, shas$version, "version")) } shas$sha[shas$version == version] From c6dd912ee0390ed788a555c328bb09e615e9754e Mon Sep 17 00:00:00 2001 From: hsonne Date: Mon, 22 Jan 2024 15:17:40 +0100 Subject: [PATCH 15/90] Try to "repair" loadDescriptionFromWeb() - rename arg "destdir" to "path" - stop() when calling non-existing function - rename "cran_versions" to "versions" TODO: implement the caching (what was the plan?) --- R/loadDescriptionFromWeb.R | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/R/loadDescriptionFromWeb.R b/R/loadDescriptionFromWeb.R index c45b57b..9a8cb92 100644 --- a/R/loadDescriptionFromWeb.R +++ b/R/loadDescriptionFromWeb.R @@ -8,12 +8,15 @@ loadDescriptionFromWeb <- function( name, version = NA, github_user = "KWB-R", - destdir = tempdir(), + path = tempdir(), cache = list(descriptions = list(), versions = list()) ) { - # Try to load DESCRIPTION from cache + #kwb.utils::assignPackageObjects("kwb.package") + #kwb.utils::assignArgumentDefaults(loadDescriptionFromWeb) #name = "sema.berlin";version = "1.6.1";github_user = "KWB-R" + + # Try to load DESCRIPTION from cache key <- paste(name, version, sep = ":") description <- cache$descriptions[[key]] @@ -25,9 +28,10 @@ loadDescriptionFromWeb <- function( versions <- cache$versions[[name]] if (! is.null(versions)) { - description <- select_version(cran_versions) + stop("loadDescriptionFromWeb(): !is.null(versions) not implemented!") + #description <- select_version(cran_versions) } else { - cran_versions <- cranVersions(name, dbg = FALSE) + versions <- cranVersions(name, dbg = FALSE) } if (! is.null(versions)) { From 9b98c0d2da039312ca9d5e0d1059c3281c48dc4c Mon Sep 17 00:00:00 2001 From: hsonne Date: Mon, 22 Jan 2024 15:30:38 +0100 Subject: [PATCH 16/90] Update RoxygenNote --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 20e5372..14cb852 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -32,4 +32,4 @@ Remotes: github::kwb-r/kwb.utils, github::kwb-r/pkgmeta Encoding: UTF-8 -RoxygenNote: 7.1.2 +RoxygenNote: 7.3.0 From 1a2aae0e5037439e62ac3243f41e9ccb1352bfae Mon Sep 17 00:00:00 2001 From: hsonne Date: Mon, 22 Jan 2024 15:34:44 +0100 Subject: [PATCH 17/90] Remove arg "pattern" from sortedDependencies() --- R/detach.R | 13 +++---------- man/sortedDependencies.Rd | 4 +--- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/R/detach.R b/R/detach.R index b083cac..318b4e7 100644 --- a/R/detach.R +++ b/R/detach.R @@ -64,7 +64,6 @@ detachRecursively <- function(package, pattern = ".*", dbg = FALSE) #' Names of depending packages in the order of their dependency #' #' @param package name of package of which dependencies are to be found -#' @param pattern pattern matching the names of packages to be considered #' @param dbg if \code{TRUE}, debug messages are shown #' #' @return vector of package names. The first element is the package itself, @@ -72,13 +71,9 @@ detachRecursively <- function(package, pattern = ".*", dbg = FALSE) #' the packages in this order without any "package ... is required by ..." #' error #' -sortedDependencies <- function(package, pattern = ".*", dbg = FALSE) +sortedDependencies <- function(package, dbg = FALSE) { - dependingOn <- grep( - pattern, - packageDependencies(package, recursive = TRUE)[[1]], - value = TRUE - ) + dependingOn <- packageDependencies(package, recursive = TRUE)[[1]] dependencies <- packageDependencies(dependingOn, recursive = FALSE) @@ -86,9 +81,7 @@ sortedDependencies <- function(package, pattern = ".*", dbg = FALSE) while (length(dependencies) > 0) { - nDependencies <- sapply(dependencies, FUN = function(x) { - length(grep(pattern, x)) - }) + nDependencies <- lengths(dependencies) printAndWaitIf(dbg, list( dependencies = dependencies, diff --git a/man/sortedDependencies.Rd b/man/sortedDependencies.Rd index ef4dd81..1d5dcf5 100644 --- a/man/sortedDependencies.Rd +++ b/man/sortedDependencies.Rd @@ -4,13 +4,11 @@ \alias{sortedDependencies} \title{Sorted Package Dependencies} \usage{ -sortedDependencies(package, pattern = ".*", dbg = FALSE) +sortedDependencies(package, dbg = FALSE) } \arguments{ \item{package}{name of package of which dependencies are to be found} -\item{pattern}{pattern matching the names of packages to be considered} - \item{dbg}{if \code{TRUE}, debug messages are shown} } \value{ From 990a495cb465b2d628a88a459440fbf55820514f Mon Sep 17 00:00:00 2001 From: hsonne Date: Mon, 22 Jan 2024 15:35:35 +0100 Subject: [PATCH 18/90] Evaluate pattern out of sortedDependencies() and correct a typo --- R/detach.R | 7 ++++--- man/detachRecursively.Rd | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/R/detach.R b/R/detach.R index 318b4e7..fd9091c 100644 --- a/R/detach.R +++ b/R/detach.R @@ -33,7 +33,7 @@ detachAllNonSystemPackages <- function() #' #' @param package name of package to be detached #' @param pattern pattern matching the names of depending packages that are -#' acutally to be detached, e.g. use pattern = "^kwb\\." to only detach kwb +#' actually to be detached, e.g. use pattern = "^kwb\\." to only detach kwb #' packages. Default: ".*" (matching all package names) #' @param dbg if \code{TRUE}, debug messages are shown #' @@ -41,9 +41,10 @@ detachAllNonSystemPackages <- function() #' detachRecursively <- function(package, pattern = ".*", dbg = FALSE) { - sortedPackages <- sortedDependencies(package, pattern = pattern, dbg = dbg) + packages <- sortedDependencies(package, dbg = dbg) + packages <- grep(pattern, packages, value = TRUE) - nonSystemPackages <- setdiff(sortedPackages, systemPackages()) + nonSystemPackages <- setdiff(packages, systemPackages()) namesToDetach <- intersect(search(), packageString(nonSystemPackages)) diff --git a/man/detachRecursively.Rd b/man/detachRecursively.Rd index 8b187db..98c1870 100644 --- a/man/detachRecursively.Rd +++ b/man/detachRecursively.Rd @@ -10,7 +10,7 @@ detachRecursively(package, pattern = ".*", dbg = FALSE) \item{package}{name of package to be detached} \item{pattern}{pattern matching the names of depending packages that are -acutally to be detached, e.g. use pattern = "^kwb\\." to only detach kwb +actually to be detached, e.g. use pattern = "^kwb\\." to only detach kwb packages. Default: ".*" (matching all package names)} \item{dbg}{if \code{TRUE}, debug messages are shown} From 0cd442cc349112d79adf7d05581d302039f4f2e4 Mon Sep 17 00:00:00 2001 From: hsonne Date: Mon, 22 Jan 2024 15:38:03 +0100 Subject: [PATCH 19/90] Use helper variable "isLeaf" --- R/detach.R | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/R/detach.R b/R/detach.R index fd9091c..8111a17 100644 --- a/R/detach.R +++ b/R/detach.R @@ -88,10 +88,13 @@ sortedDependencies <- function(package, dbg = FALSE) dependencies = dependencies, nDependencies = nDependencies )) - + + # Which dependency is a "leaf" (i.e. does not have further dependencies)? + isLeaf <- nDependencies == 0L + # Extract the "leaves" from the dependencies - leaves <- names(dependencies)[nDependencies == 0] - dependencies <- dependencies[nDependencies > 0] + leaves <- names(dependencies)[isLeaf] + dependencies <- dependencies[!isLeaf] dependencies <- sapply( dependencies, From f146b2462ccded1984b831a459abcbc3cbf80f61 Mon Sep 17 00:00:00 2001 From: hsonne Date: Mon, 22 Jan 2024 15:40:01 +0100 Subject: [PATCH 20/90] Simplify the sapply() call and integrate the filtering for "!isLeaf" --- R/detach.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/detach.R b/R/detach.R index 8111a17..49fa3c8 100644 --- a/R/detach.R +++ b/R/detach.R @@ -94,11 +94,11 @@ sortedDependencies <- function(package, dbg = FALSE) # Extract the "leaves" from the dependencies leaves <- names(dependencies)[isLeaf] - dependencies <- dependencies[!isLeaf] - + dependencies <- sapply( - dependencies, - function(x) {setdiff(x, leaves)}, + dependencies[!isLeaf], + FUN = setdiff, + y = leaves, simplify = FALSE ) From 2d835f13a081dfde031fa323f0c74f4210af68ee Mon Sep 17 00:00:00 2001 From: hsonne Date: Mon, 22 Jan 2024 15:42:43 +0100 Subject: [PATCH 21/90] No need for "> 0" in while() condition check --- R/detach.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/detach.R b/R/detach.R index 49fa3c8..e370ccb 100644 --- a/R/detach.R +++ b/R/detach.R @@ -80,7 +80,7 @@ sortedDependencies <- function(package, dbg = FALSE) allLeaves <- character() - while (length(dependencies) > 0) { + while (length(dependencies)) { nDependencies <- lengths(dependencies) From 71d0c993802f66aead2899401ba90e83fe8dcb3d Mon Sep 17 00:00:00 2001 From: hsonne Date: Mon, 22 Jan 2024 15:42:55 +0100 Subject: [PATCH 22/90] Add a comment --- R/detach.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/detach.R b/R/detach.R index e370ccb..94f35df 100644 --- a/R/detach.R +++ b/R/detach.R @@ -95,6 +95,7 @@ sortedDependencies <- function(package, dbg = FALSE) # Extract the "leaves" from the dependencies leaves <- names(dependencies)[isLeaf] + # Remove the names of the leaf packages from the dependency tree dependencies <- sapply( dependencies[!isLeaf], FUN = setdiff, From 22d00234793dffee53b57314da0f90f0ebde57f3 Mon Sep 17 00:00:00 2001 From: hsonne Date: Mon, 22 Jan 2024 16:01:17 +0100 Subject: [PATCH 23/90] Allow for more than one package and export sortedDependencies() --- NAMESPACE | 1 + R/detach.R | 23 ++++++++++++++++------- man/sortedDependencies.Rd | 5 +++-- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 6f0877f..0da52ba 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -30,6 +30,7 @@ export(plotNodes) export(plotSankeyNetwork) export(provideInLocalCRAN) export(setOptionsForPackrat) +export(sortedDependencies) export(systemPackages) export(toLinksAndNodes) export(toNodes) diff --git a/R/detach.R b/R/detach.R index 94f35df..70fdbb4 100644 --- a/R/detach.R +++ b/R/detach.R @@ -64,19 +64,28 @@ detachRecursively <- function(package, pattern = ".*", dbg = FALSE) #' #' Names of depending packages in the order of their dependency #' -#' @param package name of package of which dependencies are to be found -#' @param dbg if \code{TRUE}, debug messages are shown -#' +#' @param package name of package(s) of which dependencies are to be found +#' @param dbg if \code{TRUE}, debug messages are shown and the user is asked +#' to press Enter each time the body of the main loop is passed! #' @return vector of package names. The first element is the package itself, #' followed by the names of depending packages. You should be able to detach #' the packages in this order without any "package ... is required by ..." #' error -#' +#' @export sortedDependencies <- function(package, dbg = FALSE) { - dependingOn <- packageDependencies(package, recursive = TRUE)[[1]] + fullDependencies <- packageDependencies(package, recursive = TRUE) - dependencies <- packageDependencies(dependingOn, recursive = FALSE) + # Put all unique package names from the dependency tree into a vector + packages <- unique(unname(unlist(fullDependencies))) + + # Get sorted vector of unique package names (including those in package) + packages <- sort(unique(c(packages, package))) + + #packages <- fullDependencies[[1]] + + # Get the "direct" (non-recursive) dependencies for each package + dependencies <- packageDependencies(packages, recursive = FALSE) allLeaves <- character() @@ -107,7 +116,7 @@ sortedDependencies <- function(package, dbg = FALSE) allLeaves <- c(leaves, allLeaves) } - c(package, allLeaves) + allLeaves } # packageDependencies ---------------------------------------------------------- diff --git a/man/sortedDependencies.Rd b/man/sortedDependencies.Rd index 1d5dcf5..fd3e736 100644 --- a/man/sortedDependencies.Rd +++ b/man/sortedDependencies.Rd @@ -7,9 +7,10 @@ sortedDependencies(package, dbg = FALSE) } \arguments{ -\item{package}{name of package of which dependencies are to be found} +\item{package}{name of package(s) of which dependencies are to be found} -\item{dbg}{if \code{TRUE}, debug messages are shown} +\item{dbg}{if \code{TRUE}, debug messages are shown and the user is asked +to press Enter each time the body of the main loop is passed!} } \value{ vector of package names. The first element is the package itself, From 1ec3fb69a70548da397e8dc4113b4c59cf04f3ea Mon Sep 17 00:00:00 2001 From: hsonne Date: Tue, 9 Apr 2024 18:25:31 +0200 Subject: [PATCH 24/90] Export plot.package_versions(), TODO: document! --- NAMESPACE | 1 + R/plot_package_versions.R | 2 ++ 2 files changed, 3 insertions(+) diff --git a/NAMESPACE b/NAMESPACE index 0da52ba..7032f39 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,5 +1,6 @@ # Generated by roxygen2: do not edit by hand +S3method(plot,package_versions) export(addNodeLabels) export(anglesToPoints) export(archivedCranVersions) diff --git a/R/plot_package_versions.R b/R/plot_package_versions.R index 248f867..025a1a1 100644 --- a/R/plot_package_versions.R +++ b/R/plot_package_versions.R @@ -1,4 +1,6 @@ # plot.package_versions -------------------------------------------------------- + +#' @export plot.package_versions <- function( versions, r_range = c(1, 10), rmax = 1.1 * r_range[2L], dphi = NULL, ticklen = 1 From d76a0d9f14f7a3e6e3896dcb009ec725ebcae439 Mon Sep 17 00:00:00 2001 From: hsonne Date: Tue, 9 Apr 2024 18:26:18 +0200 Subject: [PATCH 25/90] Add "Tutorial" vignette, start with slack post --- .gitignore | 3 +- DESCRIPTION | 7 +++- vignettes/.gitignore | 2 + vignettes/tutorial.Rmd | 94 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 vignettes/.gitignore create mode 100644 vignettes/tutorial.Rmd diff --git a/.gitignore b/.gitignore index 9569181..8add92a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ .Rhistory .RData .Ruserdata -R/\.* \ No newline at end of file +R/\.* +inst/doc diff --git a/DESCRIPTION b/DESCRIPTION index 14cb852..1581c3e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -27,9 +27,12 @@ Imports: withr Suggests: covr, - pkgmeta + knitr, + pkgmeta, + rmarkdown Remotes: github::kwb-r/kwb.utils, github::kwb-r/pkgmeta Encoding: UTF-8 -RoxygenNote: 7.3.0 +RoxygenNote: 7.3.1 +VignetteBuilder: knitr diff --git a/vignettes/.gitignore b/vignettes/.gitignore new file mode 100644 index 0000000..097b241 --- /dev/null +++ b/vignettes/.gitignore @@ -0,0 +1,2 @@ +*.html +*.R diff --git a/vignettes/tutorial.Rmd b/vignettes/tutorial.Rmd new file mode 100644 index 0000000..35130a2 --- /dev/null +++ b/vignettes/tutorial.Rmd @@ -0,0 +1,94 @@ +--- +title: "Tutorial" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{Tutorial} + %\VignetteEncoding{UTF-8} + %\VignetteEngine{knitr::rmarkdown} +editor_options: + chunk_output_type: console +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +The package "kwb.package" has been developed when the KWB packages were not yet +on GitHub but on KWB's internal Subversion server. That time, it was quite +complicated to install KWB packages, especially when a package was depending +on further KWB packages. Things got simpler when we moved our packages to +GitHub and could use the `install_github()` function from the "remotes" package +to install our packages. Nevertheless, "kwb.package" contains some useful +functions about packages in general, such as functions to analyse or plot +package dependencies. I will demonstrate the usage of some of these functions +here. + +## Installation + +```{r eval = FALSE} +# Install the latest "release" from our R-universe server +install.packages("kwb.package", repos = "https://kwb-r.r-universe.dev") + +# Install the development version from GitHub +remotes::install_github("kwb-r/kwb.package@dev") +``` + +## Cook Book Recipes + +### What packages does a package depend on? + +To find out what packages an R package depends on you may use the function `packageDependencies()`: + +```{r} +# What packages does the package "ggplot2" depend on? +# (including all sub-dependencies)? +kwb.package::packageDependencies("ggplot2") + +# What packages does the package "kwb.package" itself depend on? +kwb.package::packageDependencies("kwb.package") + +# Oops! + +# What are the direct dependencies, without its sub-dependencies? +kwb.package::packageDependencies("kwb.package", recursive = FALSE) +``` + +### By what other (installed) packages a package is used? + +For a given package the function `packageDependencies()` can also find out +what other (installed!) packages are depending on it. I am curious, for example +which of my packages are depending on the "kwb.utils" package: + +```{r} +kwb.package::packageDependencies("kwb.utils", reverse = TRUE) +``` + +Quite a lot! +Does the `recursive` argument (`TRUE` by default) make any difference here? + +```{r} +kwb.package::packageDependencies("kwb.utils", reverse = TRUE, recursive = FALSE) +``` + +No. Is it the case for other packages, e.g. the "dplyr" package? + +```{r} +kwb.package::packageDependencies("dplyr", reverse = TRUE, recursive = TRUE) +kwb.package::packageDependencies("dplyr", reverse = TRUE, recursive = FALSE) +``` + +Yes. + +### How can I visualise package dependencies? + +```{r fig.width = 6, fig.height = 6, out.width = "60%"} +packages <- c("wasserportal", "kwb.dwd") +dependencies <- kwb.package::packageDependencies(packages, recursive = FALSE) +par(mar = c(3, 0, 6, 0), xpd = TRUE) +kwb.package::plotAllDependencies(dependencies, for.each = FALSE) +``` + +There are some packages that are used by both, "wasserportal" and "kwb.dwd". From 0093cf35173a37cff8c0238172d584ed44897705 Mon Sep 17 00:00:00 2001 From: Hauke Sonnenberg Date: Thu, 11 Apr 2024 08:32:40 +0200 Subject: [PATCH 26/90] Indicate dev version in version number --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 1581c3e..4e2111b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: kwb.package Title: Install / Unstall KWB Packages and Show Package Dependencies -Version: 0.3.0 +Version: 0.3.0.9000 Authors@R: c( person("Hauke", "Sonnenberg", , "hauke.sonnenberg@kompetenz-wasser.de", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-9134-2871")), From 488dcfcbede441f280d3845589449961146afcb4 Mon Sep 17 00:00:00 2001 From: Hauke Sonnenberg Date: Thu, 11 Apr 2024 08:42:48 +0200 Subject: [PATCH 27/90] Replace master with v2 in actions yaml --- .github/workflows/R-CMD-check.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 2bf5cb4..3b03cdc 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -36,11 +36,11 @@ jobs: steps: - uses: actions/checkout@v2 - - uses: r-lib/actions/setup-r@master + - uses: r-lib/actions/setup-r@v2 with: r-version: ${{ matrix.config.r }} - - uses: r-lib/actions/setup-pandoc@master + - uses: r-lib/actions/setup-pandoc@v2 - name: Query dependencies run: | @@ -76,7 +76,7 @@ jobs: - name: Upload check results if: failure() - uses: actions/upload-artifact@master + uses: actions/upload-artifact@v3 with: name: ${{ runner.os }}-r${{ matrix.config.r }}-results path: check From 1a08a9ed9a7da60d7b39da349a7ed7c3ceb421ad Mon Sep 17 00:00:00 2001 From: mrustl Date: Thu, 11 Apr 2024 10:23:57 +0200 Subject: [PATCH 28/90] Fix GH axtion by using "v2" --- .github/workflows/pkgdown.yaml | 4 ++-- .github/workflows/test-coverage.yaml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml index 8363b75..cd2c7c9 100644 --- a/.github/workflows/pkgdown.yaml +++ b/.github/workflows/pkgdown.yaml @@ -15,9 +15,9 @@ jobs: steps: - uses: actions/checkout@v2 - - uses: r-lib/actions/setup-r@master + - uses: r-lib/actions/setup-r@v2 - - uses: r-lib/actions/setup-pandoc@master + - uses: r-lib/actions/setup-pandoc@v2 - name: Query dependencies run: | diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index b9460b4..0f014df 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -18,9 +18,9 @@ jobs: steps: - uses: actions/checkout@v2 - - uses: r-lib/actions/setup-r@master + - uses: r-lib/actions/setup-r@v2 - - uses: r-lib/actions/setup-pandoc@master + - uses: r-lib/actions/setup-pandoc@v2 - name: Query dependencies run: | From 8c8f974f6a44fde731932975e1021156b3c63d8a Mon Sep 17 00:00:00 2001 From: mrustl Date: Thu, 11 Apr 2024 10:46:44 +0200 Subject: [PATCH 29/90] Fix Rcmdcheck by getting rid of "dot" in function name. See: https://stackoverflow.com/questions/49144680/checking-s3-generic-method-consistency-warning --- NAMESPACE | 2 +- R/plot_package_versions.R | 9 +++++++-- man/plotPackageVersions.Rd | 28 ++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 man/plotPackageVersions.Rd diff --git a/NAMESPACE b/NAMESPACE index 7032f39..65c016d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,5 @@ # Generated by roxygen2: do not edit by hand -S3method(plot,package_versions) export(addNodeLabels) export(anglesToPoints) export(archivedCranVersions) @@ -28,6 +27,7 @@ export(packageString) export(plotAllDependencies) export(plotDependencies) export(plotNodes) +export(plotPackageVersions) export(plotSankeyNetwork) export(provideInLocalCRAN) export(setOptionsForPackrat) diff --git a/R/plot_package_versions.R b/R/plot_package_versions.R index 025a1a1..5cde451 100644 --- a/R/plot_package_versions.R +++ b/R/plot_package_versions.R @@ -1,7 +1,12 @@ # plot.package_versions -------------------------------------------------------- - +#' Plot Package Versions +#' @param versions versions +#' @param r_range r_range (default: c(1, 10)) +#' @param rmax rmax (default: 1.1 * r_range[2L]) +#' @param dphi dphi (default: NULL) +#' @param ticklen ticklen (default: 1) #' @export -plot.package_versions <- function( +plotPackageVersions <- function( versions, r_range = c(1, 10), rmax = 1.1 * r_range[2L], dphi = NULL, ticklen = 1 ) diff --git a/man/plotPackageVersions.Rd b/man/plotPackageVersions.Rd new file mode 100644 index 0000000..b2fced1 --- /dev/null +++ b/man/plotPackageVersions.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plot_package_versions.R +\name{plotPackageVersions} +\alias{plotPackageVersions} +\title{Plot Package Versions} +\usage{ +plotPackageVersions( + versions, + r_range = c(1, 10), + rmax = 1.1 * r_range[2L], + dphi = NULL, + ticklen = 1 +) +} +\arguments{ +\item{versions}{versions} + +\item{r_range}{r_range (default: c(1, 10))} + +\item{rmax}{rmax (default: 1.1 * r_range[2L])} + +\item{dphi}{dphi (default: NULL)} + +\item{ticklen}{ticklen (default: 1)} +} +\description{ +Plot Package Versions +} From 958b6728b14fad9305cc1b4dcb597b22bdfdae66 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 12 Apr 2024 10:35:27 +0200 Subject: [PATCH 30/90] Move CRAN-related functions to cran_helpers.R --- R/archivedCranVersions.R | 76 +------------------------------------ R/cran_helpers.R | 75 ++++++++++++++++++++++++++++++++++++ man/archivedCranVersions.Rd | 4 +- 3 files changed, 77 insertions(+), 78 deletions(-) create mode 100644 R/cran_helpers.R diff --git a/R/archivedCranVersions.R b/R/archivedCranVersions.R index 8d93217..c2aec80 100644 --- a/R/archivedCranVersions.R +++ b/R/archivedCranVersions.R @@ -1,79 +1,5 @@ -# isOnCran --------------------------------------------------------------------- -isOnCran <- function(name) -{ - nrow(currentCranVersion(name)) > 0L -} - -# cranVersions ----------------------------------------------------------------- - -#' @noMd -#' @noRd -#' @keywords internal -#' @importFrom kwb.utils removeColumns safeRowBind -cranVersions <- function(name, dbg = TRUE) -{ - current <- currentCranVersion(name) - - if (nrow(current) == 0L) { - - if (dbg) { - message(sprintf( - "Package '%s' does not seem to be on CRAN.", name - )) - } - - return(NULL) - } - - archived <- archivedCranVersions(name) - - current$package_source_url <- getUrl( - "cran_package_file", package = name, version = current$version - ) - - archived$package_source_url <- sprintf( - getUrl("cran_archive_file", package = name, package_filename = "%s"), - archived$archive_file - ) - - result <- kwb.utils::safeRowBind(archived, current) - - kwb.utils::removeColumns(result, "archive_file") -} - -# currentCranVersion ----------------------------------------------------------- -#' @noMd -#' @noRd -#' @keywords internal -#' @importFrom kwb.utils noFactorDataFrame -currentCranVersion <- function(name) -{ - src <- readLinesFromUrl(getUrl("cran_package", package = name)) - - was_removed_pattern <- "was removed from the CRAN repository" - - if (is.null(src) || any(grepl(was_removed_pattern, src))) { - return(kwb.utils::noFactorDataFrame( - package = character(0L), - version = character(0L), - date = as.Date(character(0L)), - date_type = character(0L) - )) - } - - extract <- function(x) { - gsub("|", "", src[grep(sprintf("%s:", x), src) + 1L]) - } - - kwb.utils::noFactorDataFrame( - package = name, - version = extract("Version"), - date = as.Date(extract("Published")), - date_type = "published" - ) -} +# archivedCranVersions --------------------------------------------------------- -#' archivedCranVersions -------------------------------------------------------- #' Archived CRAN versions #' #' @param package package name diff --git a/R/cran_helpers.R b/R/cran_helpers.R new file mode 100644 index 0000000..913760b --- /dev/null +++ b/R/cran_helpers.R @@ -0,0 +1,75 @@ +# currentCranVersion ----------------------------------------------------------- + +#' @noMd +#' @noRd +#' @keywords internal +#' @importFrom kwb.utils noFactorDataFrame +currentCranVersion <- function(name) +{ + src <- readLinesFromUrl(getUrl("cran_package", package = name)) + + was_removed_pattern <- "was removed from the CRAN repository" + + if (is.null(src) || any(grepl(was_removed_pattern, src))) { + return(kwb.utils::noFactorDataFrame( + package = character(0L), + version = character(0L), + date = as.Date(character(0L)), + date_type = character(0L) + )) + } + + extract <- function(x) { + gsub("|", "", src[grep(sprintf("%s:", x), src) + 1L]) + } + + kwb.utils::noFactorDataFrame( + package = name, + version = extract("Version"), + date = as.Date(extract("Published")), + date_type = "published" + ) +} + +# cranVersions ----------------------------------------------------------------- + +#' @noMd +#' @noRd +#' @keywords internal +#' @importFrom kwb.utils removeColumns safeRowBind +cranVersions <- function(name, dbg = TRUE) +{ + current <- currentCranVersion(name) + + if (nrow(current) == 0L) { + + if (dbg) { + message(sprintf( + "Package '%s' does not seem to be on CRAN.", name + )) + } + + return(NULL) + } + + archived <- archivedCranVersions(name) + + current$package_source_url <- getUrl( + "cran_package_file", package = name, version = current$version + ) + + archived$package_source_url <- sprintf( + getUrl("cran_archive_file", package = name, package_filename = "%s"), + archived$archive_file + ) + + result <- kwb.utils::safeRowBind(archived, current) + + kwb.utils::removeColumns(result, "archive_file") +} + +# isOnCran --------------------------------------------------------------------- +isOnCran <- function(name) +{ + nrow(currentCranVersion(name)) > 0L +} diff --git a/man/archivedCranVersions.Rd b/man/archivedCranVersions.Rd index fb1e803..19bda2c 100644 --- a/man/archivedCranVersions.Rd +++ b/man/archivedCranVersions.Rd @@ -2,8 +2,7 @@ % Please edit documentation in R/archivedCranVersions.R \name{archivedCranVersions} \alias{archivedCranVersions} -\title{archivedCranVersions -------------------------------------------------------- -Archived CRAN versions} +\title{Archived CRAN versions} \usage{ archivedCranVersions(package, ref_date = NULL) } @@ -13,7 +12,6 @@ archivedCranVersions(package, ref_date = NULL) \item{ref_date}{default: NULL} } \description{ -archivedCranVersions -------------------------------------------------------- Archived CRAN versions } \examples{ From 6279815f63cb55b2d547cda647dc4c829e9ec061 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 12 Apr 2024 11:02:15 +0200 Subject: [PATCH 31/90] Use getPath() for two more URLs --- R/downloadPackagesFromSnapshot.R | 2 +- R/install_github_packages.R | 2 +- R/utils.R | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/R/downloadPackagesFromSnapshot.R b/R/downloadPackagesFromSnapshot.R index da89203..d55d960 100644 --- a/R/downloadPackagesFromSnapshot.R +++ b/R/downloadPackagesFromSnapshot.R @@ -24,7 +24,7 @@ downloadPackagesFromSnapshot <- function( return(character(0)) } - repos <- paste0("https://mran.microsoft.com/snapshot/", snapshot_date) + repos <- getPath("mran_snapshot", date = snapshot_date) if (is.null(destdir)) { diff --git a/R/install_github_packages.R b/R/install_github_packages.R index 2b250b6..6a988c0 100644 --- a/R/install_github_packages.R +++ b/R/install_github_packages.R @@ -59,7 +59,7 @@ installGithubPackages <- function( { withr::with_libpaths(kwb.utils::createDirectory(lib, dbg = FALSE), code = { - install.packages("remotes", repos = "https://cran.rstudio.org") + install.packages("remotes", repos = getPath("cran_rstudio")) for (repo in repos) { diff --git a/R/utils.R b/R/utils.R index d6fa059..73be77c 100644 --- a/R/utils.R +++ b/R/utils.R @@ -13,6 +13,8 @@ getUrl <- function(key, ...) { urls <- kwb.utils::resolve(..., x = list( cran = "https://cran.r-project.org", + cran_rstudio = "https://cran.rstudio.org", + mran_snapshot = "https://mran.microsoft.com/snapshot/", cran_contrib = "/src/contrib", cran_package = "/web/packages/", cran_archive = "/Archive/", From 063e438a2db35ac0ddfa3aaeecbb75c809d0cef3 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 12 Apr 2024 11:06:36 +0200 Subject: [PATCH 32/90] Move non-general functions to extra files --- R/helpers.R | 58 +++++++++++++++++++++++++++++++++++++ R/remotes_imports.R | 11 +++++++ R/utils.R | 70 --------------------------------------------- 3 files changed, 69 insertions(+), 70 deletions(-) create mode 100644 R/helpers.R create mode 100644 R/remotes_imports.R diff --git a/R/helpers.R b/R/helpers.R new file mode 100644 index 0000000..a540fdc --- /dev/null +++ b/R/helpers.R @@ -0,0 +1,58 @@ +# dirPackageZips --------------------------------------------------------------- +dirPackageZips <- function(package, path) +{ + dir(path, paste0("^", package, "_"), full.names = TRUE) +} + +# getUrl ----------------------------------------------------------------------- +#' @noMd +#' @noRd +#' @keywords internal +#' @importFrom kwb.utils selectElements +getUrl <- function(key, ...) +{ + urls <- kwb.utils::resolve(..., x = list( + cran = "https://cran.r-project.org", + cran_rstudio = "https://cran.rstudio.org", + mran_snapshot = "https://mran.microsoft.com/snapshot/", + cran_contrib = "/src/contrib", + cran_package = "/web/packages/", + cran_archive = "/Archive/", + cran_archive_file = "/", + cran_package_file = "/", + package_filename = "_.tar.gz", + github_raw = "https://raw.githubusercontent.com/", + github_api = "https://api.github.com/repos/", + github_desc = "//DESCRIPTION", + github_releases = "/releases", + github_tags = "/tags", + cached_desc = "DESCRIPTION__.txt" + )) + + kwb.utils::selectElements(urls, key) +} + +# githubRepo ------------------------------------------------------------------- +githubRepo <- function(github_user, name) +{ + paste(github_user, name, sep = "/") +} + +# packageInDestdir ------------------------------------------------------------- +#' @noMd +#' @noRd +#' @keywords internal +#' @importFrom kwb.utils safePath +packageInDestdir <- function(package, destdir, verbose = TRUE) +{ + files <- dirPackageZips(package, kwb.utils::safePath(destdir)) + + file_exists <- length(files) > 0L + + if (verbose && file_exists) { + message("Skipping already downloaded package '", package, "'") + } + + structure(file_exists, path = if (file_exists) kwb.utils::lastElement(files)) +} + diff --git a/R/remotes_imports.R b/R/remotes_imports.R new file mode 100644 index 0000000..d633bc5 --- /dev/null +++ b/R/remotes_imports.R @@ -0,0 +1,11 @@ +# remotes_github_pat ----------------------------------------------------------- +remotes_github_pat <- getFromNamespace("github_pat", "remotes") + +# remotes_parse_deps ----------------------------------------------------------- +remotes_parse_deps <- getFromNamespace("untar_description", "remotes") + +# remotes_read_dcf ------------------------------------------------------------- +remotes_read_dcf <- getFromNamespace("read_dcf", "remotes") + +# remotes_untar_description ---------------------------------------------------- +remotes_untar_description <- getFromNamespace("untar_description", "remotes") diff --git a/R/utils.R b/R/utils.R index 73be77c..924396c 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,73 +1,3 @@ -# dirPackageZips --------------------------------------------------------------- -dirPackageZips <- function(package, path) -{ - dir(path, paste0("^", package, "_"), full.names = TRUE) -} - -# getUrl ----------------------------------------------------------------------- -#' @noMd -#' @noRd -#' @keywords internal -#' @importFrom kwb.utils selectElements -getUrl <- function(key, ...) -{ - urls <- kwb.utils::resolve(..., x = list( - cran = "https://cran.r-project.org", - cran_rstudio = "https://cran.rstudio.org", - mran_snapshot = "https://mran.microsoft.com/snapshot/", - cran_contrib = "/src/contrib", - cran_package = "/web/packages/", - cran_archive = "/Archive/", - cran_archive_file = "/", - cran_package_file = "/", - package_filename = "_.tar.gz", - github_raw = "https://raw.githubusercontent.com/", - github_api = "https://api.github.com/repos/", - github_desc = "//DESCRIPTION", - github_releases = "/releases", - github_tags = "/tags", - cached_desc = "DESCRIPTION__.txt" - )) - - kwb.utils::selectElements(urls, key) -} - -# githubRepo ------------------------------------------------------------------- -githubRepo <- function(github_user, name) -{ - paste(github_user, name, sep = "/") -} - -# packageInDestdir ------------------------------------------------------------- -#' @noMd -#' @noRd -#' @keywords internal -#' @importFrom kwb.utils safePath -packageInDestdir <- function(package, destdir, verbose = TRUE) -{ - files <- dirPackageZips(package, kwb.utils::safePath(destdir)) - - file_exists <- length(files) > 0L - - if (verbose && file_exists) { - message("Skipping already downloaded package '", package, "'") - } - - structure(file_exists, path = if (file_exists) kwb.utils::lastElement(files)) -} - -# remotes_github_pat ----------------------------------------------------------- -remotes_github_pat <- getFromNamespace("github_pat", "remotes") - -# remotes_parse_deps ----------------------------------------------------------- -remotes_parse_deps <- getFromNamespace("untar_description", "remotes") - -# remotes_read_dcf ------------------------------------------------------------- -remotes_read_dcf <- getFromNamespace("read_dcf", "remotes") - -# remotes_untar_description ---------------------------------------------------- -remotes_untar_description <- getFromNamespace("untar_description", "remotes") - # readLinesFromUrl ------------------------------------------------------------- readLinesFromUrl <- function(url, silent = TRUE) { From c48844521a304ca42b1d45e04e3bc18ea531b483 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 12 Apr 2024 11:16:52 +0200 Subject: [PATCH 33/90] Use kwb.utils::stopFormatted() --- R/install.R | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/R/install.R b/R/install.R index e662e1e..510f86d 100644 --- a/R/install.R +++ b/R/install.R @@ -56,15 +56,23 @@ updateKwbPackages <- function #' Get KWB Servername #' -getServername <- function() { +getServername <- function() +{ + variable <- "SERVERNAME" - servername <- Sys.getenv("SERVERNAME") + servername <- Sys.getenv(variable) - if(servername == "") { - stop(paste("Enviroment variable servername not defined!", - "Please define with Sys.setenv('SERVERNAME' = 'kwb-servername')", - collapse = "\n")) - } + if (servername == "") { + kwb.utils::stopFormatted( + paste( + "Enviroment variable '%s' not defined!", + "Please define with Sys.setenv(%s = 'kwb-servername')", + sep = "\n" + ), + variable, + variable + ) + } servername } From 37a853a4649f624a63fc59699e44511adf340ae5 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 12 Apr 2024 11:19:59 +0200 Subject: [PATCH 34/90] Consistently use clanStop(), old: stop_() --- R/detach.R | 2 +- R/downloadGitHubPackage.R | 2 +- R/loadDescriptionFromWeb.R | 6 +++--- R/utils.R | 5 ++--- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/R/detach.R b/R/detach.R index 70fdbb4..570b31b 100644 --- a/R/detach.R +++ b/R/detach.R @@ -176,5 +176,5 @@ systemPackages <- function(set_number = 1L) return(c(common, "grid", "splines", "tools")) } - stop("set_number must be one of 1, 2.") + cleanStop("set_number must be one of 1, 2.") } diff --git a/R/downloadGitHubPackage.R b/R/downloadGitHubPackage.R index d23f15c..2195a6e 100644 --- a/R/downloadGitHubPackage.R +++ b/R/downloadGitHubPackage.R @@ -58,7 +58,7 @@ findPackageFilename <- function(tarfile) desc_file <- grep("/DESCRIPTION$", paths, value = TRUE) if (length(desc_file) == 0L) { - stop("No DESCRIPTION found in ", tarfile) + cleanStop("No DESCRIPTION found in ", tarfile) } utils::untar(tarfile, files = desc_file, exdir = tempdir()) diff --git a/R/loadDescriptionFromWeb.R b/R/loadDescriptionFromWeb.R index 9a8cb92..93f354b 100644 --- a/R/loadDescriptionFromWeb.R +++ b/R/loadDescriptionFromWeb.R @@ -28,7 +28,7 @@ loadDescriptionFromWeb <- function( versions <- cache$versions[[name]] if (! is.null(versions)) { - stop("loadDescriptionFromWeb(): !is.null(versions) not implemented!") + cleanStop("loadDescriptionFromWeb(): !is.null(versions) not implemented!") #description <- select_version(cran_versions) } else { versions <- cranVersions(name, dbg = FALSE) @@ -39,7 +39,7 @@ loadDescriptionFromWeb <- function( version <- kwb.utils::defaultIfNA(version, rev(versions$version)[1L]) if (! version %in% versions$version) { - stop_(kwb.utils::noSuchElements(version, versions$version, "version")) + cleanStop(kwb.utils::noSuchElements(version, versions$version, "version")) } url <- versions$package_source_url[versions$version == version] @@ -60,7 +60,7 @@ loadDescriptionFromWeb <- function( shas <- kwb.utils::selectColumns(versions, c("version", "sha")) if (! version %in% shas$version) { - stop_(kwb.utils::noSuchElements(version, shas$version, "version")) + cleanStop(kwb.utils::noSuchElements(version, shas$version, "version")) } shas$sha[shas$version == version] diff --git a/R/utils.R b/R/utils.R index 924396c..f493189 100644 --- a/R/utils.R +++ b/R/utils.R @@ -10,9 +10,8 @@ readLinesFromUrl <- function(url, silent = TRUE) result } -# stop_ ------------------------------------------------------------------------ -stop_ <- function(...) +# cleanStop -------------------------------------------------------------------- +cleanStop <- function(...) { stop(..., call. = FALSE) } - From fb883deb4208585cb21dfde338d4031bf328b651 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 12 Apr 2024 12:46:20 +0200 Subject: [PATCH 35/90] Move cranVersions() to extra file --- R/cranVersions.R | 41 +++++++++++++++++++++++++++++++++++++++++ R/cran_helpers.R | 40 +++++++--------------------------------- 2 files changed, 48 insertions(+), 33 deletions(-) create mode 100644 R/cranVersions.R diff --git a/R/cranVersions.R b/R/cranVersions.R new file mode 100644 index 0000000..20c831f --- /dev/null +++ b/R/cranVersions.R @@ -0,0 +1,41 @@ +# cranVersions ----------------------------------------------------------------- + +#' @noMd +#' @noRd +#' @keywords internal +#' @importFrom kwb.utils removeColumns safeRowBind +cranVersions <- function(name, dbg = TRUE) +{ + current <- currentCranVersion(name) + + if (nrow(current) == 0L) { + + if (dbg) { + message(sprintf( + "Package '%s' does not seem to be on CRAN.", name + )) + } + + return(NULL) + } + + archived <- archivedCranVersions(name) + + current$package_source_url <- getUrl( + "cran_package_file", + package = name, + version = current$version + ) + + urlPattern <- getUrl( + "cran_archive_file", + package = name, + package_filename = "%s" + ) + + archived$package_source_url <- sprintf(urlPattern = archived$archive_file) + + result <- kwb.utils::safeRowBind(archived, current) + + kwb.utils::removeColumns(result, "archive_file") +} diff --git a/R/cran_helpers.R b/R/cran_helpers.R index 913760b..0715ac7 100644 --- a/R/cran_helpers.R +++ b/R/cran_helpers.R @@ -31,41 +31,15 @@ currentCranVersion <- function(name) ) } -# cranVersions ----------------------------------------------------------------- -#' @noMd -#' @noRd -#' @keywords internal -#' @importFrom kwb.utils removeColumns safeRowBind -cranVersions <- function(name, dbg = TRUE) +# getCranPackageDatabase ------------------------------------------------------- + +#' Get Matrix with Information on All CRAN Packages +#' +#' @export +getCranPackageDatabase <- function() { - current <- currentCranVersion(name) - - if (nrow(current) == 0L) { - - if (dbg) { - message(sprintf( - "Package '%s' does not seem to be on CRAN.", name - )) - } - - return(NULL) - } - - archived <- archivedCranVersions(name) - - current$package_source_url <- getUrl( - "cran_package_file", package = name, version = current$version - ) - - archived$package_source_url <- sprintf( - getUrl("cran_archive_file", package = name, package_filename = "%s"), - archived$archive_file - ) - - result <- kwb.utils::safeRowBind(archived, current) - - kwb.utils::removeColumns(result, "archive_file") + readRDS(file(getPath("cran_packages", package = "packages.rds"))) } # isOnCran --------------------------------------------------------------------- From c1fe536a4fd4ea4329bb659838273933307e9068 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 12 Apr 2024 14:23:16 +0200 Subject: [PATCH 36/90] Provide all used kwb.utils functions locally --- NAMESPACE | 14 +++-- R/allDeps.R | 2 +- R/archivedCranVersions.R | 8 +-- R/compareInstalledVersions.R | 3 +- R/copyBasePackages.R | 3 +- R/cranVersions.R | 10 ++-- R/cran_helpers.R | 5 +- R/downloadGitHubPackage.R | 5 +- R/downloadPackagesFromSnapshot.R | 2 +- R/githubPackageVersions.R | 41 ++++++------- R/helpers.R | 10 ++-- R/install.R | 32 +++------- R/install_github_packages.R | 3 +- R/installedDependencies.R | 5 +- R/loadDescriptionFromArchiveUrl.R | 2 +- R/loadDescriptionFromWeb.R | 9 ++- R/local_cran.R | 17 +++--- R/parsePackageDeps.R | 3 +- R/plot_package_versions.R | 6 +- R/readGithubPackageDescription.R | 9 +-- R/sankey_network.R | 15 ++--- R/utils.R | 99 +++++++++++++++++++++++++++++-- man/catIf.Rd | 16 ----- man/cranVersions.Rd | 11 ++++ 24 files changed, 187 insertions(+), 143 deletions(-) delete mode 100644 man/catIf.Rd create mode 100644 man/cranVersions.Rd diff --git a/NAMESPACE b/NAMESPACE index 65c016d..8d1c69f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -40,28 +40,32 @@ importFrom(gh,gh) importFrom(grDevices,rainbow) importFrom(graphics,arrows) importFrom(graphics,plot) -importFrom(kwb.utils,assignPackageObjects) importFrom(kwb.utils,catAndRun) -importFrom(kwb.utils,createDirectory) +importFrom(kwb.utils,catIf) importFrom(kwb.utils,defaultIfNA) +importFrom(kwb.utils,defaultIfNULL) +importFrom(kwb.utils,excludeNULL) importFrom(kwb.utils,extractSubstring) importFrom(kwb.utils,getAttribute) -importFrom(kwb.utils,hsRenameColumns) -importFrom(kwb.utils,moveColumnsToFront) +importFrom(kwb.utils,get_homedir) +importFrom(kwb.utils,hsRestoreAttributes) importFrom(kwb.utils,noFactorDataFrame) +importFrom(kwb.utils,noSuchElements) importFrom(kwb.utils,orderBy) importFrom(kwb.utils,rbindAll) importFrom(kwb.utils,removeColumns) importFrom(kwb.utils,resetRowNames) +importFrom(kwb.utils,runInDirectory) importFrom(kwb.utils,safePath) importFrom(kwb.utils,safeRowBind) -importFrom(kwb.utils,selectColumns) importFrom(kwb.utils,selectElements) +importFrom(kwb.utils,stopFormatted) importFrom(mvbutils,foodweb) importFrom(networkD3,sankeyNetwork) importFrom(remotes,github_remote) importFrom(remotes,install_github) importFrom(remotes,remote_download) +importFrom(utils,available.packages) importFrom(utils,download.file) importFrom(utils,download.packages) importFrom(utils,install.packages) diff --git a/R/allDeps.R b/R/allDeps.R index b5f2df4..bd152d2 100644 --- a/R/allDeps.R +++ b/R/allDeps.R @@ -31,7 +31,7 @@ allDeps <- function( allDeps(deps$name[i], deps$version[i], depth + 1L, max_depth) }) - child_deps <- kwb.utils::excludeNULL(child_deps, dbg = FALSE) + child_deps <- excludeNull(child_deps, dbg = FALSE) if (length(child_deps) > 0L) { deps <- rbind(deps, do.call(rbind, child_deps)) diff --git a/R/archivedCranVersions.R b/R/archivedCranVersions.R index c2aec80..b617f73 100644 --- a/R/archivedCranVersions.R +++ b/R/archivedCranVersions.R @@ -5,7 +5,6 @@ #' @param package package name #' @param ref_date default: NULL #' @export -#' @importFrom kwb.utils extractSubstring noFactorDataFrame #' @examples #' packages <- c("ggplot2", "swmmr", "kwb.hantush") #' archivedCranVersions(packages) @@ -21,7 +20,7 @@ archivedCranVersions <- function(package, ref_date = NULL) src <- readLinesFromUrl(getUrl("cran_archive", package = package)) if (is.null(src)) { - return(kwb.utils::noFactorDataFrame( + return(noFactorDataFrame( package = character(0L), version = character(0L), date = as.Date(character(0L)), @@ -34,7 +33,7 @@ archivedCranVersions <- function(package, ref_date = NULL) "href=\"(%s_(.*)\\.tar\\.gz)\".*(\\d{4}-\\d{2}-\\d{2}) ", package ) - versions <- cbind(package = package, kwb.utils::extractSubstring( + versions <- cbind(package = package, extractSubstring( pattern = pattern, x = grep(pattern, src, value = TRUE), index = c( @@ -59,12 +58,11 @@ archivedCranVersions <- function(package, ref_date = NULL) #' @noRd #' @keywords internal #' @importFrom utils tail -#' @importFrom kwb.utils resetRowNames getLastVersionBefore <- function(version_dates, ref_date) { X = unname(split(version_dates, version_dates$package)) last_before <- function(x) utils::tail(x[x$date <= ref_date, ], 1L) - kwb.utils::resetRowNames(do.call(rbind, lapply(X, last_before))) + resetRowNames(do.call(rbind, lapply(X, last_before))) } diff --git a/R/compareInstalledVersions.R b/R/compareInstalledVersions.R index bc3116e..a2f897d 100644 --- a/R/compareInstalledVersions.R +++ b/R/compareInstalledVersions.R @@ -10,12 +10,11 @@ #' different in the two libraries) #' @export #' @importFrom utils installed.packages -#' @importFrom kwb.utils resetRowNames compareInstalledVersions <- function(lib1, lib2) { installed_versions <- function(x) { versions <- utils::installed.packages(path.expand(x)) - kwb.utils::resetRowNames(kwb.utils::noFactorDataFrame( + resetRowNames(noFactorDataFrame( name = rownames(versions), version = versions[, "Version", drop = FALSE] )) diff --git a/R/copyBasePackages.R b/R/copyBasePackages.R index 4e56e63..1ba9503 100644 --- a/R/copyBasePackages.R +++ b/R/copyBasePackages.R @@ -9,14 +9,13 @@ #' @param packages vector of names of packages to be copied #' @export #' @importFrom utils tail -#' @importFrom kwb.utils catAndRun copyBasePackages <- function( target_lib, set_number = 2L, system_lib = utils::tail(.libPaths(), 1L), packages = systemPackages(set_number)) { - kwb.utils::catAndRun(paste("Copying base R packages to", target_lib), { + catAndRun(paste("Copying base R packages to", target_lib), { file.copy( from = file.path(system_lib, packages), to = target_lib, diff --git a/R/cranVersions.R b/R/cranVersions.R index 20c831f..d22ecea 100644 --- a/R/cranVersions.R +++ b/R/cranVersions.R @@ -1,9 +1,7 @@ # cranVersions ----------------------------------------------------------------- -#' @noMd -#' @noRd -#' @keywords internal -#' @importFrom kwb.utils removeColumns safeRowBind +#' Get versions of CRAN packages +#' cranVersions <- function(name, dbg = TRUE) { current <- currentCranVersion(name) @@ -35,7 +33,7 @@ cranVersions <- function(name, dbg = TRUE) archived$package_source_url <- sprintf(urlPattern = archived$archive_file) - result <- kwb.utils::safeRowBind(archived, current) + result <- safeRowBind(archived, current) - kwb.utils::removeColumns(result, "archive_file") + removeColumns(result, "archive_file") } diff --git a/R/cran_helpers.R b/R/cran_helpers.R index 0715ac7..3aaff91 100644 --- a/R/cran_helpers.R +++ b/R/cran_helpers.R @@ -3,7 +3,6 @@ #' @noMd #' @noRd #' @keywords internal -#' @importFrom kwb.utils noFactorDataFrame currentCranVersion <- function(name) { src <- readLinesFromUrl(getUrl("cran_package", package = name)) @@ -11,7 +10,7 @@ currentCranVersion <- function(name) was_removed_pattern <- "was removed from the CRAN repository" if (is.null(src) || any(grepl(was_removed_pattern, src))) { - return(kwb.utils::noFactorDataFrame( + return(noFactorDataFrame( package = character(0L), version = character(0L), date = as.Date(character(0L)), @@ -23,7 +22,7 @@ currentCranVersion <- function(name) gsub("|", "", src[grep(sprintf("%s:", x), src) + 1L]) } - kwb.utils::noFactorDataFrame( + noFactorDataFrame( package = name, version = extract("Version"), date = as.Date(extract("Published")), diff --git a/R/downloadGitHubPackage.R b/R/downloadGitHubPackage.R index 2195a6e..ce22bd9 100644 --- a/R/downloadGitHubPackage.R +++ b/R/downloadGitHubPackage.R @@ -8,7 +8,6 @@ #' @return path to downloaded file in the \code{destdir} folder with attribute #' "origin" pointing to the original file in \code{tempdir()}. #' @export -#' @importFrom kwb.utils getAttribute #' @importFrom remotes github_remote remote_download downloadGitHubPackage <- function(repo, destdir = "~/../Downloads") { @@ -19,8 +18,8 @@ downloadGitHubPackage <- function(repo, destdir = "~/../Downloads") file_downloaded <- packageInDestdir(package, destdir) if (file_downloaded) { - - file <- kwb.utils::getAttribute(file_downloaded, "path") + + file <- getAttribute(file_downloaded, "path") origin <- character(0) } else{ diff --git a/R/downloadPackagesFromSnapshot.R b/R/downloadPackagesFromSnapshot.R index d55d960..068cc74 100644 --- a/R/downloadPackagesFromSnapshot.R +++ b/R/downloadPackagesFromSnapshot.R @@ -41,7 +41,7 @@ downloadPackagesFromSnapshot <- function( if (! packageInDestdir(package, destdir)) { - kwb.utils::catAndRun( + catAndRun( sprintf("Downloading %s package %d/%d: %s", type, i, n, package), utils::download.packages( package, diff --git a/R/githubPackageVersions.R b/R/githubPackageVersions.R index 619ee18..cba8e62 100644 --- a/R/githubPackageVersions.R +++ b/R/githubPackageVersions.R @@ -6,7 +6,6 @@ #' #' @return data frame with one row per available version #' @export -#' @importFrom kwb.utils moveColumnsToFront removeColumns selectColumns orderBy #' @examples #' githubVersions("kwb.utils") githubVersions <- function(name, github_user = "KWB-R") @@ -40,9 +39,6 @@ githubPackageVersions <- function( message("Reading ", repo) } - # Shortcut - get <- kwb.utils::selectColumns - # Column sets key_columns <- c("package", "version", "date") extra_columns <- c("sha", "repo", "tag", "release") @@ -57,7 +53,7 @@ githubPackageVersions <- function( # Read the description files of the commits referred to by the releases descriptions <- lapply( - get(result, "sha"), + selectColumns(result, "sha"), readGithubPackageDescription, repo = repo, auth_token = auth_token @@ -67,32 +63,28 @@ githubPackageVersions <- function( result$remote <- sprintf("github::%s@%s", result$repo, result$tag) - result$version <- sapply(descriptions, kwb.utils::selectElements, "version") + result$version <- sapply(descriptions, selectElements, "version") if (reduced) { - result <- kwb.utils::removeColumns(result, extra_columns) + result <- removeColumns(result, extra_columns) } - result <- kwb.utils::moveColumnsToFront(result, key_columns) + result <- moveColumnsToFront(result, key_columns) result <- result[! is.na(result$date) & ! is.na(result$version), ] - kwb.utils::orderBy(result, "date") + orderBy(result, "date") } # getGithubReleaseInfo --------------------------------------------------------- #' @noMd #' @noRd #' @keywords internal -#' @importFrom kwb.utils noFactorDataFrame removeColumns selectElements #' @importFrom gh gh getGithubReleaseInfo <- function( repo, reduced = TRUE, auth_token = remotes_github_pat() ) { - # Shortcut - get <- kwb.utils::selectElements - get_endpoint <- function(endpoint) { stopifnot(length(endpoint) == 1L) gh::gh(endpoint, .token = auth_token) @@ -105,20 +97,23 @@ getGithubReleaseInfo <- function( return(NULL) } - tag_info <- kwb.utils::noFactorDataFrame( - tag = sapply(tags, get, "name"), - sha = sapply(lapply(tags, get, "commit"), get, "sha") + tag_info <- noFactorDataFrame( + tag = sapply(tags, selectElements, "name"), + sha = sapply(lapply(tags, selectElements, "commit"), selectElements, "sha") ) release_info <- if (length(releases)) { - kwb.utils::noFactorDataFrame( - tag = sapply(releases, get, "tag_name"), - date = as.Date(sapply(releases, get, "published_at")), - release = sapply(releases, get, "name"), - author = sapply(releases, function(x) get(get(x, "author"), "login")) + noFactorDataFrame( + tag = sapply(releases, selectElements, "tag_name"), + date = as.Date(sapply(releases, selectElements, "published_at")), + release = sapply(releases, selectElements, "name"), + author = sapply( + releases, + function(x) selectElements(selectElements(x, "author"), "login") + ) ) } else { - kwb.utils::noFactorDataFrame( + noFactorDataFrame( tag = character(0L), date = as.Date(character(0L)), release = character(0L), @@ -136,6 +131,6 @@ getGithubReleaseInfo <- function( return(result) } - kwb.utils::removeColumns(result, "sha") + removeColumns(result, "sha") } diff --git a/R/helpers.R b/R/helpers.R index a540fdc..17cecd0 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -8,10 +8,9 @@ dirPackageZips <- function(package, path) #' @noMd #' @noRd #' @keywords internal -#' @importFrom kwb.utils selectElements getUrl <- function(key, ...) { - urls <- kwb.utils::resolve(..., x = list( + urls <- resolve(..., x = list( cran = "https://cran.r-project.org", cran_rstudio = "https://cran.rstudio.org", mran_snapshot = "https://mran.microsoft.com/snapshot/", @@ -29,7 +28,7 @@ getUrl <- function(key, ...) cached_desc = "DESCRIPTION__.txt" )) - kwb.utils::selectElements(urls, key) + selectElements(urls, key) } # githubRepo ------------------------------------------------------------------- @@ -42,10 +41,9 @@ githubRepo <- function(github_user, name) #' @noMd #' @noRd #' @keywords internal -#' @importFrom kwb.utils safePath packageInDestdir <- function(package, destdir, verbose = TRUE) { - files <- dirPackageZips(package, kwb.utils::safePath(destdir)) + files <- dirPackageZips(package, safePath(destdir)) file_exists <- length(files) > 0L @@ -53,6 +51,6 @@ packageInDestdir <- function(package, destdir, verbose = TRUE) message("Skipping already downloaded package '", package, "'") } - structure(file_exists, path = if (file_exists) kwb.utils::lastElement(files)) + structure(file_exists, path = if (file_exists) lastElement(files)) } diff --git a/R/install.R b/R/install.R index 510f86d..aa85910 100644 --- a/R/install.R +++ b/R/install.R @@ -1,15 +1,3 @@ -# catIf ------------------------------------------------------------------------ - -#' Copy of kwb.utils::catIf -#' -#' @param condition see \code{kwb.utils::catIf} -#' @param \dots see \code{kwb.utils::catIf} -#' -catIf <- function(condition, ...) -{ - if (condition) cat(...) -} - # updateKwbPackages ------------------------------------------------------------ #' Update or Install KWB-Packages @@ -63,7 +51,7 @@ getServername <- function() servername <- Sys.getenv(variable) if (servername == "") { - kwb.utils::stopFormatted( + stopFormatted( paste( "Enviroment variable '%s' not defined!", "Please define with Sys.setenv(%s = 'kwb-servername')", @@ -133,18 +121,15 @@ shallBeInstalled <- function(packageName, skip) #' @noRd #' @keywords internal #' @importFrom utils install.packages -#' @importFrom kwb.utils assignPackageObjects #' @importFrom remotes install_github installPackage <- function( packageName, package.dir = defaultPackageDir(), quiet = TRUE, type = NULL, dbg = FALSE ) { - if (FALSE) { - kwb.utils::assignPackageObjects("kwb.package") - package.dir = defaultPackageDir(); quiet = TRUE; type = NULL; dbg = FALSE - } - + #kwb.utils::assignPackageObjects("kwb.package") + #package.dir = defaultPackageDir(); quiet = TRUE; type = NULL; dbg = FALSE + if (isKwbPackage(packageName)) { packageFile <- getPackageFilesToInstall( @@ -218,17 +203,14 @@ installPackage <- function( #' the available package files #' #' @export -#' @importFrom kwb.utils assignPackageObjects getPackageFilesToInstall <- function( package.dir = defaultPackageDir(), packageNames = NULL, filepattern = "", full.names = TRUE, dbg = FALSE, warn = TRUE ) { - if (FALSE) { - kwb.utils::assignPackageObjects("kwb.package") - package.dir = defaultPackageDir(); packageNames = NULL; filepattern = ""; - full.names = TRUE; dbg = TRUE; warn = TRUE - } + #kwb.utils::assignPackageObjects("kwb.package") + #package.dir = defaultPackageDir(); packageNames = NULL; filepattern = ""; + #full.names = TRUE; dbg = TRUE; warn = TRUE catIf( dbg, "Looking for available package files in '", package.dir, "'...\n" diff --git a/R/install_github_packages.R b/R/install_github_packages.R index 6a988c0..f869830 100644 --- a/R/install_github_packages.R +++ b/R/install_github_packages.R @@ -30,7 +30,6 @@ getRVersionMajorMinor <- function() #' @export #' @importFrom withr with_libpaths #' @importFrom remotes install_github -#' @importFrom kwb.utils createDirectory #' @examples #' \dontrun{ #' remotes::install_github("kwb-r/pkgmeta") @@ -57,7 +56,7 @@ installGithubPackages <- function( auth_token = Sys.getenv("GITHUB_PAT") ) { - withr::with_libpaths(kwb.utils::createDirectory(lib, dbg = FALSE), code = { + withr::with_libpaths(createDirectory(lib, dbg = FALSE), code = { install.packages("remotes", repos = getPath("cran_rstudio")) diff --git a/R/installedDependencies.R b/R/installedDependencies.R index b18cd6d..a4b816a 100644 --- a/R/installedDependencies.R +++ b/R/installedDependencies.R @@ -6,11 +6,8 @@ #' @param recursive whether to look recursively for dependencies or only for the #' direct dependencies of \code{package}. Passed to #' \code{\link{packageDependencies}}, defaults to \code{TRUE} -#' @importFrom kwb.utils selectElements #' @importFrom utils installed.packages #' @export -#' @importFrom kwb.utils selectElements -#' @importFrom utils installed.packages #' @examples #' installedDependencies(package = "kwb.package") #' installedDependencies(package = "kwb.package", recursive = FALSE) @@ -19,7 +16,7 @@ installedDependencies <- function(package, recursive = TRUE) #kwb.utils::assignPackageObjects("kwb.package");recursive=TRUE # What other packages does the package depend on? - dependencies <- sort(kwb.utils::selectElements( + dependencies <- sort(selectElements( packageDependencies(package, recursive = recursive), package )) diff --git a/R/loadDescriptionFromArchiveUrl.R b/R/loadDescriptionFromArchiveUrl.R index d516e37..56cddee 100644 --- a/R/loadDescriptionFromArchiveUrl.R +++ b/R/loadDescriptionFromArchiveUrl.R @@ -35,7 +35,7 @@ untarDescriptionFromUrl <- function(url, target = NULL, destdir = tempdir()) on.exit(unlink(dir, recursive = TRUE), add = TRUE) # Keep only the DESCRIPTION in a .tar.gz.DESCRIPTION file - target <- kwb.utils::defaultIfNULL(target, pathDescription(tarname, destdir)) + target <- defaultIfNull(target, pathDescription(tarname, destdir)) file.copy(target_tmp, target) diff --git a/R/loadDescriptionFromWeb.R b/R/loadDescriptionFromWeb.R index 93f354b..db90d29 100644 --- a/R/loadDescriptionFromWeb.R +++ b/R/loadDescriptionFromWeb.R @@ -2,7 +2,6 @@ #' @noMd #' @noRd #' @keywords internal -#' @importFrom kwb.utils defaultIfNA selectColumns #' @importFrom gh gh loadDescriptionFromWeb <- function( name, @@ -36,10 +35,10 @@ loadDescriptionFromWeb <- function( if (! is.null(versions)) { - version <- kwb.utils::defaultIfNA(version, rev(versions$version)[1L]) + version <- defaultIfNa(version, rev(versions$version)[1L]) if (! version %in% versions$version) { - cleanStop(kwb.utils::noSuchElements(version, versions$version, "version")) + cleanStop(noSuchElements(version, versions$version, "version")) } url <- versions$package_source_url[versions$version == version] @@ -57,10 +56,10 @@ loadDescriptionFromWeb <- function( } else { versions <- githubPackageVersions(repo, reduced = FALSE) - shas <- kwb.utils::selectColumns(versions, c("version", "sha")) + shas <- selectColumns(versions, c("version", "sha")) if (! version %in% shas$version) { - cleanStop(kwb.utils::noSuchElements(version, shas$version, "version")) + cleanStop(noSuchElements(version, shas$version, "version")) } shas$sha[shas$version == version] diff --git a/R/local_cran.R b/R/local_cran.R index 43d631e..3143de9 100644 --- a/R/local_cran.R +++ b/R/local_cran.R @@ -62,7 +62,7 @@ setOptionsForPackrat <- function() if (! "local" %in% names(repos)) { - options(repos = kwb.utils::hsRestoreAttributes( + options(repos = restoreAttributes( x = c(repos, local = paste0("file://", defaultLocalCRAN())), attribs = attributes(repos) )) @@ -93,17 +93,17 @@ provideInLocalCRAN <- function( package, rebuild = TRUE, local_cran = defaultLocalCRAN(drive_letter = TRUE) ) { - paths <- kwb.utils::resolve(list( + paths <- resolve(list( packages_1 = "/Documents/R-Development/RPackages", packages_2 = "/Desktop/R_Development/RPackages", contrib = "/src/contrib", - home = kwb.utils::get_homedir(), + home = getHomedir(), local_cran = local_cran )) - package_dir <- kwb.utils::defaultIfNULL(paths$packages_1, paths$packages_2) + package_dir <- defaultIfNull(paths$packages_1, paths$packages_2) - package_dir <- kwb.utils::safePath(package_dir, package) + package_dir <- safePath(package_dir, package) # Add "Repository: moby" to the DESCRIPTION file if required desc_file <- file.path(package_dir, "DESCRIPTION") @@ -122,7 +122,7 @@ provideInLocalCRAN <- function( # Go to the package directory and build the package if (isTRUE(rebuild)) { - kwb.utils::runInDirectory( + runInDirectory( target.dir = dirname(package_dir), FUN = system, command = paste("R CMD build", package) @@ -134,13 +134,12 @@ provideInLocalCRAN <- function( files <- dir(dirname(package_dir), pattern, full.names = TRUE) - file.copy(files, kwb.utils::safePath(paths$contrib)) + file.copy(files, safePath(paths$contrib)) # Write the PACKAGE files tools::write_PACKAGES(paths$contrib, type = "source") - for (path in getBinaryPaths(kwb.utils::safePath(paths$local_cran))) { - + for (path in getBinaryPaths(safePath(paths$local_cran))) { tools::write_PACKAGES(path) } } diff --git a/R/parsePackageDeps.R b/R/parsePackageDeps.R index e34e98c..1a06537 100644 --- a/R/parsePackageDeps.R +++ b/R/parsePackageDeps.R @@ -2,10 +2,9 @@ #' @noMd #' @noRd #' @keywords internal -#' @importFrom kwb.utils rbindAll parsePackageDeps <- function(pkg, dependencies = NA) { deps <- tolower(remotes::standardise_dep(dependencies)) parsed <- lapply(pkg[intersect(deps, names(pkg))], remotes_parse_deps) - kwb.utils::rbindAll(parsed, nameColumn = "type") + rbindAll(parsed, nameColumn = "type") } diff --git a/R/plot_package_versions.R b/R/plot_package_versions.R index 5cde451..9741c7e 100644 --- a/R/plot_package_versions.R +++ b/R/plot_package_versions.R @@ -16,11 +16,11 @@ plotPackageVersions <- function( on.exit(graphics::par(old_par)) versions$r <- map_to_range( - x = as.integer(kwb.utils::selectColumns(versions, "date")), + x = as.integer(selectColumns(versions, "date")), y_range = r_range ) - X <- split(versions, kwb.utils::selectColumns(versions, "package")) + X <- split(versions, selectColumns(versions, "package")) phis <- seq_rad_len(length(X)) @@ -30,7 +30,7 @@ plotPackageVersions <- function( # Draw circles around the centre draw_circles(r = r_range, n_corners = length(X)) - dphi <- kwb.utils::defaultIfNULL(dphi, seq_rad_len(3 * length(X))[2L]) + dphi <- defaultIfNull(dphi, seq_rad_len(3 * length(X))[2L]) for (i in seq_along(X)) { x <- X[[i]] diff --git a/R/readGithubPackageDescription.R b/R/readGithubPackageDescription.R index 0087b36..045249b 100644 --- a/R/readGithubPackageDescription.R +++ b/R/readGithubPackageDescription.R @@ -3,7 +3,6 @@ #' @noRd #' @keywords internal #' @importFrom gh gh -#' @importFrom kwb.utils selectElements readGithubPackageDescription <- function( repo, sha, auth_token = remotes_github_pat(), destdir = tempdir() ) @@ -19,16 +18,18 @@ readGithubPackageDescription <- function( file <- tempfile() on.exit(unlink(file)) - writeLines(kwb.utils::selectElements(content, "message"), file) + writeLines(selectElements(content, "message"), file) # Read local DESCRIPTION file desc <- remotes_read_dcf(file) # Use package name and version to generate a name for the cached # DESCRIPTION file. Copy the DESCRITPION file to a file of that name. - get <- kwb.utils::createAccessor(desc) + file.copy(file, file.path(destdir, getUrl( - "cached_desc", package = get("Package"), version = get("Version") + "cached_desc", + package = selectColumns("Package"), + version = selectColumns("Version") ))) # See remotes:::load_pkg_description diff --git a/R/sankey_network.R b/R/sankey_network.R index d6799ef..62f8be9 100644 --- a/R/sankey_network.R +++ b/R/sankey_network.R @@ -89,7 +89,6 @@ exampleLinksAndNodes <- function() #' (data frame with column \code{name}) #' #' @export -#' @importFrom kwb.utils defaultIfNA selectElements #' @examples #' kwb.package:::toLinksAndNodes(list( #' source = c("s1", "s1"), target = c("t1", "t2") @@ -97,10 +96,10 @@ exampleLinksAndNodes <- function() #' toLinksAndNodes <- function(links) { - selection <- kwb.utils::selectElements(links, "source") + selection <- selectElements(links, "source") - sources <- as.character(kwb.utils::defaultIfNA(selection, "")) - targets <- as.character(kwb.utils::selectElements(links, "target")) + sources <- as.character(defaultIfNa(selection, "")) + targets <- as.character(selectElements(links, "target")) nodes <- data.frame(name = unique(c(sources, targets))) @@ -117,7 +116,6 @@ toLinksAndNodes <- function(links) #' @noMd #' @noRd #' @keywords internal -#' @importFrom kwb.utils hsRenameColumns toSourceTarget <- function(x) { x$target <- paste0(x$source, "@", x$f) @@ -131,7 +129,7 @@ toSourceTarget <- function(x) lastcaller[L] <- x$target[i] } - kwb.utils::hsRenameColumns(x[, c("caller", "target")], list(caller = "source")) + renameColumns(x[, c("caller", "target")], list(caller = "source")) } # includeExclude --------------------------------------------------------------- @@ -153,13 +151,10 @@ includeExclude <- function(x, exclude = NULL) #' @noMd #' @noRd #' @keywords internal -#' @importFrom kwb.utils rbindAll relationMatrixToSourceTarget <- function(x) { - kwb.utils::rbindAll(lapply(rownames(x), function(rowname) { - + rbindAll(lapply(rownames(x), function(rowname) { if (length(names.x <- names(which(x[rowname, ] == 1)))) { - data.frame(source = rowname, target = names.x) } })) diff --git a/R/utils.R b/R/utils.R index f493189..3b12eef 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,3 +1,62 @@ +# catAndRun -------------------------------------------------------------------- + +#' @importFrom kwb.utils catAndRun +catAndRun <- kwb.utils::catAndRun + +# catIf ------------------------------------------------------------------------ + +#' @importFrom kwb.utils catIf +catIf <- kwb.utils::catIf + +# cleanStop -------------------------------------------------------------------- +cleanStop <- function(...) +{ + stop(..., call. = FALSE) +} + +# defaultIfNa ------------------------------------------------------------------ +#' @importFrom kwb.utils defaultIfNA +defaultIfNa <- kwb.utils::defaultIfNA + +# defaultIfNull ---------------------------------------------------------------- +#' @importFrom kwb.utils defaultIfNULL +defaultIfNull <- kwb.utils::defaultIfNULL + +# excludeNull ------------------------------------------------------------------ +#' @importFrom kwb.utils excludeNULL +excludeNull <- kwb.utils::excludeNULL + +# extractSubstring ------------------------------------------------------------- +#' @importFrom kwb.utils extractSubstring +extractSubstring <- kwb.utils::extractSubstring + +# getAttribute ----------------------------------------------------------------- +#' @importFrom kwb.utils getAttribute +getAttribute <- kwb.utils::getAttribute + +# getHomedir ------------------------------------------------------------------- +#' @importFrom kwb.utils get_homedir +getHomedir <- kwb.utils::get_homedir + +# moveColumnsToFront ----------------------------------------------------------- +moveColumnsToFront <- kwb.utils::moveColumnsToFront + +# noFactorDataFrame ------------------------------------------------------------ +#' @importFrom kwb.utils noFactorDataFrame +noFactorDataFrame <- kwb.utils::noFactorDataFrame + +# noSuchElements --------------------------------------------------------------- +#' @importFrom kwb.utils noSuchElements +noSuchElements <- kwb.utils::noSuchElements + +# orderBy ---------------------------------------------------------------------- +#' @importFrom kwb.utils orderBy +orderBy <- kwb.utils::orderBy + +# rbindAll --------------------------------------------------------------------- +#' @importFrom kwb.utils rbindAll +rbindAll <- kwb.utils::rbindAll + # readLinesFromUrl ------------------------------------------------------------- readLinesFromUrl <- function(url, silent = TRUE) { @@ -10,8 +69,38 @@ readLinesFromUrl <- function(url, silent = TRUE) result } -# cleanStop -------------------------------------------------------------------- -cleanStop <- function(...) -{ - stop(..., call. = FALSE) -} +# removeColumns ---------------------------------------------------------------- +#' @importFrom kwb.utils removeColumns +removeColumns <- kwb.utils::removeColumns + +# resetRowNames ---------------------------------------------------------------- +#' @importFrom kwb.utils resetRowNames +resetRowNames <- kwb.utils::resetRowNames + +# restoreAttributes ------------------------------------------------------------ +#' @importFrom kwb.utils hsRestoreAttributes +restoreAttributes <- kwb.utils::hsRestoreAttributes + +# runInDirectory --------------------------------------------------------------- +#' @importFrom kwb.utils runInDirectory +kwb.utils::runInDirectory + +# safePath --------------------------------------------------------------------- +#' @importFrom kwb.utils safePath +kwb.utils::safePath + +# safeRowBind ------------------------------------------------------------------ +#' @importFrom kwb.utils safeRowBind +safeRowBind <- kwb.utils::safeRowBind + +# selectElements --------------------------------------------------------------- +#' @importFrom kwb.utils selectElements +selectColumns <- kwb.utils::selectColumns + +# stopFormatted ---------------------------------------------------------------- +#' @importFrom kwb.utils stopFormatted +stopFormatted <- kwb.utils::stopFormatted + +# removeColumns ---------------------------------------------------------------- +#' @importFrom kwb.utils removeColumns +removeColumns <- kwb.utils::removeColumns diff --git a/man/catIf.Rd b/man/catIf.Rd deleted file mode 100644 index d507f1f..0000000 --- a/man/catIf.Rd +++ /dev/null @@ -1,16 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/install.R -\name{catIf} -\alias{catIf} -\title{Copy of kwb.utils::catIf} -\usage{ -catIf(condition, ...) -} -\arguments{ -\item{condition}{see \code{kwb.utils::catIf}} - -\item{\dots}{see \code{kwb.utils::catIf}} -} -\description{ -Copy of kwb.utils::catIf -} diff --git a/man/cranVersions.Rd b/man/cranVersions.Rd new file mode 100644 index 0000000..d56a251 --- /dev/null +++ b/man/cranVersions.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/cranVersions.R +\name{cranVersions} +\alias{cranVersions} +\title{Get versions of CRAN packages} +\usage{ +cranVersions(name, dbg = TRUE) +} +\description{ +Get versions of CRAN packages +} From 6ded85e044265b5177a1be0819dc4e85fa3cc766 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 12 Apr 2024 14:28:18 +0200 Subject: [PATCH 37/90] Update project settings --- kwb.package.Rproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kwb.package.Rproj b/kwb.package.Rproj index 1788e68..eaa6b81 100644 --- a/kwb.package.Rproj +++ b/kwb.package.Rproj @@ -15,4 +15,4 @@ LaTeX: pdfLaTeX BuildType: Package PackageUseDevtools: Yes PackageInstallArgs: --no-multiarch --with-keep.source -PackageRoxygenize: rd,collate,namespace,vignette +PackageRoxygenize: rd,collate,namespace From ff0f01df9197f9de5f5cf227286200636ab4036c Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 12 Apr 2024 14:30:05 +0200 Subject: [PATCH 38/90] Add/export getCranPackageDatabase() --- NAMESPACE | 1 + R/cran_helpers.R | 1 - man/getCranPackageDatabase.Rd | 11 +++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 man/getCranPackageDatabase.Rd diff --git a/NAMESPACE b/NAMESPACE index 8d1c69f..1636663 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -13,6 +13,7 @@ export(drawDependencies) export(drawLink) export(equidistantAngles) export(exampleLinksAndNodes) +export(getCranPackageDatabase) export(getPackageFilesToInstall) export(getRVersionMajorMinor) export(githubVersions) diff --git a/R/cran_helpers.R b/R/cran_helpers.R index 3aaff91..c777886 100644 --- a/R/cran_helpers.R +++ b/R/cran_helpers.R @@ -30,7 +30,6 @@ currentCranVersion <- function(name) ) } - # getCranPackageDatabase ------------------------------------------------------- #' Get Matrix with Information on All CRAN Packages diff --git a/man/getCranPackageDatabase.Rd b/man/getCranPackageDatabase.Rd new file mode 100644 index 0000000..41a062e --- /dev/null +++ b/man/getCranPackageDatabase.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/cran_helpers.R +\name{getCranPackageDatabase} +\alias{getCranPackageDatabase} +\title{Get Matrix with Information on All CRAN Packages} +\usage{ +getCranPackageDatabase() +} +\description{ +Get Matrix with Information on All CRAN Packages +} From e5a304f707ae3b8095f0d2e82682af6b30763ab3 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 12 Apr 2024 15:39:29 +0200 Subject: [PATCH 39/90] Fix :bug:: replace getPath() with getUrl() --- R/cran_helpers.R | 2 +- R/downloadPackagesFromSnapshot.R | 2 +- R/install_github_packages.R | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/R/cran_helpers.R b/R/cran_helpers.R index c777886..54ca3b7 100644 --- a/R/cran_helpers.R +++ b/R/cran_helpers.R @@ -37,7 +37,7 @@ currentCranVersion <- function(name) #' @export getCranPackageDatabase <- function() { - readRDS(file(getPath("cran_packages", package = "packages.rds"))) + readRDS(file(getUrl("cran_packages", package = "packages.rds"))) } # isOnCran --------------------------------------------------------------------- diff --git a/R/downloadPackagesFromSnapshot.R b/R/downloadPackagesFromSnapshot.R index 068cc74..86b1b5c 100644 --- a/R/downloadPackagesFromSnapshot.R +++ b/R/downloadPackagesFromSnapshot.R @@ -24,7 +24,7 @@ downloadPackagesFromSnapshot <- function( return(character(0)) } - repos <- getPath("mran_snapshot", date = snapshot_date) + repos <- getUrl("mran_snapshot", date = snapshot_date) if (is.null(destdir)) { diff --git a/R/install_github_packages.R b/R/install_github_packages.R index f869830..d8b3642 100644 --- a/R/install_github_packages.R +++ b/R/install_github_packages.R @@ -58,7 +58,7 @@ installGithubPackages <- function( { withr::with_libpaths(createDirectory(lib, dbg = FALSE), code = { - install.packages("remotes", repos = getPath("cran_rstudio")) + install.packages("remotes", repos = getUrl("cran_rstudio")) for (repo in repos) { From 9e7654909de67e86aba6a576316156669ccd2c12 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 12 Apr 2024 15:40:07 +0200 Subject: [PATCH 40/90] Fix and export cranVersions() --- R/cranVersions.R | 6 +++++- man/cranVersions.Rd | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/R/cranVersions.R b/R/cranVersions.R index d22ecea..624c41a 100644 --- a/R/cranVersions.R +++ b/R/cranVersions.R @@ -2,6 +2,10 @@ #' Get versions of CRAN packages #' +#' @param name package name +#' @param dbg logical indicating whether or not to show debug messages. Default: +#' \code{TRUE} +#' @export cranVersions <- function(name, dbg = TRUE) { current <- currentCranVersion(name) @@ -31,7 +35,7 @@ cranVersions <- function(name, dbg = TRUE) package_filename = "%s" ) - archived$package_source_url <- sprintf(urlPattern = archived$archive_file) + archived$package_source_url <- sprintf(urlPattern, archived$archive_file) result <- safeRowBind(archived, current) diff --git a/man/cranVersions.Rd b/man/cranVersions.Rd index d56a251..674e9a8 100644 --- a/man/cranVersions.Rd +++ b/man/cranVersions.Rd @@ -6,6 +6,12 @@ \usage{ cranVersions(name, dbg = TRUE) } +\arguments{ +\item{name}{package name} + +\item{dbg}{logical indicating whether or not to show debug messages. Default: +\code{TRUE}} +} \description{ Get versions of CRAN packages } From 1df45251fe8855daba84fc64411c5156a9293137 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 12 Apr 2024 15:57:46 +0200 Subject: [PATCH 41/90] Add missing "shortcuts" to kwb.utils functions --- NAMESPACE | 5 +++++ R/utils.R | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/NAMESPACE b/NAMESPACE index 1636663..1095f5f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,6 +5,7 @@ export(anglesToPoints) export(archivedCranVersions) export(compareInstalledVersions) export(copyBasePackages) +export(cranVersions) export(detachAllNonSystemPackages) export(detachRecursively) export(downloadGitHubPackage) @@ -43,6 +44,7 @@ importFrom(graphics,arrows) importFrom(graphics,plot) importFrom(kwb.utils,catAndRun) importFrom(kwb.utils,catIf) +importFrom(kwb.utils,createDirectory) importFrom(kwb.utils,defaultIfNA) importFrom(kwb.utils,defaultIfNULL) importFrom(kwb.utils,excludeNULL) @@ -50,12 +52,15 @@ importFrom(kwb.utils,extractSubstring) importFrom(kwb.utils,getAttribute) importFrom(kwb.utils,get_homedir) importFrom(kwb.utils,hsRestoreAttributes) +importFrom(kwb.utils,lastElement) importFrom(kwb.utils,noFactorDataFrame) importFrom(kwb.utils,noSuchElements) importFrom(kwb.utils,orderBy) importFrom(kwb.utils,rbindAll) importFrom(kwb.utils,removeColumns) +importFrom(kwb.utils,renameColumns) importFrom(kwb.utils,resetRowNames) +importFrom(kwb.utils,resolve) importFrom(kwb.utils,runInDirectory) importFrom(kwb.utils,safePath) importFrom(kwb.utils,safeRowBind) diff --git a/R/utils.R b/R/utils.R index 3b12eef..49aed24 100644 --- a/R/utils.R +++ b/R/utils.R @@ -14,6 +14,10 @@ cleanStop <- function(...) stop(..., call. = FALSE) } +# createDirectory -------------------------------------------------------------- +#' @importFrom kwb.utils createDirectory +createDirectory <- kwb.utils::createDirectory + # defaultIfNa ------------------------------------------------------------------ #' @importFrom kwb.utils defaultIfNA defaultIfNa <- kwb.utils::defaultIfNA @@ -38,6 +42,10 @@ getAttribute <- kwb.utils::getAttribute #' @importFrom kwb.utils get_homedir getHomedir <- kwb.utils::get_homedir +# lastElement ------------------------------------------------------------------ +#' @importFrom kwb.utils lastElement +lastElement <- kwb.utils::lastElement + # moveColumnsToFront ----------------------------------------------------------- moveColumnsToFront <- kwb.utils::moveColumnsToFront @@ -73,10 +81,17 @@ readLinesFromUrl <- function(url, silent = TRUE) #' @importFrom kwb.utils removeColumns removeColumns <- kwb.utils::removeColumns +# renameColumns ---------------------------------------------------------------- +#' @importFrom kwb.utils renameColumns +renameColumns <- kwb.utils::renameColumns # resetRowNames ---------------------------------------------------------------- #' @importFrom kwb.utils resetRowNames resetRowNames <- kwb.utils::resetRowNames +# resolve ---------------------------------------------------------------------- +#' @importFrom kwb.utils resolve +resolve <- kwb.utils::resolve + # restoreAttributes ------------------------------------------------------------ #' @importFrom kwb.utils hsRestoreAttributes restoreAttributes <- kwb.utils::hsRestoreAttributes From ea99c975f38f778856b351d24806f1078b2e1963 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 12 Apr 2024 15:58:51 +0200 Subject: [PATCH 42/90] Extend separator line --- R/detach.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/detach.R b/R/detach.R index 570b31b..3b69325 100644 --- a/R/detach.R +++ b/R/detach.R @@ -156,7 +156,7 @@ printAndWaitIf <- function(dbg, variables) } } -# systemPackages -------------------------------------------------------------- +# systemPackages --------------------------------------------------------------- #' Names of Base R Packages #' From 485449f7d34f0952e8084f34c4dba8a798d604a8 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 12 Apr 2024 16:10:53 +0200 Subject: [PATCH 43/90] Add both, selectColumns() and selectElements() --- R/utils.R | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/R/utils.R b/R/utils.R index 49aed24..43702a7 100644 --- a/R/utils.R +++ b/R/utils.R @@ -108,9 +108,14 @@ kwb.utils::safePath #' @importFrom kwb.utils safeRowBind safeRowBind <- kwb.utils::safeRowBind +# selectColumns --------------------------------------------------------------- +#' @importFrom kwb.utils selectColumns +selectColumns <- kwb.utils::selectColumns + + # selectElements --------------------------------------------------------------- #' @importFrom kwb.utils selectElements -selectColumns <- kwb.utils::selectColumns +selectElements <- kwb.utils::selectElements # stopFormatted ---------------------------------------------------------------- #' @importFrom kwb.utils stopFormatted From abac0183351fe59996eed97108cc63e6eee743f3 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 12 Apr 2024 16:11:35 +0200 Subject: [PATCH 44/90] Give githubVersions() a title --- R/githubPackageVersions.R | 5 +++-- man/githubVersions.Rd | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/R/githubPackageVersions.R b/R/githubPackageVersions.R index cba8e62..5c2b0de 100644 --- a/R/githubPackageVersions.R +++ b/R/githubPackageVersions.R @@ -1,5 +1,6 @@ # githubVersions --------------------------------------------------------------- -#' Title + +#' Get Versions of Packages on GitHub #' #' @param name package name #' @param github_user name of github account, default: "KWB-R" @@ -24,6 +25,7 @@ githubPackageVersions <- function( { #kwb.utils::assignPackageObjects("kwb.package") #repo = "cran/kwb.hantush";verbose=TRUE;reduced=TRUE + stopifnot(is.character(repo)) if (length(repo) > 1L) { @@ -133,4 +135,3 @@ getGithubReleaseInfo <- function( removeColumns(result, "sha") } - diff --git a/man/githubVersions.Rd b/man/githubVersions.Rd index e577631..77fe486 100644 --- a/man/githubVersions.Rd +++ b/man/githubVersions.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/githubPackageVersions.R \name{githubVersions} \alias{githubVersions} -\title{Title} +\title{Get Versions of Packages on GitHub} \usage{ githubVersions(name, github_user = "KWB-R") } @@ -15,7 +15,7 @@ githubVersions(name, github_user = "KWB-R") data frame with one row per available version } \description{ -Title +Get Versions of Packages on GitHub } \examples{ githubVersions("kwb.utils") From 819903ecf028b82874c410e5eeaaa63ad1f11e92 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 12 Apr 2024 16:20:45 +0200 Subject: [PATCH 45/90] Document readGithubPackageDescription() --- R/readGithubPackageDescription.R | 11 ++++++++--- man/readGithubPackageDescription.Rd | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 man/readGithubPackageDescription.Rd diff --git a/R/readGithubPackageDescription.R b/R/readGithubPackageDescription.R index 045249b..436d73b 100644 --- a/R/readGithubPackageDescription.R +++ b/R/readGithubPackageDescription.R @@ -1,7 +1,12 @@ #' readGithubPackageDescription ------------------------------------------------ -#' @noMd -#' @noRd -#' @keywords internal +#' +#' Read DESCRIPTION File for R Package on GitHub +#' +#' @param repo GitHub repository, e.g. "kwb-r/kwb.utils" +#' @param sha SHA (hash) of the commit +#' @param auth_token GitHub token +#' @param destdir path to destination directory, i.e. directory to which the +#' DESCRIPTION file is copied. Default: \code{tempdir()} #' @importFrom gh gh readGithubPackageDescription <- function( repo, sha, auth_token = remotes_github_pat(), destdir = tempdir() diff --git a/man/readGithubPackageDescription.Rd b/man/readGithubPackageDescription.Rd new file mode 100644 index 0000000..b359f8f --- /dev/null +++ b/man/readGithubPackageDescription.Rd @@ -0,0 +1,26 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/readGithubPackageDescription.R +\name{readGithubPackageDescription} +\alias{readGithubPackageDescription} +\title{readGithubPackageDescription ------------------------------------------------} +\usage{ +readGithubPackageDescription( + repo, + sha, + auth_token = remotes_github_pat(), + destdir = tempdir() +) +} +\arguments{ +\item{repo}{GitHub repository, e.g. "kwb-r/kwb.utils"} + +\item{sha}{SHA (hash) of the commit} + +\item{auth_token}{GitHub token} + +\item{destdir}{path to destination directory, i.e. directory to which the +DESCRIPTION file is copied. Default: \code{tempdir()}} +} +\description{ +Read DESCRIPTION File for R Package on GitHub +} From 763d5779e24f9f99c0216609d5aa6eee95f8713e Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 12 Apr 2024 16:38:35 +0200 Subject: [PATCH 46/90] Fix :bug: in readGithubPackageDescription() --- R/readGithubPackageDescription.R | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/R/readGithubPackageDescription.R b/R/readGithubPackageDescription.R index 436d73b..4a4d370 100644 --- a/R/readGithubPackageDescription.R +++ b/R/readGithubPackageDescription.R @@ -16,6 +16,7 @@ readGithubPackageDescription <- function( content <- try(gh::gh(endpoint, .token = auth_token), silent = TRUE) if (inherits(content, "try-error")) { + message("Error: ", content) return(NULL) } @@ -23,7 +24,9 @@ readGithubPackageDescription <- function( file <- tempfile() on.exit(unlink(file)) - writeLines(selectElements(content, "message"), file) + contentLines <- strsplit(selectElements(content, "message"), "\r?\n")[[1L]] + + writeLines(contentLines, file) # Read local DESCRIPTION file desc <- remotes_read_dcf(file) @@ -33,8 +36,8 @@ readGithubPackageDescription <- function( file.copy(file, file.path(destdir, getUrl( "cached_desc", - package = selectColumns("Package"), - version = selectColumns("Version") + package = selectElements(desc, "Package"), + version = selectElements(desc, "Version") ))) # See remotes:::load_pkg_description From 4f9fd8c66b458d27330366f1e0473674fbf5f112 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 12 Apr 2024 16:42:58 +0200 Subject: [PATCH 47/90] Add two function calls to the tutorial --- vignettes/tutorial.Rmd | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/vignettes/tutorial.Rmd b/vignettes/tutorial.Rmd index 35130a2..6fc39f9 100644 --- a/vignettes/tutorial.Rmd +++ b/vignettes/tutorial.Rmd @@ -92,3 +92,15 @@ kwb.package::plotAllDependencies(dependencies, for.each = FALSE) ``` There are some packages that are used by both, "wasserportal" and "kwb.dwd". + +### Which versions of CRAN packages exist? + +```{r} +kwb.package::cranVersions("magrittr") +``` + +### Which versions of R packages on GitHub exist? + +```{r} +kwb.package::githubVersions(name = "kwb.utils") +``` From b7940dbb45f8a877e4902f63a67903c863fe3ddf Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 12 Apr 2024 16:43:10 +0200 Subject: [PATCH 48/90] Update documentation --- NAMESPACE | 2 +- man/reexports.Rd | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 man/reexports.Rd diff --git a/NAMESPACE b/NAMESPACE index 1095f5f..8ed6c45 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -64,6 +64,7 @@ importFrom(kwb.utils,resolve) importFrom(kwb.utils,runInDirectory) importFrom(kwb.utils,safePath) importFrom(kwb.utils,safeRowBind) +importFrom(kwb.utils,selectColumns) importFrom(kwb.utils,selectElements) importFrom(kwb.utils,stopFormatted) importFrom(mvbutils,foodweb) @@ -71,7 +72,6 @@ importFrom(networkD3,sankeyNetwork) importFrom(remotes,github_remote) importFrom(remotes,install_github) importFrom(remotes,remote_download) -importFrom(utils,available.packages) importFrom(utils,download.file) importFrom(utils,download.packages) importFrom(utils,install.packages) diff --git a/man/reexports.Rd b/man/reexports.Rd new file mode 100644 index 0000000..8c97f8d --- /dev/null +++ b/man/reexports.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\docType{import} +\name{reexports} +\alias{reexports} +\alias{runInDirectory} +\alias{safePath} +\title{Objects exported from other packages} +\keyword{internal} +\description{ +These objects are imported from other packages. Follow the links +below to see their documentation. + +\describe{ + \item{kwb.utils}{\code{\link[kwb.utils]{runInDirectory}}, \code{\link[kwb.utils]{safePath}}} +}} + From 37bc47d76eaa3739a6e329cff3e4e6db427d2a66 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 12 Apr 2024 17:55:14 +0200 Subject: [PATCH 49/90] Add magrittr's pipe operator --- DESCRIPTION | 1 + NAMESPACE | 2 ++ R/utils-pipe.R | 14 ++++++++++++++ man/pipe.Rd | 20 ++++++++++++++++++++ 4 files changed, 37 insertions(+) create mode 100644 R/utils-pipe.R create mode 100644 man/pipe.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 4e2111b..e899522 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -21,6 +21,7 @@ BugReports: https://github.com/kwb-r/kwb.package/issues Imports: gh, kwb.utils (>= 0.5.0), + magrittr, mvbutils, networkD3, remotes, diff --git a/NAMESPACE b/NAMESPACE index 8ed6c45..914f434 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,5 +1,6 @@ # Generated by roxygen2: do not edit by hand +export("%>%") export(addNodeLabels) export(anglesToPoints) export(archivedCranVersions) @@ -67,6 +68,7 @@ importFrom(kwb.utils,safeRowBind) importFrom(kwb.utils,selectColumns) importFrom(kwb.utils,selectElements) importFrom(kwb.utils,stopFormatted) +importFrom(magrittr,"%>%") importFrom(mvbutils,foodweb) importFrom(networkD3,sankeyNetwork) importFrom(remotes,github_remote) diff --git a/R/utils-pipe.R b/R/utils-pipe.R new file mode 100644 index 0000000..fd0b1d1 --- /dev/null +++ b/R/utils-pipe.R @@ -0,0 +1,14 @@ +#' Pipe operator +#' +#' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. +#' +#' @name %>% +#' @rdname pipe +#' @keywords internal +#' @export +#' @importFrom magrittr %>% +#' @usage lhs \%>\% rhs +#' @param lhs A value or the magrittr placeholder. +#' @param rhs A function call using the magrittr semantics. +#' @return The result of calling `rhs(lhs)`. +NULL diff --git a/man/pipe.Rd b/man/pipe.Rd new file mode 100644 index 0000000..1f8f237 --- /dev/null +++ b/man/pipe.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils-pipe.R +\name{\%>\%} +\alias{\%>\%} +\title{Pipe operator} +\usage{ +lhs \%>\% rhs +} +\arguments{ +\item{lhs}{A value or the magrittr placeholder.} + +\item{rhs}{A function call using the magrittr semantics.} +} +\value{ +The result of calling `rhs(lhs)`. +} +\description{ +See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. +} +\keyword{internal} From e3bce7f1c97e992aabd2d3da9a28e0d10eb0bfaa Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 12 Apr 2024 17:55:38 +0200 Subject: [PATCH 50/90] Add getPackageLicences() --- NAMESPACE | 1 + R/getPackageLicences.R | 27 +++++++++++++++++++++++++++ man/getPackageLicences.Rd | 17 +++++++++++++++++ vignettes/tutorial.Rmd | 6 ++++++ 4 files changed, 51 insertions(+) create mode 100644 R/getPackageLicences.R create mode 100644 man/getPackageLicences.Rd diff --git a/NAMESPACE b/NAMESPACE index 914f434..0d756ed 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -17,6 +17,7 @@ export(equidistantAngles) export(exampleLinksAndNodes) export(getCranPackageDatabase) export(getPackageFilesToInstall) +export(getPackageLicences) export(getRVersionMajorMinor) export(githubVersions) export(gradToRad) diff --git a/R/getPackageLicences.R b/R/getPackageLicences.R new file mode 100644 index 0000000..4f61cbb --- /dev/null +++ b/R/getPackageLicences.R @@ -0,0 +1,27 @@ +# getPackageLicences ----------------------------------------------------------- + +#' Which Licences are Specified for the Packages? +#' +#' @param packages names of (installed) packages +#' @return data frame +#' @export +getPackageLicences <- function(packages) +{ + lapply(packages, function(package) { + description <- readDescription(package) + fields <- c("licence", "license") + columns <- intersect(colnames(description), fields) + as.data.frame(description[, columns, drop = FALSE]) + }) %>% + stats::setNames(packages) %>% + rbindAll(nameColumn = "package") %>% + moveColumnsToFront("package") +} + +# readDescription -------------------------------------------------------------- +readDescription <- function(package) +{ + description <- read.dcf(system.file("DESCRIPTION", package = package)) + colnames(description) <- tolower(colnames(description)) + description +} diff --git a/man/getPackageLicences.Rd b/man/getPackageLicences.Rd new file mode 100644 index 0000000..725d1ec --- /dev/null +++ b/man/getPackageLicences.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/getPackageLicences.R +\name{getPackageLicences} +\alias{getPackageLicences} +\title{Which Licences are Specified for the Packages?} +\usage{ +getPackageLicences(packages) +} +\arguments{ +\item{packages}{names of (installed) packages} +} +\value{ +data frame +} +\description{ +Which Licences are Specified for the Packages? +} diff --git a/vignettes/tutorial.Rmd b/vignettes/tutorial.Rmd index 6fc39f9..30b2327 100644 --- a/vignettes/tutorial.Rmd +++ b/vignettes/tutorial.Rmd @@ -104,3 +104,9 @@ kwb.package::cranVersions("magrittr") ```{r} kwb.package::githubVersions(name = "kwb.utils") ``` + +### What licences are specified for (installed) packages? + +```{r} +kwb.package::getPackageLicences(c("magrittr", "dplyr", "shiny")) +``` From 58aeca47522b0b5f1838b0355b8170e70564fec5 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 12 Apr 2024 18:02:52 +0200 Subject: [PATCH 51/90] Use base packages to let vignette pass on GitHub actions --- vignettes/tutorial.Rmd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vignettes/tutorial.Rmd b/vignettes/tutorial.Rmd index 30b2327..97aa359 100644 --- a/vignettes/tutorial.Rmd +++ b/vignettes/tutorial.Rmd @@ -107,6 +107,6 @@ kwb.package::githubVersions(name = "kwb.utils") ### What licences are specified for (installed) packages? -```{r} -kwb.package::getPackageLicences(c("magrittr", "dplyr", "shiny")) +```{r eval = FALSE} +kwb.package::getPackageLicences(kwb.package::systemPackages()) ``` From 636d76773d0543b76e265b919612bbb26a8e495b Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 12 Apr 2024 18:12:15 +0200 Subject: [PATCH 52/90] Set mustWork = TRUE --- R/getPackageLicences.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/R/getPackageLicences.R b/R/getPackageLicences.R index 4f61cbb..770146c 100644 --- a/R/getPackageLicences.R +++ b/R/getPackageLicences.R @@ -21,7 +21,10 @@ getPackageLicences <- function(packages) # readDescription -------------------------------------------------------------- readDescription <- function(package) { - description <- read.dcf(system.file("DESCRIPTION", package = package)) + description <- "DESCRIPTION" %>% + system.file(package = package, mustWork = TRUE) %>% + read.dcf() + colnames(description) <- tolower(colnames(description)) description } From 82e10f17ddb51cc86591c09c88f7e1cd02999da2 Mon Sep 17 00:00:00 2001 From: hsonne Date: Tue, 16 Apr 2024 16:12:05 +0200 Subject: [PATCH 53/90] Do not convert "package" column to a factor --- NAMESPACE | 1 + R/getPackageLicences.R | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 0d756ed..051dfe3 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -55,6 +55,7 @@ importFrom(kwb.utils,getAttribute) importFrom(kwb.utils,get_homedir) importFrom(kwb.utils,hsRestoreAttributes) importFrom(kwb.utils,lastElement) +importFrom(kwb.utils,moveColumnsToFront) importFrom(kwb.utils,noFactorDataFrame) importFrom(kwb.utils,noSuchElements) importFrom(kwb.utils,orderBy) diff --git a/R/getPackageLicences.R b/R/getPackageLicences.R index 770146c..0b70d14 100644 --- a/R/getPackageLicences.R +++ b/R/getPackageLicences.R @@ -4,6 +4,7 @@ #' #' @param packages names of (installed) packages #' @return data frame +#' @importFrom kwb.utils moveColumnsToFront rbindAll #' @export getPackageLicences <- function(packages) { @@ -14,8 +15,8 @@ getPackageLicences <- function(packages) as.data.frame(description[, columns, drop = FALSE]) }) %>% stats::setNames(packages) %>% - rbindAll(nameColumn = "package") %>% - moveColumnsToFront("package") + kwb.utils::rbindAll(nameColumn = "package", namesAsFactor = FALSE) %>% + kwb.utils::moveColumnsToFront("package") } # readDescription -------------------------------------------------------------- From 8db98c3329f267fae0cf8987ffb6334f8d138eb2 Mon Sep 17 00:00:00 2001 From: hsonne Date: Tue, 16 Apr 2024 16:26:47 +0200 Subject: [PATCH 54/90] Move readDescription() to helpers.R --- R/getPackageLicences.R | 11 ----------- R/helpers.R | 11 +++++++++++ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/R/getPackageLicences.R b/R/getPackageLicences.R index 0b70d14..49e8e0d 100644 --- a/R/getPackageLicences.R +++ b/R/getPackageLicences.R @@ -18,14 +18,3 @@ getPackageLicences <- function(packages) kwb.utils::rbindAll(nameColumn = "package", namesAsFactor = FALSE) %>% kwb.utils::moveColumnsToFront("package") } - -# readDescription -------------------------------------------------------------- -readDescription <- function(package) -{ - description <- "DESCRIPTION" %>% - system.file(package = package, mustWork = TRUE) %>% - read.dcf() - - colnames(description) <- tolower(colnames(description)) - description -} diff --git a/R/helpers.R b/R/helpers.R index 17cecd0..79a5929 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -54,3 +54,14 @@ packageInDestdir <- function(package, destdir, verbose = TRUE) structure(file_exists, path = if (file_exists) lastElement(files)) } + +# readDescription -------------------------------------------------------------- +readDescription <- function(package) +{ + description <- "DESCRIPTION" %>% + system.file(package = package, mustWork = TRUE) %>% + read.dcf() + + colnames(description) <- tolower(colnames(description)) + description +} From 112c4d8d7fb2f2a92ec9cf480cb66cf89175bdb5 Mon Sep 17 00:00:00 2001 From: hsonne Date: Tue, 16 Apr 2024 16:26:56 +0200 Subject: [PATCH 55/90] Add getAuthors() --- NAMESPACE | 1 + R/getAuthors.R | 13 +++++++++++++ man/getAuthors.Rd | 14 ++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 R/getAuthors.R create mode 100644 man/getAuthors.Rd diff --git a/NAMESPACE b/NAMESPACE index 051dfe3..03bda77 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -15,6 +15,7 @@ export(drawDependencies) export(drawLink) export(equidistantAngles) export(exampleLinksAndNodes) +export(getAuthors) export(getCranPackageDatabase) export(getPackageFilesToInstall) export(getPackageLicences) diff --git a/R/getAuthors.R b/R/getAuthors.R new file mode 100644 index 0000000..b3a108a --- /dev/null +++ b/R/getAuthors.R @@ -0,0 +1,13 @@ +# getAuthors ------------------------------------------------------------------- + +#' Get Information on Package Authors +#' +#' @param package name of (installed) package +#' @export +getAuthors <- function(package) +{ + description <- readDescription(package) + columns <- colnames(description) + columns <- grep("author", columns, value = TRUE, ignore.case = TRUE) + description[, columns] +} diff --git a/man/getAuthors.Rd b/man/getAuthors.Rd new file mode 100644 index 0000000..c9bcfbc --- /dev/null +++ b/man/getAuthors.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/getAuthors.R +\name{getAuthors} +\alias{getAuthors} +\title{Get Information on Package Authors} +\usage{ +getAuthors(package) +} +\arguments{ +\item{package}{name of (installed) package} +} +\description{ +Get Information on Package Authors +} From 22ba3c24b8bac78da4db9f3e18b8eb6e3069f77f Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 26 Apr 2024 16:09:50 +0200 Subject: [PATCH 56/90] Add arguments "db", "which", "by.type" to packageDependencies() --- R/detach.R | 76 +++++++++++++++++++++++++++++++------- man/packageDependencies.Rd | 43 +++++++++++++++++++-- 2 files changed, 102 insertions(+), 17 deletions(-) diff --git a/R/detach.R b/R/detach.R index 3b69325..c738905 100644 --- a/R/detach.R +++ b/R/detach.R @@ -123,26 +123,76 @@ sortedDependencies <- function(package, dbg = FALSE) #' Package Dependencies #' -#' @param packages passed to \code{\link[tools]{package_dependencies}} -#' @param recursive passed to \code{\link[tools]{package_dependencies}} -#' @param reverse passed to \code{\link[tools]{package_dependencies}} -#' +#' @inheritParams tools::package_dependencies +#' @param \dots further arguments passed to +#' \code{\link[tools]{package_dependencies}} +#' @param by.type logical indicating whether or not to split the dependencies +#' by type i.e. by the elements given in \code{which} #' @export -#' packageDependencies <- function( - packages = NULL, recursive = TRUE, reverse = FALSE + packages = NULL, + db = utils::installed.packages(), + which = c("Depends", "Imports", "LinkingTo", "Suggests", "Enhances")[1:3], + recursive = TRUE, + reverse = FALSE, + ..., + by.type = FALSE ) { - tools::package_dependencies( - packages, - db = utils::installed.packages(), - recursive = recursive, - reverse = reverse - ) + if (!by.type) { + return(tools::package_dependencies( + packages, + db = db, + which = which, + recursive = recursive, + reverse = reverse, + ... + )) + } + + # Package dependencies by type + + if (length(packages) < 1L) { + # Recursive call for each package + return(lapply( + X = packages, + FUN = packageDependencies, + db = db, + which = which, + recursive = recursive, + reverse = reverse, + ..., + by.type = by.type + )) + } + + stats::setNames(nm = which) %>% + lapply(function(which.one) { + #which.one <- "Depends" + #print(which.one) + dependencies <- tools::package_dependencies( + packages, + db = db, + which = which.one, + recursive = recursive, + reverse = reverse, + ... + )[[1L]] + if (length(dependencies)) { + data.frame( + type = rep(which.one, length(dependencies)), + dependency = dependencies, + getPackageLicences(dependencies) %>% + kwb.utils::selectColumns("license", drop = FALSE) + ) + } # else NULL + }) %>% + kwb.utils::excludeNULL(dbg = FALSE) %>% + do.call(what = rbind.data.frame) %>% + kwb.utils::resetRowNames() } # printAndWaitIf --------------------------------------------------------------- - printAndWaitIf <- function(dbg, variables) { if (dbg) { diff --git a/man/packageDependencies.Rd b/man/packageDependencies.Rd index e49a427..3bbe481 100644 --- a/man/packageDependencies.Rd +++ b/man/packageDependencies.Rd @@ -4,14 +4,49 @@ \alias{packageDependencies} \title{Package Dependencies} \usage{ -packageDependencies(packages = NULL, recursive = TRUE, reverse = FALSE) +packageDependencies( + packages = NULL, + db = utils::installed.packages(), + which = c("Depends", "Imports", "LinkingTo", "Suggests", "Enhances")[1:3], + recursive = TRUE, + reverse = FALSE, + ..., + by.type = FALSE +) } \arguments{ -\item{packages}{passed to \code{\link[tools]{package_dependencies}}} +\item{packages}{a character vector of package names.} -\item{recursive}{passed to \code{\link[tools]{package_dependencies}}} +\item{db}{character matrix as from \code{\link{available.packages}()} + (with the default \code{NULL} the results of this call) + or data frame variants thereof. Alternatively, a package database + like the one available from + \url{https://cran.r-project.org/web/packages/packages.rds}. + } -\item{reverse}{passed to \code{\link[tools]{package_dependencies}}} +\item{which}{a character vector listing the types of + dependencies, a subset of + \code{c("Depends", "Imports", "LinkingTo", "Suggests", "Enhances")}. + Character string \code{"all"} is shorthand for that vector, + character string \code{"most"} for the same vector without + \code{"Enhances"}, + character string \code{"strong"} (default) for the first three + elements of that vector. + } + +\item{recursive}{a logical indicating whether (reverse) dependencies + of (reverse) dependencies (and so on) should be included, or a + character vector like \code{which} indicating the type of (reverse) + dependencies to be added recursively.} + +\item{reverse}{logical: if \code{FALSE} (default), regular + dependencies are calculated, otherwise reverse dependencies.} + +\item{\dots}{further arguments passed to +\code{\link[tools]{package_dependencies}}} + +\item{by.type}{logical indicating whether or not to split the dependencies +by type i.e. by the elements given in \code{which}} } \description{ Package Dependencies From c9f0017a8e798a0bcac541f73d3d0d9163d2c3f6 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 26 Apr 2024 16:10:24 +0200 Subject: [PATCH 57/90] Rename "license" to "licence" (British English) --- R/getPackageLicences.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/R/getPackageLicences.R b/R/getPackageLicences.R index 49e8e0d..8f2de2c 100644 --- a/R/getPackageLicences.R +++ b/R/getPackageLicences.R @@ -12,7 +12,10 @@ getPackageLicences <- function(packages) description <- readDescription(package) fields <- c("licence", "license") columns <- intersect(colnames(description), fields) - as.data.frame(description[, columns, drop = FALSE]) + as.data.frame(description[, columns, drop = FALSE]) %>% + kwb.utils::renameColumns(list( + license = "licence" + )) }) %>% stats::setNames(packages) %>% kwb.utils::rbindAll(nameColumn = "package", namesAsFactor = FALSE) %>% From 5ba96cdcb41e6ebfbc51eb38697ab6fb323f84c2 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 26 Apr 2024 16:11:29 +0200 Subject: [PATCH 58/90] Improve error handling add stopIfNotInstalled() --- NAMESPACE | 1 + R/helpers.R | 23 +++++++++++++++++++++-- man/stopIfNotInstalled.Rd | 14 ++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 man/stopIfNotInstalled.Rd diff --git a/NAMESPACE b/NAMESPACE index 03bda77..36d17df 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -37,6 +37,7 @@ export(plotSankeyNetwork) export(provideInLocalCRAN) export(setOptionsForPackrat) export(sortedDependencies) +export(stopIfNotInstalled) export(systemPackages) export(toLinksAndNodes) export(toNodes) diff --git a/R/helpers.R b/R/helpers.R index 79a5929..19d6389 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -58,10 +58,29 @@ packageInDestdir <- function(package, destdir, verbose = TRUE) # readDescription -------------------------------------------------------------- readDescription <- function(package) { - description <- "DESCRIPTION" %>% - system.file(package = package, mustWork = TRUE) %>% + stopIfNotInstalled(package) + + description <- system.file("DESCRIPTION", package = package) %>% + kwb.utils::safePath() %>% read.dcf() colnames(description) <- tolower(colnames(description)) description } + +# stopIfNotInstalled ----------------------------------------------------------- + +#' Is a Package Installed? +#' +#' @param package package name (character vector of length one) +#' @export +stopIfNotInstalled <- function(package) +{ + stopifnot(is.character(package), length(package) == 1L) + + available <- rownames(installed.packages()) + + if (!package %in% available) { + kwb.utils::stopFormatted("The package '%s' is not installed.", package) + } +} diff --git a/man/stopIfNotInstalled.Rd b/man/stopIfNotInstalled.Rd new file mode 100644 index 0000000..d2c0693 --- /dev/null +++ b/man/stopIfNotInstalled.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/helpers.R +\name{stopIfNotInstalled} +\alias{stopIfNotInstalled} +\title{Is a Package Installed?} +\usage{ +stopIfNotInstalled(package) +} +\arguments{ +\item{package}{package name (character vector of length one)} +} +\description{ +Is a Package Installed? +} From bf606a5b50758f01e175e0d39f0a943a9093e7f0 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 26 Apr 2024 16:14:55 +0200 Subject: [PATCH 59/90] Add hasGplLicence() --- NAMESPACE | 1 + R/helpers.R | 14 ++++++++++++++ man/hasGplLicence.Rd | 17 +++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 man/hasGplLicence.Rd diff --git a/NAMESPACE b/NAMESPACE index 36d17df..3889338 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -22,6 +22,7 @@ export(getPackageLicences) export(getRVersionMajorMinor) export(githubVersions) export(gradToRad) +export(hasGplLicence) export(initLocalCRAN) export(installGithubPackages) export(installRemotes) diff --git a/R/helpers.R b/R/helpers.R index 19d6389..ade4264 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -37,6 +37,20 @@ githubRepo <- function(github_user, name) paste(github_user, name, sep = "/") } +# hasGplLicence ---------------------------------------------------------------- + +#' Do Packages have a GPL Licence? +#' +#' @param packages package name(s) as a vector of character +#' @returns vector of logical +#' @export +hasGplLicence <- function(packages) +{ + getPackageLicences(packages) %>% + kwb.utils::selectColumns("licence") %>% + grep(pattern = "GPL", ignore.case = TRUE) +} + # packageInDestdir ------------------------------------------------------------- #' @noMd #' @noRd diff --git a/man/hasGplLicence.Rd b/man/hasGplLicence.Rd new file mode 100644 index 0000000..a6afd81 --- /dev/null +++ b/man/hasGplLicence.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/helpers.R +\name{hasGplLicence} +\alias{hasGplLicence} +\title{Do Packages have a GPL Licence?} +\usage{ +hasGplLicence(packages) +} +\arguments{ +\item{packages}{package name(s) as a vector of character} +} +\value{ +vector of logical +} +\description{ +Do Packages have a GPL Licence? +} From d64c786e1f2e2e31940fdaf94d7bb0053d12912b Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 26 Apr 2024 18:46:42 +0200 Subject: [PATCH 60/90] Extract packageDependenciesByType() from packageDependencies() --- NAMESPACE | 1 + R/detach.R | 101 ++++++++++++++++++++----------- man/packageDependencies.Rd | 13 ++-- man/packageDependenciesByType.Rd | 49 +++++++++++++++ 4 files changed, 119 insertions(+), 45 deletions(-) create mode 100644 man/packageDependenciesByType.Rd diff --git a/NAMESPACE b/NAMESPACE index 3889338..898da87 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -29,6 +29,7 @@ export(installRemotes) export(installedDependencies) export(installedKwbPackages) export(packageDependencies) +export(packageDependenciesByType) export(packageString) export(plotAllDependencies) export(plotDependencies) diff --git a/R/detach.R b/R/detach.R index c738905..5efa8d6 100644 --- a/R/detach.R +++ b/R/detach.R @@ -122,12 +122,11 @@ sortedDependencies <- function(package, dbg = FALSE) # packageDependencies ---------------------------------------------------------- #' Package Dependencies +#' +#' This is just a wrapper around \code{\link[tools]{package_dependencies}} with +#' some defaults defined. #' #' @inheritParams tools::package_dependencies -#' @param \dots further arguments passed to -#' \code{\link[tools]{package_dependencies}} -#' @param by.type logical indicating whether or not to split the dependencies -#' by type i.e. by the elements given in \code{which} #' @export packageDependencies <- function( packages = NULL, @@ -135,40 +134,65 @@ packageDependencies <- function( which = c("Depends", "Imports", "LinkingTo", "Suggests", "Enhances")[1:3], recursive = TRUE, reverse = FALSE, - ..., - by.type = FALSE + verbose = FALSE ) { - if (!by.type) { - return(tools::package_dependencies( - packages, - db = db, - which = which, - recursive = recursive, - reverse = reverse, - ... - )) + tools::package_dependencies( + packages, + db = db, + which = which, + recursive = recursive, + reverse = reverse, + verbose = verbose + ) +} + +# packageDependenciesByType ---------------------------------------------------- + +#' Package Dependencies by Type +#' +#' @inheritParams tools::package_dependencies +#' @export +packageDependenciesByType <- function( + packages = NULL, + db = utils::installed.packages(), + which = c("Depends", "Imports", "LinkingTo", "Suggests", "Enhances")[1:3], + recursive = TRUE, + reverse = FALSE, + verbose = FALSE +) +{ + #kwb.utils::assignPackageObjects("kwb.package");`%>%` <- magrittr::`%>%` + #packages <- c("kwb.utils", "kwb.plot") + + n_packages <- length(packages) + + if (n_packages == 0L) { + return(NULL) } - # Package dependencies by type - - if (length(packages) < 1L) { - # Recursive call for each package - return(lapply( - X = packages, - FUN = packageDependencies, - db = db, - which = which, - recursive = recursive, - reverse = reverse, - ..., - by.type = by.type - )) + if (n_packages > 1L) { + + # Call this function recursively for each package + return( + lapply( + X = stats::setNames(nm = packages), + FUN = packageDependenciesByType, + db = db, + which = which, + recursive = recursive, + reverse = reverse, + verbose = verbose + ) %>% + do.call(what = rbind) + ) } - stats::setNames(nm = which) %>% + stopifnot(n_packages == 1L) + + which %>% lapply(function(which.one) { - #which.one <- "Depends" + #which.one <- "Imports" #print(which.one) dependencies <- tools::package_dependencies( packages, @@ -176,17 +200,20 @@ packageDependencies <- function( which = which.one, recursive = recursive, reverse = reverse, - ... + verbose = verbose )[[1L]] if (length(dependencies)) { data.frame( - type = rep(which.one, length(dependencies)), - dependency = dependencies, - getPackageLicences(dependencies) %>% - kwb.utils::selectColumns("license", drop = FALSE) - ) + package = packages, + type = rep(which.one, length(dependencies)) + ) %>% + cbind( + getPackageLicences(dependencies) %>% + kwb.utils::renameColumns(list(package = "dependency")) + ) } # else NULL }) %>% + stats::setNames(which) %>% kwb.utils::excludeNULL(dbg = FALSE) %>% do.call(what = rbind.data.frame) %>% kwb.utils::resetRowNames() diff --git a/man/packageDependencies.Rd b/man/packageDependencies.Rd index 3bbe481..d772c8f 100644 --- a/man/packageDependencies.Rd +++ b/man/packageDependencies.Rd @@ -10,8 +10,7 @@ packageDependencies( which = c("Depends", "Imports", "LinkingTo", "Suggests", "Enhances")[1:3], recursive = TRUE, reverse = FALSE, - ..., - by.type = FALSE + verbose = FALSE ) } \arguments{ @@ -42,12 +41,10 @@ packageDependencies( \item{reverse}{logical: if \code{FALSE} (default), regular dependencies are calculated, otherwise reverse dependencies.} -\item{\dots}{further arguments passed to -\code{\link[tools]{package_dependencies}}} - -\item{by.type}{logical indicating whether or not to split the dependencies -by type i.e. by the elements given in \code{which}} +\item{verbose}{logical indicating if output should monitor the package + search cycles.} } \description{ -Package Dependencies +This is just a wrapper around \code{\link[tools]{package_dependencies}} with +some defaults defined. } diff --git a/man/packageDependenciesByType.Rd b/man/packageDependenciesByType.Rd new file mode 100644 index 0000000..75fc8b8 --- /dev/null +++ b/man/packageDependenciesByType.Rd @@ -0,0 +1,49 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/detach.R +\name{packageDependenciesByType} +\alias{packageDependenciesByType} +\title{Package Dependencies by Type} +\usage{ +packageDependenciesByType( + packages = NULL, + db = utils::installed.packages(), + which = c("Depends", "Imports", "LinkingTo", "Suggests", "Enhances")[1:3], + recursive = TRUE, + reverse = FALSE, + verbose = FALSE +) +} +\arguments{ +\item{packages}{a character vector of package names.} + +\item{db}{character matrix as from \code{\link{available.packages}()} + (with the default \code{NULL} the results of this call) + or data frame variants thereof. Alternatively, a package database + like the one available from + \url{https://cran.r-project.org/web/packages/packages.rds}. + } + +\item{which}{a character vector listing the types of + dependencies, a subset of + \code{c("Depends", "Imports", "LinkingTo", "Suggests", "Enhances")}. + Character string \code{"all"} is shorthand for that vector, + character string \code{"most"} for the same vector without + \code{"Enhances"}, + character string \code{"strong"} (default) for the first three + elements of that vector. + } + +\item{recursive}{a logical indicating whether (reverse) dependencies + of (reverse) dependencies (and so on) should be included, or a + character vector like \code{which} indicating the type of (reverse) + dependencies to be added recursively.} + +\item{reverse}{logical: if \code{FALSE} (default), regular + dependencies are calculated, otherwise reverse dependencies.} + +\item{verbose}{logical indicating if output should monitor the package + search cycles.} +} +\description{ +Package Dependencies by Type +} From 59b19316a50615638621e0c6a78ba6c751eb8e6c Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 26 Apr 2024 19:24:58 +0200 Subject: [PATCH 61/90] Define "shortcuts" to all kwb.utils functions --- R/detach.R | 9 +++++---- R/getPackageLicences.R | 6 +++--- R/helpers.R | 6 +++--- R/utils.R | 4 ++-- man/reexports.Rd | 17 ----------------- 5 files changed, 13 insertions(+), 29 deletions(-) delete mode 100644 man/reexports.Rd diff --git a/R/detach.R b/R/detach.R index 5efa8d6..f317df2 100644 --- a/R/detach.R +++ b/R/detach.R @@ -184,7 +184,8 @@ packageDependenciesByType <- function( reverse = reverse, verbose = verbose ) %>% - do.call(what = rbind) + do.call(what = rbind) %>% + resetRowNames() ) } @@ -209,14 +210,14 @@ packageDependenciesByType <- function( ) %>% cbind( getPackageLicences(dependencies) %>% - kwb.utils::renameColumns(list(package = "dependency")) + renameColumns(list(package = "dependency")) ) } # else NULL }) %>% stats::setNames(which) %>% - kwb.utils::excludeNULL(dbg = FALSE) %>% + excludeNULL(dbg = FALSE) %>% do.call(what = rbind.data.frame) %>% - kwb.utils::resetRowNames() + resetRowNames() } # printAndWaitIf --------------------------------------------------------------- diff --git a/R/getPackageLicences.R b/R/getPackageLicences.R index 8f2de2c..85bc3a7 100644 --- a/R/getPackageLicences.R +++ b/R/getPackageLicences.R @@ -13,11 +13,11 @@ getPackageLicences <- function(packages) fields <- c("licence", "license") columns <- intersect(colnames(description), fields) as.data.frame(description[, columns, drop = FALSE]) %>% - kwb.utils::renameColumns(list( + renameColumns(list( license = "licence" )) }) %>% stats::setNames(packages) %>% - kwb.utils::rbindAll(nameColumn = "package", namesAsFactor = FALSE) %>% - kwb.utils::moveColumnsToFront("package") + rbindAll(nameColumn = "package", namesAsFactor = FALSE) %>% + moveColumnsToFront("package") } diff --git a/R/helpers.R b/R/helpers.R index ade4264..2112bd8 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -47,7 +47,7 @@ githubRepo <- function(github_user, name) hasGplLicence <- function(packages) { getPackageLicences(packages) %>% - kwb.utils::selectColumns("licence") %>% + selectColumns("licence") %>% grep(pattern = "GPL", ignore.case = TRUE) } @@ -75,7 +75,7 @@ readDescription <- function(package) stopIfNotInstalled(package) description <- system.file("DESCRIPTION", package = package) %>% - kwb.utils::safePath() %>% + safePath() %>% read.dcf() colnames(description) <- tolower(colnames(description)) @@ -95,6 +95,6 @@ stopIfNotInstalled <- function(package) available <- rownames(installed.packages()) if (!package %in% available) { - kwb.utils::stopFormatted("The package '%s' is not installed.", package) + stopFormatted("The package '%s' is not installed.", package) } } diff --git a/R/utils.R b/R/utils.R index 43702a7..700b625 100644 --- a/R/utils.R +++ b/R/utils.R @@ -98,11 +98,11 @@ restoreAttributes <- kwb.utils::hsRestoreAttributes # runInDirectory --------------------------------------------------------------- #' @importFrom kwb.utils runInDirectory -kwb.utils::runInDirectory +runInDirectory <- kwb.utils::runInDirectory # safePath --------------------------------------------------------------------- #' @importFrom kwb.utils safePath -kwb.utils::safePath +safePath <- kwb.utils::safePath # safeRowBind ------------------------------------------------------------------ #' @importFrom kwb.utils safeRowBind diff --git a/man/reexports.Rd b/man/reexports.Rd deleted file mode 100644 index 8c97f8d..0000000 --- a/man/reexports.Rd +++ /dev/null @@ -1,17 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils.R -\docType{import} -\name{reexports} -\alias{reexports} -\alias{runInDirectory} -\alias{safePath} -\title{Objects exported from other packages} -\keyword{internal} -\description{ -These objects are imported from other packages. Follow the links -below to see their documentation. - -\describe{ - \item{kwb.utils}{\code{\link[kwb.utils]{runInDirectory}}, \code{\link[kwb.utils]{safePath}}} -}} - From 5578f0e3d89cade977c6cf581b08e34ea8e2738c Mon Sep 17 00:00:00 2001 From: hsonne Date: Tue, 30 Apr 2024 21:33:44 +0200 Subject: [PATCH 62/90] Move packageDependenciesByType() to its own file --- R/detach.R | 73 -------------------------------- R/packageDependenciesByType.R | 72 +++++++++++++++++++++++++++++++ man/packageDependenciesByType.Rd | 2 +- 3 files changed, 73 insertions(+), 74 deletions(-) create mode 100644 R/packageDependenciesByType.R diff --git a/R/detach.R b/R/detach.R index f317df2..430f9a7 100644 --- a/R/detach.R +++ b/R/detach.R @@ -147,79 +147,6 @@ packageDependencies <- function( ) } -# packageDependenciesByType ---------------------------------------------------- - -#' Package Dependencies by Type -#' -#' @inheritParams tools::package_dependencies -#' @export -packageDependenciesByType <- function( - packages = NULL, - db = utils::installed.packages(), - which = c("Depends", "Imports", "LinkingTo", "Suggests", "Enhances")[1:3], - recursive = TRUE, - reverse = FALSE, - verbose = FALSE -) -{ - #kwb.utils::assignPackageObjects("kwb.package");`%>%` <- magrittr::`%>%` - #packages <- c("kwb.utils", "kwb.plot") - - n_packages <- length(packages) - - if (n_packages == 0L) { - return(NULL) - } - - if (n_packages > 1L) { - - # Call this function recursively for each package - return( - lapply( - X = stats::setNames(nm = packages), - FUN = packageDependenciesByType, - db = db, - which = which, - recursive = recursive, - reverse = reverse, - verbose = verbose - ) %>% - do.call(what = rbind) %>% - resetRowNames() - ) - } - - stopifnot(n_packages == 1L) - - which %>% - lapply(function(which.one) { - #which.one <- "Imports" - #print(which.one) - dependencies <- tools::package_dependencies( - packages, - db = db, - which = which.one, - recursive = recursive, - reverse = reverse, - verbose = verbose - )[[1L]] - if (length(dependencies)) { - data.frame( - package = packages, - type = rep(which.one, length(dependencies)) - ) %>% - cbind( - getPackageLicences(dependencies) %>% - renameColumns(list(package = "dependency")) - ) - } # else NULL - }) %>% - stats::setNames(which) %>% - excludeNULL(dbg = FALSE) %>% - do.call(what = rbind.data.frame) %>% - resetRowNames() -} - # printAndWaitIf --------------------------------------------------------------- printAndWaitIf <- function(dbg, variables) { diff --git a/R/packageDependenciesByType.R b/R/packageDependenciesByType.R new file mode 100644 index 0000000..e10fcfd --- /dev/null +++ b/R/packageDependenciesByType.R @@ -0,0 +1,72 @@ +# packageDependenciesByType ---------------------------------------------------- + +#' Package Dependencies by Type +#' +#' @inheritParams tools::package_dependencies +#' @export +packageDependenciesByType <- function( + packages = NULL, + db = utils::installed.packages(), + which = c("Depends", "Imports", "LinkingTo", "Suggests", "Enhances")[1:3], + recursive = TRUE, + reverse = FALSE, + verbose = FALSE +) +{ + #kwb.utils::assignPackageObjects("kwb.package");`%>%` <- magrittr::`%>%` + #packages <- c("kwb.utils", "kwb.plot") + + n_packages <- length(packages) + + if (n_packages == 0L) { + return(NULL) + } + + if (n_packages > 1L) { + + # Call this function recursively for each package + return( + lapply( + X = stats::setNames(nm = packages), + FUN = packageDependenciesByType, + db = db, + which = which, + recursive = recursive, + reverse = reverse, + verbose = verbose + ) %>% + do.call(what = rbind) %>% + resetRowNames() + ) + } + + stopifnot(n_packages == 1L) + + which %>% + lapply(function(which.one) { + #which.one <- "Imports" + #print(which.one) + dependencies <- tools::package_dependencies( + packages, + db = db, + which = which.one, + recursive = recursive, + reverse = reverse, + verbose = verbose + )[[1L]] + if (length(dependencies)) { + data.frame( + package = packages, + type = rep(which.one, length(dependencies)) + ) %>% + cbind( + getPackageLicences(dependencies) %>% + renameColumns(list(package = "dependency")) + ) + } # else NULL + }) %>% + stats::setNames(which) %>% + excludeNULL(dbg = FALSE) %>% + do.call(what = rbind.data.frame) %>% + resetRowNames() +} diff --git a/man/packageDependenciesByType.Rd b/man/packageDependenciesByType.Rd index 75fc8b8..e4d2d0f 100644 --- a/man/packageDependenciesByType.Rd +++ b/man/packageDependenciesByType.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/detach.R +% Please edit documentation in R/packageDependenciesByType.R \name{packageDependenciesByType} \alias{packageDependenciesByType} \title{Package Dependencies by Type} From 72eea3ad2d02f6730f9c1dbe2b44e382c98a3237 Mon Sep 17 00:00:00 2001 From: hsonne Date: Tue, 30 Apr 2024 21:34:04 +0200 Subject: [PATCH 63/90] Add argument "stop.on.error" --- R/getPackageLicences.R | 18 ++++++++++-------- R/helpers.R | 19 ++++++++++++------- man/getPackageLicences.Rd | 2 +- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/R/getPackageLicences.R b/R/getPackageLicences.R index 85bc3a7..0182242 100644 --- a/R/getPackageLicences.R +++ b/R/getPackageLicences.R @@ -6,16 +6,18 @@ #' @return data frame #' @importFrom kwb.utils moveColumnsToFront rbindAll #' @export -getPackageLicences <- function(packages) +getPackageLicences <- function(packages, stop.on.error = FALSE) { lapply(packages, function(package) { - description <- readDescription(package) - fields <- c("licence", "license") - columns <- intersect(colnames(description), fields) - as.data.frame(description[, columns, drop = FALSE]) %>% - renameColumns(list( - license = "licence" - )) + description <- readDescription(package, stop.on.error = stop.on.error) + if (is.null(description)) { + data.frame(licence = "") + } else { + columns <- intersect(colnames(description), c("licence", "license")) + description[, columns, drop = FALSE] %>% + as.data.frame() %>% + renameColumns(list(license = "licence")) + } # else NULL }) %>% stats::setNames(packages) %>% rbindAll(nameColumn = "package", namesAsFactor = FALSE) %>% diff --git a/R/helpers.R b/R/helpers.R index 2112bd8..9e3bc8b 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -70,16 +70,21 @@ packageInDestdir <- function(package, destdir, verbose = TRUE) # readDescription -------------------------------------------------------------- -readDescription <- function(package) +readDescription <- function(package, stop.on.error = TRUE) { - stopIfNotInstalled(package) + if (stop.on.error) { + stopIfNotInstalled(package) + } + + file <- system.file("DESCRIPTION", package = package) - description <- system.file("DESCRIPTION", package = package) %>% - safePath() %>% - read.dcf() + if (!file.exists(file) ) { + return(NULL) + } - colnames(description) <- tolower(colnames(description)) - description + file %>% + read.dcf() %>% + `colnames<-`(tolower(colnames(.))) } # stopIfNotInstalled ----------------------------------------------------------- diff --git a/man/getPackageLicences.Rd b/man/getPackageLicences.Rd index 725d1ec..8e205f7 100644 --- a/man/getPackageLicences.Rd +++ b/man/getPackageLicences.Rd @@ -4,7 +4,7 @@ \alias{getPackageLicences} \title{Which Licences are Specified for the Packages?} \usage{ -getPackageLicences(packages) +getPackageLicences(packages, stop.on.error = FALSE) } \arguments{ \item{packages}{names of (installed) packages} From 062cdce10922ead678d284dacfad31784887775c Mon Sep 17 00:00:00 2001 From: hsonne Date: Tue, 30 Apr 2024 21:36:23 +0200 Subject: [PATCH 64/90] Rename "which.one" to "type" --- R/packageDependenciesByType.R | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/R/packageDependenciesByType.R b/R/packageDependenciesByType.R index e10fcfd..b81ca2a 100644 --- a/R/packageDependenciesByType.R +++ b/R/packageDependenciesByType.R @@ -43,13 +43,13 @@ packageDependenciesByType <- function( stopifnot(n_packages == 1L) which %>% - lapply(function(which.one) { - #which.one <- "Imports" - #print(which.one) + lapply(function(type) { + #type <- "Imports" + #print(type) dependencies <- tools::package_dependencies( packages, db = db, - which = which.one, + which = type, recursive = recursive, reverse = reverse, verbose = verbose @@ -57,7 +57,7 @@ packageDependenciesByType <- function( if (length(dependencies)) { data.frame( package = packages, - type = rep(which.one, length(dependencies)) + type = rep(type, length(dependencies)) ) %>% cbind( getPackageLicences(dependencies) %>% From 4531ea3ddede0e32aa321304d46761e152d5a39a Mon Sep 17 00:00:00 2001 From: hsonne Date: Tue, 30 Apr 2024 22:27:39 +0200 Subject: [PATCH 65/90] Read from package db, not from DESCRIPTIONS --- NAMESPACE | 1 - R/getPackageLicences.R | 50 ++++++++++++++++++++++++----------- R/helpers.R | 11 +++++--- R/packageDependenciesByType.R | 2 +- man/getPackageLicences.Rd | 6 ++++- 5 files changed, 47 insertions(+), 23 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 898da87..a8e5771 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -59,7 +59,6 @@ importFrom(kwb.utils,getAttribute) importFrom(kwb.utils,get_homedir) importFrom(kwb.utils,hsRestoreAttributes) importFrom(kwb.utils,lastElement) -importFrom(kwb.utils,moveColumnsToFront) importFrom(kwb.utils,noFactorDataFrame) importFrom(kwb.utils,noSuchElements) importFrom(kwb.utils,orderBy) diff --git a/R/getPackageLicences.R b/R/getPackageLicences.R index 0182242..335328b 100644 --- a/R/getPackageLicences.R +++ b/R/getPackageLicences.R @@ -3,23 +3,41 @@ #' Which Licences are Specified for the Packages? #' #' @param packages names of (installed) packages +#' @param db optional. Package database, similar to what is returned by +#' \code{\link[utils]{installed.packages}}. Default: +#' \code{as.data.frame(installed.packages())} #' @return data frame -#' @importFrom kwb.utils moveColumnsToFront rbindAll +#' @importFrom utils installed.packages #' @export -getPackageLicences <- function(packages, stop.on.error = FALSE) +getPackageLicences <- function( + packages, + db = as.data.frame(utils::installed.packages()) +) { - lapply(packages, function(package) { - description <- readDescription(package, stop.on.error = stop.on.error) - if (is.null(description)) { - data.frame(licence = "") - } else { - columns <- intersect(colnames(description), c("licence", "license")) - description[, columns, drop = FALSE] %>% - as.data.frame() %>% - renameColumns(list(license = "licence")) - } # else NULL - }) %>% - stats::setNames(packages) %>% - rbindAll(nameColumn = "package", namesAsFactor = FALSE) %>% - moveColumnsToFront("package") + #kwb.utils::assignPackageObjects("kwb.package");stop.on.error = FALSE + #`%>%` <- magrittr::`%>%` + #db <- kwb.utils:::get_cached("package_db") + #packages <- db$Package + + colnames(db) <- tolower(colnames(db)) + licence_fields <- intersect(colnames(db), c("licence", "license")) + stopifnot(length(licence_fields) == 1L) + + backbone <- data.frame( + package = packages, + stringsAsFactors = FALSE + ) + + result <- backbone %>% + merge( + y = db[, c("package", licence_fields)], + by = "package", + all.x = TRUE + ) %>% + renameColumns(list(license = "licence")) %>% + orderBy("package") + + result[["licence"]] <- defaultIfNa(result[["licence"]], "") + + result } diff --git a/R/helpers.R b/R/helpers.R index 9e3bc8b..5aecd24 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -82,9 +82,11 @@ readDescription <- function(package, stop.on.error = TRUE) return(NULL) } - file %>% - read.dcf() %>% - `colnames<-`(tolower(colnames(.))) + result <- read.dcf(file) + + colnames(result) <- tolower(colnames(result)) + + result } # stopIfNotInstalled ----------------------------------------------------------- @@ -92,12 +94,13 @@ readDescription <- function(package, stop.on.error = TRUE) #' Is a Package Installed? #' #' @param package package name (character vector of length one) +#' @importFrom utils installed.packages #' @export stopIfNotInstalled <- function(package) { stopifnot(is.character(package), length(package) == 1L) - available <- rownames(installed.packages()) + available <- rownames(utils::installed.packages()) if (!package %in% available) { stopFormatted("The package '%s' is not installed.", package) diff --git a/R/packageDependenciesByType.R b/R/packageDependenciesByType.R index b81ca2a..9606d47 100644 --- a/R/packageDependenciesByType.R +++ b/R/packageDependenciesByType.R @@ -60,7 +60,7 @@ packageDependenciesByType <- function( type = rep(type, length(dependencies)) ) %>% cbind( - getPackageLicences(dependencies) %>% + getPackageLicences(dependencies, db = db) %>% renameColumns(list(package = "dependency")) ) } # else NULL diff --git a/man/getPackageLicences.Rd b/man/getPackageLicences.Rd index 8e205f7..37a5c02 100644 --- a/man/getPackageLicences.Rd +++ b/man/getPackageLicences.Rd @@ -4,10 +4,14 @@ \alias{getPackageLicences} \title{Which Licences are Specified for the Packages?} \usage{ -getPackageLicences(packages, stop.on.error = FALSE) +getPackageLicences(packages, db = as.data.frame(utils::installed.packages())) } \arguments{ \item{packages}{names of (installed) packages} + +\item{db}{optional. Package database, similar to what is returned by +\code{\link[utils]{installed.packages}}. Default: +\code{as.data.frame(installed.packages())}} } \value{ data frame From b43763e9aba10688a725ee6a8517228c7e151510 Mon Sep 17 00:00:00 2001 From: hsonne Date: Thu, 2 May 2024 18:45:19 +0200 Subject: [PATCH 66/90] Do not lookup licenses in packageDependenciesByType() --- R/packageDependenciesByType.R | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/R/packageDependenciesByType.R b/R/packageDependenciesByType.R index 9606d47..9384c1a 100644 --- a/R/packageDependenciesByType.R +++ b/R/packageDependenciesByType.R @@ -44,8 +44,7 @@ packageDependenciesByType <- function( which %>% lapply(function(type) { - #type <- "Imports" - #print(type) + dependencies <- tools::package_dependencies( packages, db = db, @@ -54,19 +53,17 @@ packageDependenciesByType <- function( reverse = reverse, verbose = verbose )[[1L]] + if (length(dependencies)) { data.frame( package = packages, type = rep(type, length(dependencies)) - ) %>% - cbind( - getPackageLicences(dependencies, db = db) %>% - renameColumns(list(package = "dependency")) - ) - } # else NULL + ) + } + }) %>% stats::setNames(which) %>% excludeNULL(dbg = FALSE) %>% - do.call(what = rbind.data.frame) %>% + do.call(what = rbind) %>% resetRowNames() } From cebc73644a70d4e175effc7fd442f7cffd39c4f7 Mon Sep 17 00:00:00 2001 From: hsonne Date: Thu, 2 May 2024 18:46:52 +0200 Subject: [PATCH 67/90] Create tests with kwb.test::create_test_files() and modify some tests. Skip tests that would detach testthat! Skip test that would install the remotes package! --- DESCRIPTION | 4 +- R/install.R | 1 - tests/testthat.R | 12 ++++++ tests/testthat/Rplots.pdf | Bin 0 -> 3448 bytes tests/testthat/test-function-addNodeLabels.R | 17 +++++++++ tests/testthat/test-function-allDeps.R | 17 +++++++++ tests/testthat/test-function-anglesToPoints.R | 17 +++++++++ .../test-function-archivedCranVersions.R | 17 +++++++++ tests/testthat/test-function-cleanStop.R | 17 +++++++++ .../test-function-compareInstalledVersions.R | 17 +++++++++ .../testthat/test-function-copyBasePackages.R | 17 +++++++++ tests/testthat/test-function-cranVersions.R | 17 +++++++++ .../test-function-currentCranVersion.R | 12 ++++++ .../testthat/test-function-defaultLocalCRAN.R | 10 +++++ .../test-function-defaultPackageDir.R | 12 ++++++ ...test-function-detachAllNonSystemPackages.R | 11 ++++++ .../test-function-detachRecursively.R | 11 ++++++ tests/testthat/test-function-dirPackageZips.R | 9 +++++ .../test-function-downloadGitHubPackage.R | 17 +++++++++ ...st-function-downloadPackagesFromSnapshot.R | 17 +++++++++ .../testthat/test-function-drawDependencies.R | 17 +++++++++ tests/testthat/test-function-drawLink.R | 17 +++++++++ tests/testthat/test-function-draw_circles.R | 17 +++++++++ .../test-function-equidistantAngles.R | 17 +++++++++ .../test-function-exampleLinksAndNodes.R | 17 +++++++++ .../test-function-findPackageFilename.R | 17 +++++++++ tests/testthat/test-function-getAuthors.R | 17 +++++++++ tests/testthat/test-function-getBinaryPaths.R | 12 ++++++ .../test-function-getCranPackageDatabase.R | 35 ++++++++++++++++++ .../testthat/test-function-getFileToInstall.R | 17 +++++++++ .../test-function-getGithubReleaseInfo.R | 17 +++++++++ .../test-function-getLastVersionBefore.R | 17 +++++++++ .../test-function-getPackageFilesToInstall.R | 12 ++++++ .../test-function-getPackageLicences.R | 17 +++++++++ .../test-function-getRVersionMajorMinor.R | 11 ++++++ tests/testthat/test-function-getServername.R | 12 ++++++ tests/testthat/test-function-getUrl.R | 17 +++++++++ .../test-function-githubPackageVersions.R | 17 +++++++++ tests/testthat/test-function-githubRepo.R | 17 +++++++++ tests/testthat/test-function-githubVersions.R | 17 +++++++++ tests/testthat/test-function-gradToRad.R | 17 +++++++++ tests/testthat/test-function-hasGplLicence.R | 17 +++++++++ tests/testthat/test-function-includeExclude.R | 17 +++++++++ tests/testthat/test-function-initLocalCRAN.R | 17 +++++++++ .../test-function-installGithubPackages.R | 17 +++++++++ tests/testthat/test-function-installPackage.R | 17 +++++++++ .../test-function-installPackageIfRequired.R | 17 +++++++++ tests/testthat/test-function-installRemotes.R | 11 ++++++ .../test-function-installedDependencies.R | 17 +++++++++ .../test-function-installedKwbPackages.R | 11 ++++++ tests/testthat/test-function-isKwbPackage.R | 17 +++++++++ tests/testthat/test-function-isOnCran.R | 12 ++++++ ...t-function-loadDescriptionFromArchiveUrl.R | 17 +++++++++ .../test-function-loadDescriptionFromWeb.R | 17 +++++++++ tests/testthat/test-function-map_to_range.R | 17 +++++++++ .../test-function-packageDependencies.R | 12 ++++++ .../test-function-packageDependenciesByType.R | 15 ++++++++ .../testthat/test-function-packageInDestdir.R | 17 +++++++++ tests/testthat/test-function-packageString.R | 17 +++++++++ .../testthat/test-function-parsePackageDeps.R | 17 +++++++++ .../testthat/test-function-pathDescription.R | 17 +++++++++ .../test-function-plotAllDependencies.R | 17 +++++++++ .../testthat/test-function-plotDependencies.R | 17 +++++++++ tests/testthat/test-function-plotNodes.R | 17 +++++++++ .../test-function-plotPackageVersions.R | 17 +++++++++ .../test-function-plotSankeyNetwork.R | 17 +++++++++ tests/testthat/test-function-polar_to_xy.R | 17 +++++++++ tests/testthat/test-function-printAndWaitIf.R | 17 +++++++++ .../test-function-provideInLocalCRAN.R | 17 +++++++++ .../testthat/test-function-readDescription.R | 17 +++++++++ ...st-function-readGithubPackageDescription.R | 17 +++++++++ .../testthat/test-function-readLinesFromUrl.R | 9 +++++ ...st-function-relationMatrixToSourceTarget.R | 17 +++++++++ tests/testthat/test-function-seq_rad_len.R | 17 +++++++++ .../test-function-setOptionsForPackrat.R | 13 +++++++ .../testthat/test-function-shallBeInstalled.R | 17 +++++++++ .../testthat/test-function-sortPackageFiles.R | 17 +++++++++ .../test-function-sortedDependencies.R | 17 +++++++++ .../test-function-stopIfNotInstalled.R | 17 +++++++++ tests/testthat/test-function-systemPackages.R | 13 +++++++ .../testthat/test-function-toLinksAndNodes.R | 17 +++++++++ tests/testthat/test-function-toNodes.R | 17 +++++++++ tests/testthat/test-function-toSourceTarget.R | 17 +++++++++ .../test-function-untarDescriptionFromUrl.R | 17 +++++++++ 84 files changed, 1295 insertions(+), 2 deletions(-) create mode 100644 tests/testthat.R create mode 100644 tests/testthat/Rplots.pdf create mode 100644 tests/testthat/test-function-addNodeLabels.R create mode 100644 tests/testthat/test-function-allDeps.R create mode 100644 tests/testthat/test-function-anglesToPoints.R create mode 100644 tests/testthat/test-function-archivedCranVersions.R create mode 100644 tests/testthat/test-function-cleanStop.R create mode 100644 tests/testthat/test-function-compareInstalledVersions.R create mode 100644 tests/testthat/test-function-copyBasePackages.R create mode 100644 tests/testthat/test-function-cranVersions.R create mode 100644 tests/testthat/test-function-currentCranVersion.R create mode 100644 tests/testthat/test-function-defaultLocalCRAN.R create mode 100644 tests/testthat/test-function-defaultPackageDir.R create mode 100644 tests/testthat/test-function-detachAllNonSystemPackages.R create mode 100644 tests/testthat/test-function-detachRecursively.R create mode 100644 tests/testthat/test-function-dirPackageZips.R create mode 100644 tests/testthat/test-function-downloadGitHubPackage.R create mode 100644 tests/testthat/test-function-downloadPackagesFromSnapshot.R create mode 100644 tests/testthat/test-function-drawDependencies.R create mode 100644 tests/testthat/test-function-drawLink.R create mode 100644 tests/testthat/test-function-draw_circles.R create mode 100644 tests/testthat/test-function-equidistantAngles.R create mode 100644 tests/testthat/test-function-exampleLinksAndNodes.R create mode 100644 tests/testthat/test-function-findPackageFilename.R create mode 100644 tests/testthat/test-function-getAuthors.R create mode 100644 tests/testthat/test-function-getBinaryPaths.R create mode 100644 tests/testthat/test-function-getCranPackageDatabase.R create mode 100644 tests/testthat/test-function-getFileToInstall.R create mode 100644 tests/testthat/test-function-getGithubReleaseInfo.R create mode 100644 tests/testthat/test-function-getLastVersionBefore.R create mode 100644 tests/testthat/test-function-getPackageFilesToInstall.R create mode 100644 tests/testthat/test-function-getPackageLicences.R create mode 100644 tests/testthat/test-function-getRVersionMajorMinor.R create mode 100644 tests/testthat/test-function-getServername.R create mode 100644 tests/testthat/test-function-getUrl.R create mode 100644 tests/testthat/test-function-githubPackageVersions.R create mode 100644 tests/testthat/test-function-githubRepo.R create mode 100644 tests/testthat/test-function-githubVersions.R create mode 100644 tests/testthat/test-function-gradToRad.R create mode 100644 tests/testthat/test-function-hasGplLicence.R create mode 100644 tests/testthat/test-function-includeExclude.R create mode 100644 tests/testthat/test-function-initLocalCRAN.R create mode 100644 tests/testthat/test-function-installGithubPackages.R create mode 100644 tests/testthat/test-function-installPackage.R create mode 100644 tests/testthat/test-function-installPackageIfRequired.R create mode 100644 tests/testthat/test-function-installRemotes.R create mode 100644 tests/testthat/test-function-installedDependencies.R create mode 100644 tests/testthat/test-function-installedKwbPackages.R create mode 100644 tests/testthat/test-function-isKwbPackage.R create mode 100644 tests/testthat/test-function-isOnCran.R create mode 100644 tests/testthat/test-function-loadDescriptionFromArchiveUrl.R create mode 100644 tests/testthat/test-function-loadDescriptionFromWeb.R create mode 100644 tests/testthat/test-function-map_to_range.R create mode 100644 tests/testthat/test-function-packageDependencies.R create mode 100644 tests/testthat/test-function-packageDependenciesByType.R create mode 100644 tests/testthat/test-function-packageInDestdir.R create mode 100644 tests/testthat/test-function-packageString.R create mode 100644 tests/testthat/test-function-parsePackageDeps.R create mode 100644 tests/testthat/test-function-pathDescription.R create mode 100644 tests/testthat/test-function-plotAllDependencies.R create mode 100644 tests/testthat/test-function-plotDependencies.R create mode 100644 tests/testthat/test-function-plotNodes.R create mode 100644 tests/testthat/test-function-plotPackageVersions.R create mode 100644 tests/testthat/test-function-plotSankeyNetwork.R create mode 100644 tests/testthat/test-function-polar_to_xy.R create mode 100644 tests/testthat/test-function-printAndWaitIf.R create mode 100644 tests/testthat/test-function-provideInLocalCRAN.R create mode 100644 tests/testthat/test-function-readDescription.R create mode 100644 tests/testthat/test-function-readGithubPackageDescription.R create mode 100644 tests/testthat/test-function-readLinesFromUrl.R create mode 100644 tests/testthat/test-function-relationMatrixToSourceTarget.R create mode 100644 tests/testthat/test-function-seq_rad_len.R create mode 100644 tests/testthat/test-function-setOptionsForPackrat.R create mode 100644 tests/testthat/test-function-shallBeInstalled.R create mode 100644 tests/testthat/test-function-sortPackageFiles.R create mode 100644 tests/testthat/test-function-sortedDependencies.R create mode 100644 tests/testthat/test-function-stopIfNotInstalled.R create mode 100644 tests/testthat/test-function-systemPackages.R create mode 100644 tests/testthat/test-function-toLinksAndNodes.R create mode 100644 tests/testthat/test-function-toNodes.R create mode 100644 tests/testthat/test-function-toSourceTarget.R create mode 100644 tests/testthat/test-function-untarDescriptionFromUrl.R diff --git a/DESCRIPTION b/DESCRIPTION index e899522..7752413 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -30,10 +30,12 @@ Suggests: covr, knitr, pkgmeta, - rmarkdown + rmarkdown, + testthat (>= 3.0.0) Remotes: github::kwb-r/kwb.utils, github::kwb-r/pkgmeta Encoding: UTF-8 RoxygenNote: 7.3.1 VignetteBuilder: knitr +Config/testthat/edition: 3 diff --git a/R/install.R b/R/install.R index aa85910..22dea84 100644 --- a/R/install.R +++ b/R/install.R @@ -39,7 +39,6 @@ updateKwbPackages <- function } } - # getServername ------------------------------------------------------------ #' Get KWB Servername diff --git a/tests/testthat.R b/tests/testthat.R new file mode 100644 index 0000000..b644e2c --- /dev/null +++ b/tests/testthat.R @@ -0,0 +1,12 @@ +# This file is part of the standard setup for testthat. +# It is recommended that you do not modify it. +# +# Where should you do additional test configuration? +# Learn more about the roles of various files in: +# * https://r-pkgs.org/tests.html +# * https://testthat.r-lib.org/reference/test_package.html#special-files + +library(testthat) +library(kwb.package) + +test_check("kwb.package") diff --git a/tests/testthat/Rplots.pdf b/tests/testthat/Rplots.pdf new file mode 100644 index 0000000000000000000000000000000000000000..f6d5b84adefa96033052ad9b8528051a02b11f06 GIT binary patch literal 3448 zcmZ`+XH-+^7DW({sPtk6gbPxF0wJM=rj$^mNGEiOAwb5E#3V=!y-9llil9_!3d2JL zqzQ_2DWQp?CSNmL9%szM`*@1+{{6L@-dov?IgUR?q?q7;o5KFN;^sKS55t@Sa z0W?`zo`24O75#Z7Lp&8rCa{`7k=V;P43*vw`Vs$+Gd`iauUYFZ}Ipl zn~WyXk%Y9%C_e;;%tnPYPWM66_IW!Ts~mi`ZaOL8_Je^zdewbc1f}& z+{?aePRZ|7)%3K7<$=PBiqOS1Mj>yc@%eDNef#UR-_gOFS%^$3%-Bnd;2TI4 zyh+e*_~XreH+FS^&BTCX$v}LOL+J6r2ag4s*!X5S*bN~`2QPWUW@Ch}9zX(O!ch%H z$F9Xxdn?@G3M>*(kJTg{qef$9)e+n((F5KGrw`bx@)krXu7d^*_~YXH_(kj!seo~x z#Qk`etK#oCIE@8tC9WNkGd4137cp2avcDrynXpvsyXd|Mq5jgscGS4B$j)DoAri`c zLY1ey!|k2`p0m!|25~4oPOPJU9gdJviD`U%ox~B&zZz%Ld1F?<1#~95LLiD?K<9Rf zs(|PdQ=^PvSsnrDs;h#f>^Os$S0ziOnv=~lD*D`oxlBx8wpP~;Ka~=RpSzu1>|Cr_ zQfbF+n}6r@gwq7%SI}nxYtxIjhen4N*{Di7;QSO7Q&iEdk>iVXivn8+h6q<|F(wt3 zek{^TLSCefy$)O_KAx@}5AI1tm)E-drZXwAoP4yKeD4At_5c*dA0`;ashduVJuycm zJwTlI&^woOs>^BCjif+Ak%XGS4+Y=wuch*JZ>|q~!tR=e^FoP*(7B(z!0u?Wm>%m$Q0EJsSzRb~!t9Us+AXXj$n1=@o^1nb$IH zKvuu04xHrZLki_6M++^ORh_ZqsD6GoFn$QvU;L_Y`vmLa&o>!y+wgV+S5xSipPt^M>!Th zY{405Mj%7iN!iK9seMWQndY-ol{L@a-wC<%>6yjE%V(w&Z|2BjzWep#D5B~Ul{X-LKw>p7Q#)~CdNNL9Nd1I5%71lSVkB>JY;t4#=~(5MPRVD- zTmN1u&aZ4U-izBV<#p<{HY=(#UML;LB!D`zGKTN?Y{AN@8i8K}>RdY2S{gj~8DctFq@HL?(Ej8^zs^+mkus+;b zjaPM8i=fed(Ma=>maFfWH+e`H^Av8a_BtSR>WF5YmL;qTCJs*=IzGtxzI7;3c|`P_ zs8I@6inx{FcvfyF9-HnqrW~t$Sh-cH&=u^`?H*9K)X4A;Am$TZ`_p<8E(rNM_>W^Y ztEzLApFil?e(AB{G1FYNaG6dc_z`*=UtxmA3x1Wl@TjBx`M22ElGwiDA@tbjW7ufz z4Y3-n2{^C<*D=+}-?TA+33-ne4Ib zSw=Y0h-_>l*avwArH94taq!Xj3e2*4<0|g@RW2CP{k$f0-oNhRnQ4NQ#Qmq)T4=?yg|BT%Men;OG_D73C{y+QoTX!&_rf zWet`UP54!nRiOfIA~!K}?J0D@Mz&f0x`MvNW$QNudbx82_8A+Fk3}617gR7RCd=B- z9kzZ|xUHx!-=@!TBO~XMqq#si&mO!%Z4;hYH&~ZkS2~b)W5q*L4kW07HJ(bj-`cG{ zMW2Z3Lf-d+-<;2O$l8?G(%CUDAQz|-y_=^ttOpb}Xq%6`qTM+FQmMuJG zIE_@6RfVFKYgF9y+k1#Z(G778xQmgHdKD#Tc(aPHr%i_Q=*`=;pCgvtQ$&(Yy0tW$ z@ONG%y@b3#G~rguE3Kt0gXP35t1VAi%n;ub+IO!Hp{}2&z09n~-Wx2&)13#M-%c*S znr=J}L8;K8Qm-WMw^6t;X8q|mbZ>loXp2VKHKyFNyl?3S_L%a-+BP&S(E=?#o2Q|y z!>WB(%3nTj4QZ|U`02&CbA=PiZHG|fy*3p3h%wAnl8{Wxp=s|)YMN?oM-DMsn$MQp zt^d#&@iyW^bP@+`D1B&1`KB_qnp9O9xZ(YzV_+sYa{P4T| zgQs|&T)8b&ca2KJ7{oqcy%O7;8)3ySXDCq5ieja|zHty`-BU*L^{)tp zBN!4WxIY096p8co#gefE4AZc?1L_*k030EZ0(kz9(GMnLeL<=K0;Kx$0W>u<)HDEJ z;3o!WE+?!9ApFE&noP(4Hw+GAt_^?35ZeF1)U=tt|8IHf@PF{B!C;8L@~C7q4v!@> z_agx6fD6R}2mpGP;7bHpi<3P7wI>p(0BddeVe=_eG@1J2ZfZ 0L) + expect_true(grepl("windows", result[1L])) +}) diff --git a/tests/testthat/test-function-getCranPackageDatabase.R b/tests/testthat/test-function-getCranPackageDatabase.R new file mode 100644 index 0000000..f621f19 --- /dev/null +++ b/tests/testthat/test-function-getCranPackageDatabase.R @@ -0,0 +1,35 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 17:58:26. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("getCranPackageDatabase() works", { + + f <- kwb.package::getCranPackageDatabase + + expect_error( + f() + # No such element in list 'urls': +# - 'cran_packages' +# Available elements (sorted): +# - 'cached_desc' +# - 'cran' +# - 'cran_archive' +# - 'cran_archive_file' +# - 'cran_contrib' +# - 'cran_package' +# - 'cran_package_file' +# - 'cran_rstudio' +# - 'github_api' +# - 'github_desc' +# - 'github_raw' +# - 'github_releases' +# - 'github_tags' +# - 'mran_snapshot' +# - 'package_filename' +# + ) + +}) diff --git a/tests/testthat/test-function-getFileToInstall.R b/tests/testthat/test-function-getFileToInstall.R new file mode 100644 index 0000000..ca63682 --- /dev/null +++ b/tests/testthat/test-function-getFileToInstall.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 18:06:07. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("getFileToInstall() works", { + + f <- kwb.package:::getFileToInstall + + expect_error( + f() + # Argument "package" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-getGithubReleaseInfo.R b/tests/testthat/test-function-getGithubReleaseInfo.R new file mode 100644 index 0000000..a05501a --- /dev/null +++ b/tests/testthat/test-function-getGithubReleaseInfo.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 17:58:28. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("getGithubReleaseInfo() works", { + + f <- kwb.package:::getGithubReleaseInfo + + expect_error( + f() + # Argument "repo" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-getLastVersionBefore.R b/tests/testthat/test-function-getLastVersionBefore.R new file mode 100644 index 0000000..b1fec35 --- /dev/null +++ b/tests/testthat/test-function-getLastVersionBefore.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 17:58:25. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("getLastVersionBefore() works", { + + f <- kwb.package:::getLastVersionBefore + + expect_error( + f() + # Argument "version_dates" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-getPackageFilesToInstall.R b/tests/testthat/test-function-getPackageFilesToInstall.R new file mode 100644 index 0000000..6fa1cdf --- /dev/null +++ b/tests/testthat/test-function-getPackageFilesToInstall.R @@ -0,0 +1,12 @@ +#library(testthat) + +test_that("getPackageFilesToInstall() works", { + + f <- kwb.package::getPackageFilesToInstall + + suppressWarnings(result <- f()) + + expect_type(result, "character") + expect_true(all(file.exists(result))) + +}) diff --git a/tests/testthat/test-function-getPackageLicences.R b/tests/testthat/test-function-getPackageLicences.R new file mode 100644 index 0000000..33933f3 --- /dev/null +++ b/tests/testthat/test-function-getPackageLicences.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 17:58:28. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("getPackageLicences() works", { + + f <- kwb.package::getPackageLicences + + expect_error( + f() + # Argument "packages" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-getRVersionMajorMinor.R b/tests/testthat/test-function-getRVersionMajorMinor.R new file mode 100644 index 0000000..3de19dd --- /dev/null +++ b/tests/testthat/test-function-getRVersionMajorMinor.R @@ -0,0 +1,11 @@ +#library(testthat) + +test_that("getRVersionMajorMinor() works", { + + f <- kwb.package::getRVersionMajorMinor + + result <- f() + + expect_true(grepl("^\\d+\\.\\d+$", result)) + +}) diff --git a/tests/testthat/test-function-getServername.R b/tests/testthat/test-function-getServername.R new file mode 100644 index 0000000..4279c23 --- /dev/null +++ b/tests/testthat/test-function-getServername.R @@ -0,0 +1,12 @@ +#library(testthat) + +test_that("getServername() works", { + + f <- kwb.package:::getServername + + result <- f() + + expect_type(result, "character") + expect_length(result, 1L) + +}) diff --git a/tests/testthat/test-function-getUrl.R b/tests/testthat/test-function-getUrl.R new file mode 100644 index 0000000..4da1ed0 --- /dev/null +++ b/tests/testthat/test-function-getUrl.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 17:58:28. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("getUrl() works", { + + f <- kwb.package:::getUrl + + expect_error( + f() + # Argument "key" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-githubPackageVersions.R b/tests/testthat/test-function-githubPackageVersions.R new file mode 100644 index 0000000..26d29ee --- /dev/null +++ b/tests/testthat/test-function-githubPackageVersions.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 17:58:28. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("githubPackageVersions() works", { + + f <- kwb.package:::githubPackageVersions + + expect_error( + f() + # Argument "repo" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-githubRepo.R b/tests/testthat/test-function-githubRepo.R new file mode 100644 index 0000000..3f83fe0 --- /dev/null +++ b/tests/testthat/test-function-githubRepo.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 17:58:28. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("githubRepo() works", { + + f <- kwb.package:::githubRepo + + expect_error( + f() + # Argument "github_user" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-githubVersions.R b/tests/testthat/test-function-githubVersions.R new file mode 100644 index 0000000..955e8f0 --- /dev/null +++ b/tests/testthat/test-function-githubVersions.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 17:58:28. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("githubVersions() works", { + + f <- kwb.package::githubVersions + + expect_error( + f() + # Argument "name" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-gradToRad.R b/tests/testthat/test-function-gradToRad.R new file mode 100644 index 0000000..1d0c0cb --- /dev/null +++ b/tests/testthat/test-function-gradToRad.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 18:06:13. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("gradToRad() works", { + + f <- kwb.package::gradToRad + + expect_error( + f() + # Argument "grad" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-hasGplLicence.R b/tests/testthat/test-function-hasGplLicence.R new file mode 100644 index 0000000..85bbb89 --- /dev/null +++ b/tests/testthat/test-function-hasGplLicence.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 17:58:28. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("hasGplLicence() works", { + + f <- kwb.package::hasGplLicence + + expect_error( + f() + # Argument "packages" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-includeExclude.R b/tests/testthat/test-function-includeExclude.R new file mode 100644 index 0000000..117e8de --- /dev/null +++ b/tests/testthat/test-function-includeExclude.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 18:06:14. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("includeExclude() works", { + + f <- kwb.package:::includeExclude + + expect_error( + f() + # Argument "x" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-initLocalCRAN.R b/tests/testthat/test-function-initLocalCRAN.R new file mode 100644 index 0000000..773a019 --- /dev/null +++ b/tests/testthat/test-function-initLocalCRAN.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 18:06:12. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("initLocalCRAN() works", { + + f <- kwb.package::initLocalCRAN + + expect_error( + f() + # Argument "local_cran" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-installGithubPackages.R b/tests/testthat/test-function-installGithubPackages.R new file mode 100644 index 0000000..6a859a6 --- /dev/null +++ b/tests/testthat/test-function-installGithubPackages.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 18:06:07. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("installGithubPackages() works", { + + f <- kwb.package::installGithubPackages + + expect_error( + f() + # Argument "lib" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-installPackage.R b/tests/testthat/test-function-installPackage.R new file mode 100644 index 0000000..8d4f262 --- /dev/null +++ b/tests/testthat/test-function-installPackage.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 18:06:07. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("installPackage() works", { + + f <- kwb.package:::installPackage + + expect_error( + f() + # Argument "packageName" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-installPackageIfRequired.R b/tests/testthat/test-function-installPackageIfRequired.R new file mode 100644 index 0000000..c76ec79 --- /dev/null +++ b/tests/testthat/test-function-installPackageIfRequired.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 18:06:07. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("installPackageIfRequired() works", { + + f <- kwb.package:::installPackageIfRequired + + expect_error( + f() + # Argument "packageName" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-installRemotes.R b/tests/testthat/test-function-installRemotes.R new file mode 100644 index 0000000..6f24c09 --- /dev/null +++ b/tests/testthat/test-function-installRemotes.R @@ -0,0 +1,11 @@ +#library(testthat) + +testthat::skip("Do not install a package during testing!") + +test_that("installRemotes() works", { + + f <- kwb.package::installRemotes + + f() + +}) diff --git a/tests/testthat/test-function-installedDependencies.R b/tests/testthat/test-function-installedDependencies.R new file mode 100644 index 0000000..a2d0d07 --- /dev/null +++ b/tests/testthat/test-function-installedDependencies.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 18:06:07. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("installedDependencies() works", { + + f <- kwb.package::installedDependencies + + expect_error( + f() + # Argument "package" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-installedKwbPackages.R b/tests/testthat/test-function-installedKwbPackages.R new file mode 100644 index 0000000..cbfad8f --- /dev/null +++ b/tests/testthat/test-function-installedKwbPackages.R @@ -0,0 +1,11 @@ +#library(testthat) + +test_that("installedKwbPackages() works", { + + f <- kwb.package::installedKwbPackages + + result <- f() + + expect_type(result, "character") + +}) diff --git a/tests/testthat/test-function-isKwbPackage.R b/tests/testthat/test-function-isKwbPackage.R new file mode 100644 index 0000000..ea18e9b --- /dev/null +++ b/tests/testthat/test-function-isKwbPackage.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 18:06:07. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("isKwbPackage() works", { + + f <- kwb.package:::isKwbPackage + + expect_error( + f() + # Argument "packageName" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-isOnCran.R b/tests/testthat/test-function-isOnCran.R new file mode 100644 index 0000000..e4dab9e --- /dev/null +++ b/tests/testthat/test-function-isOnCran.R @@ -0,0 +1,12 @@ +#library(testthat) + +test_that("isOnCran() works", { + + f <- kwb.package:::isOnCran + + result <- f() + + expect_type(result, "logical") + expect_length(result, 1L) + +}) diff --git a/tests/testthat/test-function-loadDescriptionFromArchiveUrl.R b/tests/testthat/test-function-loadDescriptionFromArchiveUrl.R new file mode 100644 index 0000000..689e565 --- /dev/null +++ b/tests/testthat/test-function-loadDescriptionFromArchiveUrl.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 18:06:11. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("loadDescriptionFromArchiveUrl() works", { + + f <- kwb.package:::loadDescriptionFromArchiveUrl + + expect_error( + f() + # Argument "url" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-loadDescriptionFromWeb.R b/tests/testthat/test-function-loadDescriptionFromWeb.R new file mode 100644 index 0000000..4129829 --- /dev/null +++ b/tests/testthat/test-function-loadDescriptionFromWeb.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 18:06:11. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("loadDescriptionFromWeb() works", { + + f <- kwb.package:::loadDescriptionFromWeb + + expect_error( + f() + # Argument "name" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-map_to_range.R b/tests/testthat/test-function-map_to_range.R new file mode 100644 index 0000000..3947b97 --- /dev/null +++ b/tests/testthat/test-function-map_to_range.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 18:06:13. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("map_to_range() works", { + + f <- kwb.package:::map_to_range + + expect_error( + f() + # Argument "y_range" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-packageDependencies.R b/tests/testthat/test-function-packageDependencies.R new file mode 100644 index 0000000..67e2006 --- /dev/null +++ b/tests/testthat/test-function-packageDependencies.R @@ -0,0 +1,12 @@ +#library(testthat) + +test_that("packageDependencies() works", { + + f <- kwb.package::packageDependencies + + result <- f() + + expect_type(result, "list") + expect_true(all(sapply(result, typeof) == "character")) + +}) diff --git a/tests/testthat/test-function-packageDependenciesByType.R b/tests/testthat/test-function-packageDependenciesByType.R new file mode 100644 index 0000000..5955392 --- /dev/null +++ b/tests/testthat/test-function-packageDependenciesByType.R @@ -0,0 +1,15 @@ +#library(testthat) + +test_that("packageDependenciesByType() works", { + + f <- kwb.package::packageDependenciesByType + + expect_null(f()) + + result <- f("testthat") + + expect_s3_class(result, "data.frame") + expect_true(nrow(result) > 1L) + expect_identical(names(result), c("package", "type")) + +}) diff --git a/tests/testthat/test-function-packageInDestdir.R b/tests/testthat/test-function-packageInDestdir.R new file mode 100644 index 0000000..b894a3b --- /dev/null +++ b/tests/testthat/test-function-packageInDestdir.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 17:58:28. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("packageInDestdir() works", { + + f <- kwb.package:::packageInDestdir + + expect_error( + f() + # Argument "destdir" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-packageString.R b/tests/testthat/test-function-packageString.R new file mode 100644 index 0000000..f018500 --- /dev/null +++ b/tests/testthat/test-function-packageString.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 18:06:14. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("packageString() works", { + + f <- kwb.package::packageString + + expect_error( + f() + # Argument "package" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-parsePackageDeps.R b/tests/testthat/test-function-parsePackageDeps.R new file mode 100644 index 0000000..0723d44 --- /dev/null +++ b/tests/testthat/test-function-parsePackageDeps.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 18:06:13. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("parsePackageDeps() works", { + + f <- kwb.package:::parsePackageDeps + + expect_error( + f() + # Argument "pkg" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-pathDescription.R b/tests/testthat/test-function-pathDescription.R new file mode 100644 index 0000000..6a59e38 --- /dev/null +++ b/tests/testthat/test-function-pathDescription.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 18:06:11. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("pathDescription() works", { + + f <- kwb.package:::pathDescription + + expect_error( + f() + # Argument "name" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-plotAllDependencies.R b/tests/testthat/test-function-plotAllDependencies.R new file mode 100644 index 0000000..6f5d3fd --- /dev/null +++ b/tests/testthat/test-function-plotAllDependencies.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 18:06:13. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("plotAllDependencies() works", { + + f <- kwb.package::plotAllDependencies + + expect_error( + f() + # Argument "dependencies" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-plotDependencies.R b/tests/testthat/test-function-plotDependencies.R new file mode 100644 index 0000000..5b67bca --- /dev/null +++ b/tests/testthat/test-function-plotDependencies.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 18:06:13. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("plotDependencies() works", { + + f <- kwb.package::plotDependencies + + expect_error( + f() + # Argument "nodes" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-plotNodes.R b/tests/testthat/test-function-plotNodes.R new file mode 100644 index 0000000..e8488e9 --- /dev/null +++ b/tests/testthat/test-function-plotNodes.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 18:06:13. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("plotNodes() works", { + + f <- kwb.package::plotNodes + + expect_error( + f() + # Argument "nodes" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-plotPackageVersions.R b/tests/testthat/test-function-plotPackageVersions.R new file mode 100644 index 0000000..5394ed0 --- /dev/null +++ b/tests/testthat/test-function-plotPackageVersions.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 18:06:13. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("plotPackageVersions() works", { + + f <- kwb.package::plotPackageVersions + + expect_error( + f() + # Argument "versions" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-plotSankeyNetwork.R b/tests/testthat/test-function-plotSankeyNetwork.R new file mode 100644 index 0000000..eeedf53 --- /dev/null +++ b/tests/testthat/test-function-plotSankeyNetwork.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 18:06:14. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("plotSankeyNetwork() works", { + + f <- kwb.package::plotSankeyNetwork + + expect_error( + f() + # Argument "functionName" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-polar_to_xy.R b/tests/testthat/test-function-polar_to_xy.R new file mode 100644 index 0000000..6e237c0 --- /dev/null +++ b/tests/testthat/test-function-polar_to_xy.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 18:06:13. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("polar_to_xy() works", { + + f <- kwb.package:::polar_to_xy + + expect_error( + f() + # Argument "phi" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-printAndWaitIf.R b/tests/testthat/test-function-printAndWaitIf.R new file mode 100644 index 0000000..f160fac --- /dev/null +++ b/tests/testthat/test-function-printAndWaitIf.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 17:58:28. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("printAndWaitIf() works", { + + f <- kwb.package:::printAndWaitIf + + expect_error( + f() + # Argument "dbg" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-provideInLocalCRAN.R b/tests/testthat/test-function-provideInLocalCRAN.R new file mode 100644 index 0000000..596e1ab --- /dev/null +++ b/tests/testthat/test-function-provideInLocalCRAN.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 18:06:12. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("provideInLocalCRAN() works", { + + f <- kwb.package::provideInLocalCRAN + + expect_error( + f() + # Argument "package" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-readDescription.R b/tests/testthat/test-function-readDescription.R new file mode 100644 index 0000000..9fa0b8b --- /dev/null +++ b/tests/testthat/test-function-readDescription.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 17:58:28. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("readDescription() works", { + + f <- kwb.package:::readDescription + + expect_error( + f() + # Argument "package" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-readGithubPackageDescription.R b/tests/testthat/test-function-readGithubPackageDescription.R new file mode 100644 index 0000000..1aea829 --- /dev/null +++ b/tests/testthat/test-function-readGithubPackageDescription.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 18:06:13. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("readGithubPackageDescription() works", { + + f <- kwb.package:::readGithubPackageDescription + + expect_error( + f() + # Argument "repo" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-readLinesFromUrl.R b/tests/testthat/test-function-readLinesFromUrl.R new file mode 100644 index 0000000..e7f006c --- /dev/null +++ b/tests/testthat/test-function-readLinesFromUrl.R @@ -0,0 +1,9 @@ +#library(testthat) + +test_that("readLinesFromUrl() works", { + + f <- kwb.package:::readLinesFromUrl + + expect_null(f()) + +}) diff --git a/tests/testthat/test-function-relationMatrixToSourceTarget.R b/tests/testthat/test-function-relationMatrixToSourceTarget.R new file mode 100644 index 0000000..f890589 --- /dev/null +++ b/tests/testthat/test-function-relationMatrixToSourceTarget.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 18:06:14. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("relationMatrixToSourceTarget() works", { + + f <- kwb.package:::relationMatrixToSourceTarget + + expect_error( + f() + # Argument "x" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-seq_rad_len.R b/tests/testthat/test-function-seq_rad_len.R new file mode 100644 index 0000000..fcb74de --- /dev/null +++ b/tests/testthat/test-function-seq_rad_len.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 18:06:13. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("seq_rad_len() works", { + + f <- kwb.package:::seq_rad_len + + expect_error( + f() + # Argument "n" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-setOptionsForPackrat.R b/tests/testthat/test-function-setOptionsForPackrat.R new file mode 100644 index 0000000..4f41341 --- /dev/null +++ b/tests/testthat/test-function-setOptionsForPackrat.R @@ -0,0 +1,13 @@ +#library(testthat) + +test_that("setOptionsForPackrat() works", { + + f <- kwb.package::setOptionsForPackrat + + expect_silent(result <- f()) + + expect_type(result, "list") + + options(result) + +}) diff --git a/tests/testthat/test-function-shallBeInstalled.R b/tests/testthat/test-function-shallBeInstalled.R new file mode 100644 index 0000000..a1036ab --- /dev/null +++ b/tests/testthat/test-function-shallBeInstalled.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 18:06:07. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("shallBeInstalled() works", { + + f <- kwb.package:::shallBeInstalled + + expect_error( + f() + # Argument "packageName" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-sortPackageFiles.R b/tests/testthat/test-function-sortPackageFiles.R new file mode 100644 index 0000000..8e26858 --- /dev/null +++ b/tests/testthat/test-function-sortPackageFiles.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 18:06:07. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("sortPackageFiles() works", { + + f <- kwb.package:::sortPackageFiles + + expect_error( + f() + # Argument "packageFiles" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-sortedDependencies.R b/tests/testthat/test-function-sortedDependencies.R new file mode 100644 index 0000000..10e6200 --- /dev/null +++ b/tests/testthat/test-function-sortedDependencies.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 17:58:28. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("sortedDependencies() works", { + + f <- kwb.package::sortedDependencies + + expect_error( + f() + # Argument "package" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-stopIfNotInstalled.R b/tests/testthat/test-function-stopIfNotInstalled.R new file mode 100644 index 0000000..9e69e99 --- /dev/null +++ b/tests/testthat/test-function-stopIfNotInstalled.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 17:58:28. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("stopIfNotInstalled() works", { + + f <- kwb.package::stopIfNotInstalled + + expect_error( + f() + # Argument "package" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-systemPackages.R b/tests/testthat/test-function-systemPackages.R new file mode 100644 index 0000000..4454392 --- /dev/null +++ b/tests/testthat/test-function-systemPackages.R @@ -0,0 +1,13 @@ +#library(testthat) + +test_that("systemPackages() works", { + + f <- kwb.package::systemPackages + + result <- f() + + expect_type(result, "character") + expect_true("base" %in% result) + expect_true(all(result %in% rownames(installed.packages()))) + +}) diff --git a/tests/testthat/test-function-toLinksAndNodes.R b/tests/testthat/test-function-toLinksAndNodes.R new file mode 100644 index 0000000..49bf8d4 --- /dev/null +++ b/tests/testthat/test-function-toLinksAndNodes.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 18:06:14. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("toLinksAndNodes() works", { + + f <- kwb.package::toLinksAndNodes + + expect_error( + f() + # Argument "links" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-toNodes.R b/tests/testthat/test-function-toNodes.R new file mode 100644 index 0000000..f0df743 --- /dev/null +++ b/tests/testthat/test-function-toNodes.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 18:06:13. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("toNodes() works", { + + f <- kwb.package::toNodes + + expect_error( + f() + # Argument "nodeNames" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-toSourceTarget.R b/tests/testthat/test-function-toSourceTarget.R new file mode 100644 index 0000000..a38a523 --- /dev/null +++ b/tests/testthat/test-function-toSourceTarget.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 18:06:14. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("toSourceTarget() works", { + + f <- kwb.package:::toSourceTarget + + expect_error( + f() + # Argument "x" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-untarDescriptionFromUrl.R b/tests/testthat/test-function-untarDescriptionFromUrl.R new file mode 100644 index 0000000..89a2396 --- /dev/null +++ b/tests/testthat/test-function-untarDescriptionFromUrl.R @@ -0,0 +1,17 @@ +# +# This file was generated by kwb.test::create_test_files(), +# launched by hsonne on 2024-05-02 18:06:11. +# Please modify the dummy functions so that real cases are +# tested. Then, delete this comment. +# + +test_that("untarDescriptionFromUrl() works", { + + f <- kwb.package:::untarDescriptionFromUrl + + expect_error( + f() + # Argument "url" fehlt (ohne Standardwert) + ) + +}) From f7f9159cd0614af7aa1ce22cc7a1066663401477 Mon Sep 17 00:00:00 2001 From: Hauke Sonnenberg Date: Fri, 3 May 2024 05:17:42 +0200 Subject: [PATCH 68/90] Set env SERVERNAME. Does this fix R CMD Check? --- .github/workflows/R-CMD-check.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 3b03cdc..8b25c04 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -32,6 +32,7 @@ jobs: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} R_REMOTES_NO_ERRORS_FROM_WARNINGS: true RSPM: ${{ matrix.config.rspm }} + SERVERNAME: 'kwb-servername' steps: - uses: actions/checkout@v2 From 49d8de486cff7d097ff2365a5be8c59ed28e7f8b Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 3 May 2024 11:43:56 +0200 Subject: [PATCH 69/90] Set default radius to 1, multiply with vector --- R/plot_package_versions.R | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/R/plot_package_versions.R b/R/plot_package_versions.R index 9741c7e..0396010 100644 --- a/R/plot_package_versions.R +++ b/R/plot_package_versions.R @@ -96,9 +96,8 @@ draw_circles <- function(r, n_corners = 36L, col = "lightgrey") } # polar_to_xy ------------------------------------------------------------------ -polar_to_xy <- function(phi, r) +polar_to_xy <- function(phi, r = 1) { - data <- c(cos(phi) * r, sin(phi) * r) - + data <- r * c(cos(phi), sin(phi)) matrix(data, ncol = 2L, dimnames = list(NULL, c("x", "y"))) } From a0fd4ca04390b69834f1b0245cd22ee3cd461bd1 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 3 May 2024 11:44:46 +0200 Subject: [PATCH 70/90] Cosmetics --- R/utils.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/utils.R b/R/utils.R index 700b625..2cffa54 100644 --- a/R/utils.R +++ b/R/utils.R @@ -84,6 +84,7 @@ removeColumns <- kwb.utils::removeColumns # renameColumns ---------------------------------------------------------------- #' @importFrom kwb.utils renameColumns renameColumns <- kwb.utils::renameColumns + # resetRowNames ---------------------------------------------------------------- #' @importFrom kwb.utils resetRowNames resetRowNames <- kwb.utils::resetRowNames @@ -108,11 +109,10 @@ safePath <- kwb.utils::safePath #' @importFrom kwb.utils safeRowBind safeRowBind <- kwb.utils::safeRowBind -# selectColumns --------------------------------------------------------------- +# selectColumns ---------------------------------------------------------------- #' @importFrom kwb.utils selectColumns selectColumns <- kwb.utils::selectColumns - # selectElements --------------------------------------------------------------- #' @importFrom kwb.utils selectElements selectElements <- kwb.utils::selectElements From 1acd146388766162a3c395832149d4750d54aa67 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 3 May 2024 14:08:37 +0200 Subject: [PATCH 71/90] Move functions to utils.R - anglesToPoints() - equidistantAngles() - gradToRad() --- R/plot.R | 61 ------------------------------------------------------ R/utils.R | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 61 deletions(-) diff --git a/R/plot.R b/R/plot.R index a92c8e9..4b37eda 100644 --- a/R/plot.R +++ b/R/plot.R @@ -80,67 +80,6 @@ toNodes <- function(nodeNames) nodes } -# equidistantAngles ------------------------------------------------------------ - -#' Equidistantly Distributed Angles in Degrees Between 0 and 360 -#' -#' @param n number of angles to be returned -#' @param from start angle in degrees. Default: 0 -#' -#' @export -#' -#' @examples -#' x <- equidistantAngles(90) -#' -#' plot(x, sin(gradToRad(x)), xlab = "angle in degree", ylab = "sin(angle)") -#' -equidistantAngles <- function(n, from = 0) -{ - seq(from = from, by = 360/n, length.out = n) -} - -# anglesToPoints --------------------------------------------------------------- - -#' Angle in Unit Circle to Point Coordinate -#' -#' Convert angles in a unit circle to point coordinates (x, y) -#' -#' @param angles.grad vector of angles in degree -#' -#' @return matrix with columns \emph{x} and \emph{y} containing the coordinates -#' of points corresponding to the given angles in a unit circle -#' -#' @export -#' -#' @examples -#' plot(anglesToPoints(equidistantAngles(n = 10)), type = "b") -#' -anglesToPoints <- function(angles.grad) -{ - angles.rad <- gradToRad(angles.grad) - - M <- matrix(c(cos(angles.rad), sin(angles.rad)), ncol = 2, byrow = FALSE) - colnames(M) <- c("x", "y") - - M -} - -# gradToRad -------------------------------------------------------------------- - -#' Angle in Degree to Angle in rad -#' -#' @param grad vector of angles in degrees -#' -#' @export -#' -#' @examples -#' gradToRad(c(0, 90, 180, 270, 360)) / pi -#' -gradToRad <- function(grad) -{ - grad/180 * pi -} - # plotDependencies ------------------------------------------------------------- #' Plot Dependencies Between Nodes on a Circle Line diff --git a/R/utils.R b/R/utils.R index 2cffa54..a6325de 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,3 +1,29 @@ +# anglesToPoints --------------------------------------------------------------- + +#' Angle in Unit Circle to Point Coordinate +#' +#' Convert angles in a unit circle to point coordinates (x, y) +#' +#' @param angles.grad vector of angles in degree +#' +#' @return matrix with columns \emph{x} and \emph{y} containing the coordinates +#' of points corresponding to the given angles in a unit circle +#' +#' @export +#' +#' @examples +#' plot(anglesToPoints(equidistantAngles(n = 10)), type = "b") +#' +anglesToPoints <- function(angles.grad) +{ + angles.rad <- gradToRad(angles.grad) + + M <- matrix(c(cos(angles.rad), sin(angles.rad)), ncol = 2, byrow = FALSE) + colnames(M) <- c("x", "y") + + M +} + # catAndRun -------------------------------------------------------------------- #' @importFrom kwb.utils catAndRun @@ -26,6 +52,25 @@ defaultIfNa <- kwb.utils::defaultIfNA #' @importFrom kwb.utils defaultIfNULL defaultIfNull <- kwb.utils::defaultIfNULL +# equidistantAngles ------------------------------------------------------------ + +#' Equidistantly Distributed Angles in Degrees Between 0 and 360 +#' +#' @param n number of angles to be returned +#' @param from start angle in degrees. Default: 0 +#' +#' @export +#' +#' @examples +#' x <- equidistantAngles(90) +#' +#' plot(x, sin(gradToRad(x)), xlab = "angle in degree", ylab = "sin(angle)") +#' +equidistantAngles <- function(n, from = 0) +{ + seq(from, by = 360/n, length.out = n) +} + # excludeNull ------------------------------------------------------------------ #' @importFrom kwb.utils excludeNULL excludeNull <- kwb.utils::excludeNULL @@ -42,6 +87,22 @@ getAttribute <- kwb.utils::getAttribute #' @importFrom kwb.utils get_homedir getHomedir <- kwb.utils::get_homedir +# gradToRad -------------------------------------------------------------------- + +#' Angle in Degree to Angle in rad +#' +#' @param grad vector of angles in degrees +#' +#' @export +#' +#' @examples +#' gradToRad(c(0, 90, 180, 270, 360)) / pi +#' +gradToRad <- function(grad) +{ + grad/180 * pi +} + # lastElement ------------------------------------------------------------------ #' @importFrom kwb.utils lastElement lastElement <- kwb.utils::lastElement @@ -124,3 +185,4 @@ stopFormatted <- kwb.utils::stopFormatted # removeColumns ---------------------------------------------------------------- #' @importFrom kwb.utils removeColumns removeColumns <- kwb.utils::removeColumns + From 762746a75ed27267e7a7ec165b66a1fcdb0a844c Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 3 May 2024 14:09:32 +0200 Subject: [PATCH 72/90] Do not specify your own package --- R/plot_package_versions.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/plot_package_versions.R b/R/plot_package_versions.R index 0396010..3fc03ec 100644 --- a/R/plot_package_versions.R +++ b/R/plot_package_versions.R @@ -81,7 +81,7 @@ map_to_range <- function(x, y_range, x_range = range(x)) # seq_rad_len ------------------------------------------------------------------ seq_rad_len <- function(n) { - kwb.package::gradToRad(kwb.package::equidistantAngles(n)) + gradToRad(equidistantAngles(n)) } # draw_circles ----------------------------------------------------------------- From 17d4d17559f00e7b43c1d1d22e0450ad728db44d Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 3 May 2024 14:10:06 +0200 Subject: [PATCH 73/90] Fix function name (caused by "copy and paste") --- R/remotes_imports.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/remotes_imports.R b/R/remotes_imports.R index d633bc5..4cb4d17 100644 --- a/R/remotes_imports.R +++ b/R/remotes_imports.R @@ -2,7 +2,7 @@ remotes_github_pat <- getFromNamespace("github_pat", "remotes") # remotes_parse_deps ----------------------------------------------------------- -remotes_parse_deps <- getFromNamespace("untar_description", "remotes") +remotes_parse_deps <- getFromNamespace("remotes_parse_deps", "remotes") # remotes_read_dcf ------------------------------------------------------------- remotes_read_dcf <- getFromNamespace("read_dcf", "remotes") From 8895c5bc2c3743f55aa8bbac45e7c3847e4fd392 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 3 May 2024 14:10:50 +0200 Subject: [PATCH 74/90] Fix (again) function name --- R/plot_package_versions.R | 8 ++++++-- R/remotes_imports.R | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/R/plot_package_versions.R b/R/plot_package_versions.R index 3fc03ec..e674a34 100644 --- a/R/plot_package_versions.R +++ b/R/plot_package_versions.R @@ -1,4 +1,5 @@ -# plot.package_versions -------------------------------------------------------- +# plotPackageVersions ---------------------------------------------------------- + #' Plot Package Versions #' @param versions versions #' @param r_range r_range (default: c(1, 10)) @@ -7,7 +8,10 @@ #' @param ticklen ticklen (default: 1) #' @export plotPackageVersions <- function( - versions, r_range = c(1, 10), rmax = 1.1 * r_range[2L], dphi = NULL, + versions, + r_range = c(1, 10), + rmax = 1.1 * r_range[2L], + dphi = NULL, ticklen = 1 ) { diff --git a/R/remotes_imports.R b/R/remotes_imports.R index 4cb4d17..8c81d77 100644 --- a/R/remotes_imports.R +++ b/R/remotes_imports.R @@ -2,7 +2,7 @@ remotes_github_pat <- getFromNamespace("github_pat", "remotes") # remotes_parse_deps ----------------------------------------------------------- -remotes_parse_deps <- getFromNamespace("remotes_parse_deps", "remotes") +remotes_parse_deps <- getFromNamespace("parse_deps", "remotes") # remotes_read_dcf ------------------------------------------------------------- remotes_read_dcf <- getFromNamespace("read_dcf", "remotes") From 01acd16e7987f047bb98f4b8573e38969672a924 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 3 May 2024 14:15:14 +0200 Subject: [PATCH 75/90] Update Rd files --- man/anglesToPoints.Rd | 2 +- man/equidistantAngles.Rd | 2 +- man/gradToRad.Rd | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/man/anglesToPoints.Rd b/man/anglesToPoints.Rd index 2166e72..34963bd 100644 --- a/man/anglesToPoints.Rd +++ b/man/anglesToPoints.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/plot.R +% Please edit documentation in R/utils.R \name{anglesToPoints} \alias{anglesToPoints} \title{Angle in Unit Circle to Point Coordinate} diff --git a/man/equidistantAngles.Rd b/man/equidistantAngles.Rd index 302ae71..34e83ff 100644 --- a/man/equidistantAngles.Rd +++ b/man/equidistantAngles.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/plot.R +% Please edit documentation in R/utils.R \name{equidistantAngles} \alias{equidistantAngles} \title{Equidistantly Distributed Angles in Degrees Between 0 and 360} diff --git a/man/gradToRad.Rd b/man/gradToRad.Rd index dbf8088..826a2f7 100644 --- a/man/gradToRad.Rd +++ b/man/gradToRad.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/plot.R +% Please edit documentation in R/utils.R \name{gradToRad} \alias{gradToRad} \title{Angle in Degree to Angle in rad} From 7381792c02e0864c803f46d07e17fa5c74b82f19 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 3 May 2024 14:15:29 +0200 Subject: [PATCH 76/90] Update NEWS --- NEWS.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/NEWS.md b/NEWS.md index 01b1b71..91a3e79 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,50 @@ +# Current Development + +The following public functions were added: + +- getAuthors() +- getCranPackageDatabase() +- getPackageLicences() +- hasGplLicence() +- packageDependenciesByType() +- plotPackageVersions() +- sortedDependencies(): Was private before. The argument "pattern" is no longer + supported. +- stopIfNotInstalled() + +The following public functions were modified: + +- packageDependencies: add arguments "db", "which", "verbose" + +The following private functions were added: + +- allDeps() +- draw_circles() +- map_to_range() +- pathDescription() +- polar_to_xy() +- readDescription() +- remotes_github_pat() -> remotes:::github_pat() +- remotes_parse_deps() -> remotes:::parse_deps() +- remotes_read_dcf() -> remotes:::read_dcf() +- remotes_untar_description() -> remotes:::untar_description() +- seq_rad_len() +- untarDescriptionFromUrl() + +The following private functions were modified: + +- cranVersions(): add argument "dbg" +- loadDescriptionFromArchiveUrl(): add argument "path" +- loadDescriptionFromWeb(): add arguments "path", "cache" +- readGithubPackageDescription: add argument "destdir" +- stop_(): rename to cleanStop() + +Further changes: + +- Add Tests +- Add vignette "Tutorial" +- Update GitHub action files (e.g. master -> v2) + # [kwb.package 0.3.0](https://github.com/KWB-R/kwb.package/releases/tag/v0.3.0) 2022-06-11 * Harmonise with R package [kwb.pkgbuild](https://kwb-r.github.io/kwb.pkgbuild) From 2856640a2224376fb48e4c1f134f359c90841b01 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 3 May 2024 14:30:21 +0200 Subject: [PATCH 77/90] Reuse polar_to_xy() --- R/utils.R | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/R/utils.R b/R/utils.R index a6325de..d6aa7be 100644 --- a/R/utils.R +++ b/R/utils.R @@ -16,12 +16,7 @@ #' anglesToPoints <- function(angles.grad) { - angles.rad <- gradToRad(angles.grad) - - M <- matrix(c(cos(angles.rad), sin(angles.rad)), ncol = 2, byrow = FALSE) - colnames(M) <- c("x", "y") - - M + polar_to_xy(gradToRad(angles.grad)) } # catAndRun -------------------------------------------------------------------- From 5816edc46c2ba030293ad99ab4e24152127fbf6a Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 3 May 2024 14:31:15 +0200 Subject: [PATCH 78/90] Rename plot.R to plotAllDependencies.R --- R/{plot.R => plotAllDependencies.R} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename R/{plot.R => plotAllDependencies.R} (100%) diff --git a/R/plot.R b/R/plotAllDependencies.R similarity index 100% rename from R/plot.R rename to R/plotAllDependencies.R From c53b9592e10b9688bb77c3e30aecc7d97c2b7c07 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 3 May 2024 14:32:15 +0200 Subject: [PATCH 79/90] Renam "nodeColours" to "col" --- R/plotAllDependencies.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/plotAllDependencies.R b/R/plotAllDependencies.R index 4b37eda..cbf3faa 100644 --- a/R/plotAllDependencies.R +++ b/R/plotAllDependencies.R @@ -103,11 +103,11 @@ plotDependencies <- function( ... ) { - nodeColours <- rep(nodeColours, length.out = nrow(nodes)) + col <- rep(nodeColours, length.out = nrow(nodes)) - plotNodes(nodes, r = r, col = nodeColours, main = main) + plotNodes(nodes, r = r, col = col, main = main) addNodeLabels(nodes, cex = 0.8, distance.factor = 1.03) - drawDependencies(nodes, dependencies, nodeColours, ...) + drawDependencies(nodes, dependencies, col, ...) } # plotNodes -------------------------------------------------------------------- From 86add8087401a9577a4c0e65b1546187fbf85541 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 3 May 2024 14:33:23 +0200 Subject: [PATCH 80/90] Rename "stopNode(s)" to "endNode(s)" --- R/plotAllDependencies.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/plotAllDependencies.R b/R/plotAllDependencies.R index cbf3faa..78caf44 100644 --- a/R/plotAllDependencies.R +++ b/R/plotAllDependencies.R @@ -181,12 +181,12 @@ drawDependencies <- function(nodes, dependencies, nodeColours, ...) for (startNode in startNodes) { - stopNodes <- dependencies[[startNode]] + endNodes <- dependencies[[startNode]] - for (stopNode in stopNodes) { + for (endNode in endNodes) { drawLink( - nodes, startNode, stopNode, col = nodeColours[startNode == nodeNames], + nodes, startNode, endNode, col = nodeColours[startNode == nodeNames], ... ) } From 0f4ea2ccc0b00c0135eb6ff6fb723727f0bab8f4 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 3 May 2024 14:35:26 +0200 Subject: [PATCH 81/90] Omit intermediate variable --- R/plotAllDependencies.R | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/R/plotAllDependencies.R b/R/plotAllDependencies.R index 78caf44..6cd9083 100644 --- a/R/plotAllDependencies.R +++ b/R/plotAllDependencies.R @@ -71,9 +71,7 @@ plotAllDependencies <- function(dependencies, r = 1.5, for.each = TRUE, ...) #' toNodes <- function(nodeNames) { - n_nodes <- length(nodeNames) - - nodes <- anglesToPoints(equidistantAngles(n_nodes)) + nodes <- anglesToPoints(equidistantAngles(length(nodeNames))) rownames(nodes) <- nodeNames From 201d17fe58fa35ab307aa2d0ce45360ded644d4c Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 3 May 2024 14:51:19 +0200 Subject: [PATCH 82/90] Update Rd files --- man/addNodeLabels.Rd | 2 +- man/drawDependencies.Rd | 2 +- man/plotAllDependencies.Rd | 2 +- man/plotDependencies.Rd | 2 +- man/plotNodes.Rd | 2 +- man/toNodes.Rd | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/man/addNodeLabels.Rd b/man/addNodeLabels.Rd index 3a8ffa8..4e7c343 100644 --- a/man/addNodeLabels.Rd +++ b/man/addNodeLabels.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/plot.R +% Please edit documentation in R/plotAllDependencies.R \name{addNodeLabels} \alias{addNodeLabels} \title{Add Labels to the Nodes Drawn on a Circle Line} diff --git a/man/drawDependencies.Rd b/man/drawDependencies.Rd index bd9f6de..5b6c6b4 100644 --- a/man/drawDependencies.Rd +++ b/man/drawDependencies.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/plot.R +% Please edit documentation in R/plotAllDependencies.R \name{drawDependencies} \alias{drawDependencies} \title{Draw Lines between Nodes} diff --git a/man/plotAllDependencies.Rd b/man/plotAllDependencies.Rd index 6ad0533..a5f2dd5 100644 --- a/man/plotAllDependencies.Rd +++ b/man/plotAllDependencies.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/plot.R +% Please edit documentation in R/plotAllDependencies.R \name{plotAllDependencies} \alias{plotAllDependencies} \title{Plot all Package Dependencies} diff --git a/man/plotDependencies.Rd b/man/plotDependencies.Rd index 4d16426..16ba8ad 100644 --- a/man/plotDependencies.Rd +++ b/man/plotDependencies.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/plot.R +% Please edit documentation in R/plotAllDependencies.R \name{plotDependencies} \alias{plotDependencies} \title{Plot Dependencies Between Nodes on a Circle Line} diff --git a/man/plotNodes.Rd b/man/plotNodes.Rd index ef11726..9ad72bb 100644 --- a/man/plotNodes.Rd +++ b/man/plotNodes.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/plot.R +% Please edit documentation in R/plotAllDependencies.R \name{plotNodes} \alias{plotNodes} \title{Plot Nodes} diff --git a/man/toNodes.Rd b/man/toNodes.Rd index 2d5b067..8d3d165 100644 --- a/man/toNodes.Rd +++ b/man/toNodes.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/plot.R +% Please edit documentation in R/plotAllDependencies.R \name{toNodes} \alias{toNodes} \title{Nodes in a Unit Circle} From 0f473d54a249edbb7623870e9a665b6a32b91aba Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 3 May 2024 14:52:39 +0200 Subject: [PATCH 83/90] Remove drawLink() --- NAMESPACE | 1 - NEWS.md | 4 ++ R/plotAllDependencies.R | 54 ++++++++----------------- man/drawDependencies.Rd | 2 +- man/drawLink.Rd | 20 --------- tests/testthat/test-function-drawLink.R | 17 -------- 6 files changed, 21 insertions(+), 77 deletions(-) delete mode 100644 man/drawLink.Rd delete mode 100644 tests/testthat/test-function-drawLink.R diff --git a/NAMESPACE b/NAMESPACE index a8e5771..6f0d1fc 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -12,7 +12,6 @@ export(detachRecursively) export(downloadGitHubPackage) export(downloadPackagesFromSnapshot) export(drawDependencies) -export(drawLink) export(equidistantAngles) export(exampleLinksAndNodes) export(getAuthors) diff --git a/NEWS.md b/NEWS.md index 91a3e79..00506a8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -16,6 +16,10 @@ The following public functions were modified: - packageDependencies: add arguments "db", "which", "verbose" +The following public functions were deleted: + +- drawLink(): It was a one-liner and only used once within the package + The following private functions were added: - allDeps() diff --git a/R/plotAllDependencies.R b/R/plotAllDependencies.R index 6cd9083..0acf218 100644 --- a/R/plotAllDependencies.R +++ b/R/plotAllDependencies.R @@ -93,12 +93,12 @@ toNodes <- function(nodeNames) #' @export #' plotDependencies <- function( - nodes, - dependencies, - main = "", - r = 1.5, - nodeColours = grDevices::rainbow(nrow(nodes)), - ... + nodes, + dependencies, + main = "", + r = 1.5, + nodeColours = grDevices::rainbow(nrow(nodes)), + ... ) { col <- rep(nodeColours, length.out = nrow(nodes)) @@ -168,43 +168,21 @@ addNodeLabels <- function(nodes, cex = 1, distance.factor = 1) #' @param dependencies list of package dependencies as returned by #' \code{\link{packageDependencies}} #' @param nodeColours colours given to the lines starting at the same start node -#' @param \dots arguments passed to \code{\link{drawLink}} +#' @param \dots arguments passed to \code{\link[graphics]{arrows}} +#' @importFrom graphics arrows #' @export -#' drawDependencies <- function(nodes, dependencies, nodeColours, ...) { - nodeNames <- rownames(nodes) - - startNodes <- names(dependencies) - - for (startNode in startNodes) { - - endNodes <- dependencies[[startNode]] - - for (endNode in endNodes) { - - drawLink( - nodes, startNode, endNode, col = nodeColours[startNode == nodeNames], + for (startNode in names(dependencies)) { + for (endNode in dependencies[[startNode]]) { + graphics::arrows( + nodes[startNode, "x"], + nodes[startNode, "y"], + nodes[endNode, "x"], + nodes[endNode, "y"], + col = nodeColours[startNode == rownames(nodes)], ... ) } } } - -# drawLink --------------------------------------------------------------------- - -#' Draw a Link Between a Pair of Nodes -#' -#' @param nodes data frame as returned by \code{\link{toNodes}} -#' @param i row index of the start node -#' @param j row index of the finish node -#' @param \dots arguments passed to \code{arrows} -#' @export -#' @importFrom graphics arrows -drawLink <- function(nodes, i, j, ...) -{ - graphics::arrows( - x0 = nodes[i, "x"], y0 = nodes[i, "y"], - x1 = nodes[j, "x"], y1 = nodes[j, "y"], ... - ) -} diff --git a/man/drawDependencies.Rd b/man/drawDependencies.Rd index 5b6c6b4..8ad3611 100644 --- a/man/drawDependencies.Rd +++ b/man/drawDependencies.Rd @@ -14,7 +14,7 @@ drawDependencies(nodes, dependencies, nodeColours, ...) \item{nodeColours}{colours given to the lines starting at the same start node} -\item{\dots}{arguments passed to \code{\link{drawLink}}} +\item{\dots}{arguments passed to \code{\link[graphics]{arrows}}} } \description{ Draw Lines between Nodes diff --git a/man/drawLink.Rd b/man/drawLink.Rd deleted file mode 100644 index 0aec6dd..0000000 --- a/man/drawLink.Rd +++ /dev/null @@ -1,20 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/plot.R -\name{drawLink} -\alias{drawLink} -\title{Draw a Link Between a Pair of Nodes} -\usage{ -drawLink(nodes, i, j, ...) -} -\arguments{ -\item{nodes}{data frame as returned by \code{\link{toNodes}}} - -\item{i}{row index of the start node} - -\item{j}{row index of the finish node} - -\item{\dots}{arguments passed to \code{arrows}} -} -\description{ -Draw a Link Between a Pair of Nodes -} diff --git a/tests/testthat/test-function-drawLink.R b/tests/testthat/test-function-drawLink.R deleted file mode 100644 index 4d00866..0000000 --- a/tests/testthat/test-function-drawLink.R +++ /dev/null @@ -1,17 +0,0 @@ -# -# This file was generated by kwb.test::create_test_files(), -# launched by hsonne on 2024-05-02 18:06:13. -# Please modify the dummy functions so that real cases are -# tested. Then, delete this comment. -# - -test_that("drawLink() works", { - - f <- kwb.package::drawLink - - expect_error( - f() - # Argument "nodes" fehlt (ohne Standardwert) - ) - -}) From 9acf3d0409ccc76eb671984c5f5be34ce3fa0013 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 3 May 2024 14:53:52 +0200 Subject: [PATCH 84/90] Do not track Rplots.pdf --- .gitignore | 1 + tests/testthat/Rplots.pdf | Bin 3448 -> 0 bytes 2 files changed, 1 insertion(+) delete mode 100644 tests/testthat/Rplots.pdf diff --git a/.gitignore b/.gitignore index 8add92a..37da325 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ .Ruserdata R/\.* inst/doc +tests/testthat/Rplots.pdf diff --git a/tests/testthat/Rplots.pdf b/tests/testthat/Rplots.pdf deleted file mode 100644 index f6d5b84adefa96033052ad9b8528051a02b11f06..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3448 zcmZ`+XH-+^7DW({sPtk6gbPxF0wJM=rj$^mNGEiOAwb5E#3V=!y-9llil9_!3d2JL zqzQ_2DWQp?CSNmL9%szM`*@1+{{6L@-dov?IgUR?q?q7;o5KFN;^sKS55t@Sa z0W?`zo`24O75#Z7Lp&8rCa{`7k=V;P43*vw`Vs$+Gd`iauUYFZ}Ipl zn~WyXk%Y9%C_e;;%tnPYPWM66_IW!Ts~mi`ZaOL8_Je^zdewbc1f}& z+{?aePRZ|7)%3K7<$=PBiqOS1Mj>yc@%eDNef#UR-_gOFS%^$3%-Bnd;2TI4 zyh+e*_~XreH+FS^&BTCX$v}LOL+J6r2ag4s*!X5S*bN~`2QPWUW@Ch}9zX(O!ch%H z$F9Xxdn?@G3M>*(kJTg{qef$9)e+n((F5KGrw`bx@)krXu7d^*_~YXH_(kj!seo~x z#Qk`etK#oCIE@8tC9WNkGd4137cp2avcDrynXpvsyXd|Mq5jgscGS4B$j)DoAri`c zLY1ey!|k2`p0m!|25~4oPOPJU9gdJviD`U%ox~B&zZz%Ld1F?<1#~95LLiD?K<9Rf zs(|PdQ=^PvSsnrDs;h#f>^Os$S0ziOnv=~lD*D`oxlBx8wpP~;Ka~=RpSzu1>|Cr_ zQfbF+n}6r@gwq7%SI}nxYtxIjhen4N*{Di7;QSO7Q&iEdk>iVXivn8+h6q<|F(wt3 zek{^TLSCefy$)O_KAx@}5AI1tm)E-drZXwAoP4yKeD4At_5c*dA0`;ashduVJuycm zJwTlI&^woOs>^BCjif+Ak%XGS4+Y=wuch*JZ>|q~!tR=e^FoP*(7B(z!0u?Wm>%m$Q0EJsSzRb~!t9Us+AXXj$n1=@o^1nb$IH zKvuu04xHrZLki_6M++^ORh_ZqsD6GoFn$QvU;L_Y`vmLa&o>!y+wgV+S5xSipPt^M>!Th zY{405Mj%7iN!iK9seMWQndY-ol{L@a-wC<%>6yjE%V(w&Z|2BjzWep#D5B~Ul{X-LKw>p7Q#)~CdNNL9Nd1I5%71lSVkB>JY;t4#=~(5MPRVD- zTmN1u&aZ4U-izBV<#p<{HY=(#UML;LB!D`zGKTN?Y{AN@8i8K}>RdY2S{gj~8DctFq@HL?(Ej8^zs^+mkus+;b zjaPM8i=fed(Ma=>maFfWH+e`H^Av8a_BtSR>WF5YmL;qTCJs*=IzGtxzI7;3c|`P_ zs8I@6inx{FcvfyF9-HnqrW~t$Sh-cH&=u^`?H*9K)X4A;Am$TZ`_p<8E(rNM_>W^Y ztEzLApFil?e(AB{G1FYNaG6dc_z`*=UtxmA3x1Wl@TjBx`M22ElGwiDA@tbjW7ufz z4Y3-n2{^C<*D=+}-?TA+33-ne4Ib zSw=Y0h-_>l*avwArH94taq!Xj3e2*4<0|g@RW2CP{k$f0-oNhRnQ4NQ#Qmq)T4=?yg|BT%Men;OG_D73C{y+QoTX!&_rf zWet`UP54!nRiOfIA~!K}?J0D@Mz&f0x`MvNW$QNudbx82_8A+Fk3}617gR7RCd=B- z9kzZ|xUHx!-=@!TBO~XMqq#si&mO!%Z4;hYH&~ZkS2~b)W5q*L4kW07HJ(bj-`cG{ zMW2Z3Lf-d+-<;2O$l8?G(%CUDAQz|-y_=^ttOpb}Xq%6`qTM+FQmMuJG zIE_@6RfVFKYgF9y+k1#Z(G778xQmgHdKD#Tc(aPHr%i_Q=*`=;pCgvtQ$&(Yy0tW$ z@ONG%y@b3#G~rguE3Kt0gXP35t1VAi%n;ub+IO!Hp{}2&z09n~-Wx2&)13#M-%c*S znr=J}L8;K8Qm-WMw^6t;X8q|mbZ>loXp2VKHKyFNyl?3S_L%a-+BP&S(E=?#o2Q|y z!>WB(%3nTj4QZ|U`02&CbA=PiZHG|fy*3p3h%wAnl8{Wxp=s|)YMN?oM-DMsn$MQp zt^d#&@iyW^bP@+`D1B&1`KB_qnp9O9xZ(YzV_+sYa{P4T| zgQs|&T)8b&ca2KJ7{oqcy%O7;8)3ySXDCq5ieja|zHty`-BU*L^{)tp zBN!4WxIY096p8co#gefE4AZc?1L_*k030EZ0(kz9(GMnLeL<=K0;Kx$0W>u<)HDEJ z;3o!WE+?!9ApFE&noP(4Hw+GAt_^?35ZeF1)U=tt|8IHf@PF{B!C;8L@~C7q4v!@> z_agx6fD6R}2mpGP;7bHpi<3P7wI>p(0BddeVe=_eG@1J2ZfZ Date: Fri, 3 May 2024 14:55:48 +0200 Subject: [PATCH 85/90] Rename packageNames to nodeNames --- R/plotAllDependencies.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/plotAllDependencies.R b/R/plotAllDependencies.R index 0acf218..12ea003 100644 --- a/R/plotAllDependencies.R +++ b/R/plotAllDependencies.R @@ -24,9 +24,9 @@ #' plotAllDependencies <- function(dependencies, r = 1.5, for.each = TRUE, ...) { - packageNames <- unique(c(names(dependencies), unlist(dependencies))) + nodeNames <- unique(c(names(dependencies), unlist(dependencies))) - nodes <- toNodes(nodeNames = packageNames) + nodes <- toNodes(nodeNames) plotDependencies( nodes, dependencies, From 9556248d253fe1e7d3bcc15144ddcdf33639c253 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 3 May 2024 16:46:25 +0200 Subject: [PATCH 86/90] Fix keyword in getCranPackageDatabase() and prove that this function returns exactly the same as tools::CRAN_package_db() --- R/cran_helpers.R | 9 ++++- .../test-function-getCranPackageDatabase.R | 33 +++---------------- 2 files changed, 13 insertions(+), 29 deletions(-) diff --git a/R/cran_helpers.R b/R/cran_helpers.R index 54ca3b7..73654c4 100644 --- a/R/cran_helpers.R +++ b/R/cran_helpers.R @@ -37,7 +37,14 @@ currentCranVersion <- function(name) #' @export getCranPackageDatabase <- function() { - readRDS(file(getUrl("cran_packages", package = "packages.rds"))) + url <- getUrl("cran_package", package = "packages.rds") + + system.time(db1 <- as.data.frame(readRDS(file(url)))) + + #system.time(db2 <- tools::CRAN_package_db()) + #stopifnot(identical(db1, db2)) + + db1 } # isOnCran --------------------------------------------------------------------- diff --git a/tests/testthat/test-function-getCranPackageDatabase.R b/tests/testthat/test-function-getCranPackageDatabase.R index f621f19..3946035 100644 --- a/tests/testthat/test-function-getCranPackageDatabase.R +++ b/tests/testthat/test-function-getCranPackageDatabase.R @@ -1,35 +1,12 @@ -# -# This file was generated by kwb.test::create_test_files(), -# launched by hsonne on 2024-05-02 17:58:26. -# Please modify the dummy functions so that real cases are -# tested. Then, delete this comment. -# +#library(testthat) test_that("getCranPackageDatabase() works", { f <- kwb.package::getCranPackageDatabase - expect_error( - f() - # No such element in list 'urls': -# - 'cran_packages' -# Available elements (sorted): -# - 'cached_desc' -# - 'cran' -# - 'cran_archive' -# - 'cran_archive_file' -# - 'cran_contrib' -# - 'cran_package' -# - 'cran_package_file' -# - 'cran_rstudio' -# - 'github_api' -# - 'github_desc' -# - 'github_raw' -# - 'github_releases' -# - 'github_tags' -# - 'mran_snapshot' -# - 'package_filename' -# - ) + result <- f() + expect_s3_class(result, "data.frame") + expect_true(all(c("Package", "Depends", "Imports") %in% names(result))) + }) From ec4b3dcacec49408b9e0c0fbec34dfc8f1d48e89 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 3 May 2024 20:59:39 +0200 Subject: [PATCH 87/90] Add getDependencyData() --- NAMESPACE | 2 ++ NEWS.md | 1 + R/getDependencyData.R | 72 ++++++++++++++++++++++++++++++++++++++++ R/utils.R | 4 +++ man/getDependencyData.Rd | 21 ++++++++++++ 5 files changed, 100 insertions(+) create mode 100644 R/getDependencyData.R create mode 100644 man/getDependencyData.Rd diff --git a/NAMESPACE b/NAMESPACE index 6f0d1fc..86f3add 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -16,6 +16,7 @@ export(equidistantAngles) export(exampleLinksAndNodes) export(getAuthors) export(getCranPackageDatabase) +export(getDependencyData) export(getPackageFilesToInstall) export(getPackageLicences) export(getRVersionMajorMinor) @@ -54,6 +55,7 @@ importFrom(kwb.utils,defaultIfNA) importFrom(kwb.utils,defaultIfNULL) importFrom(kwb.utils,excludeNULL) importFrom(kwb.utils,extractSubstring) +importFrom(kwb.utils,fullySorted) importFrom(kwb.utils,getAttribute) importFrom(kwb.utils,get_homedir) importFrom(kwb.utils,hsRestoreAttributes) diff --git a/NEWS.md b/NEWS.md index 00506a8..6610309 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,7 @@ The following public functions were added: - getAuthors() - getCranPackageDatabase() +- getDependencyData() - getPackageLicences() - hasGplLicence() - packageDependenciesByType() diff --git a/R/getDependencyData.R b/R/getDependencyData.R new file mode 100644 index 0000000..ee7851d --- /dev/null +++ b/R/getDependencyData.R @@ -0,0 +1,72 @@ +# getDependencyData ------------------------------------------------------------ + +#' Get Package Dependency Data from Package Database +#' +#' @param db package data base as e.g. returned by +#' \code{\link{getCranPackageDatabase}} +#' @param fields types of dependencies to be considered. Default: +#' \code{c("Depends", "Imports", "LinkingTo", "Suggests", "Enhances")} +#' @export +getDependencyData <- function( + db, + fields = c("Depends", "Imports", "LinkingTo", "Suggests", "Enhances") +) +{ + stopifnot(`db must be a matrix or a data frame` = length(dim(db)) == 2L) + + db <- as.data.frame(db) + packages <- selectColumns(db, "Package") + + deps <- lapply(fields, function(field) { + catAndRun( + sprintf("Analysing %s field", field), + packages %>% + toDependencyData(selectColumns(db, field)) %>% + cbind( + type = tolower(field), + reverse = FALSE + ) + ) + }) %>% + rbindAll() %>% + fullySorted() %>% + moveColumnsToFront(c("package", "type")) +} + +# toDependencyData ------------------------------------------------------------- +toDependencyData <- function(packages, strings) +{ + stopifnot(length(packages) == length(strings)) + + # Split dependency strings at comma (after removing new line or space) + parts <- strsplit(gsub("\n|\\s+", "", strings), ",") + + data.frame( + package = rep(packages, lengths(parts)), + splitDependency(unlist(parts)) + ) +} + +# splitDependency -------------------------------------------------------------- +splitDependency <- function(x) +{ + stopifnot(`No spaces allowed!` = !any(grepl("\\s", x))) + + pattern <- "^([^(]+)(\\(([<>=]+)(.*)\\))?" + matches <- is.na(x) | grepl(pattern, x) + + if (any(!matches)) { + stopFormatted( + "Non-matching dependency string: '%s'", x[!matches][1L] + ) + } + + cbind( + dep_full = x, + extractSubstring(pattern, x, index = c( + dep_name = 1L, + dep_version_op = 3L, + dep_version_no = 4L + )) + ) +} diff --git a/R/utils.R b/R/utils.R index d6aa7be..5392d07 100644 --- a/R/utils.R +++ b/R/utils.R @@ -74,6 +74,10 @@ excludeNull <- kwb.utils::excludeNULL #' @importFrom kwb.utils extractSubstring extractSubstring <- kwb.utils::extractSubstring +# fullySorted ------------------------------------------------------------------ +#' @importFrom kwb.utils fullySorted +fullySorted <- kwb.utils::fullySorted + # getAttribute ----------------------------------------------------------------- #' @importFrom kwb.utils getAttribute getAttribute <- kwb.utils::getAttribute diff --git a/man/getDependencyData.Rd b/man/getDependencyData.Rd new file mode 100644 index 0000000..a6aab1b --- /dev/null +++ b/man/getDependencyData.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/getDependencyData.R +\name{getDependencyData} +\alias{getDependencyData} +\title{Get Package Dependency Data from Package Database} +\usage{ +getDependencyData( + db, + fields = c("Depends", "Imports", "LinkingTo", "Suggests", "Enhances") +) +} +\arguments{ +\item{db}{package data base as e.g. returned by +\code{\link{getCranPackageDatabase}}} + +\item{fields}{types of dependencies to be considered. Default: +\code{c("Depends", "Imports", "LinkingTo", "Suggests", "Enhances")}} +} +\description{ +Get Package Dependency Data from Package Database +} From 96c57c59a96a67dcbc460be7260a7e3e11e8ae31 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 3 May 2024 21:27:35 +0200 Subject: [PATCH 88/90] Analyse only fields that exist in db and do not provide column "reverse" --- R/getDependencyData.R | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/R/getDependencyData.R b/R/getDependencyData.R index ee7851d..20fe26d 100644 --- a/R/getDependencyData.R +++ b/R/getDependencyData.R @@ -17,15 +17,12 @@ getDependencyData <- function( db <- as.data.frame(db) packages <- selectColumns(db, "Package") - deps <- lapply(fields, function(field) { + lapply(intersect(fields, names(db)), function(field) { catAndRun( sprintf("Analysing %s field", field), packages %>% toDependencyData(selectColumns(db, field)) %>% - cbind( - type = tolower(field), - reverse = FALSE - ) + cbind(type = tolower(field)) ) }) %>% rbindAll() %>% From 2a518bf7fc9509cc08d77594c6f9f9de27155a01 Mon Sep 17 00:00:00 2001 From: hsonne Date: Sun, 5 May 2024 11:23:48 +0200 Subject: [PATCH 89/90] Return version and all licence columns --- R/getPackageLicences.R | 14 ++++++++------ man/getPackageLicences.Rd | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/R/getPackageLicences.R b/R/getPackageLicences.R index 335328b..f2fc756 100644 --- a/R/getPackageLicences.R +++ b/R/getPackageLicences.R @@ -5,13 +5,13 @@ #' @param packages names of (installed) packages #' @param db optional. Package database, similar to what is returned by #' \code{\link[utils]{installed.packages}}. Default: -#' \code{as.data.frame(installed.packages())} +#' \code{installed.packages()} #' @return data frame #' @importFrom utils installed.packages #' @export getPackageLicences <- function( packages, - db = as.data.frame(utils::installed.packages()) + db = utils::installed.packages() ) { #kwb.utils::assignPackageObjects("kwb.package");stop.on.error = FALSE @@ -19,9 +19,11 @@ getPackageLicences <- function( #db <- kwb.utils:::get_cached("package_db") #packages <- db$Package - colnames(db) <- tolower(colnames(db)) - licence_fields <- intersect(colnames(db), c("licence", "license")) - stopifnot(length(licence_fields) == 1L) + db <- as.data.frame(db) + names(db) <- gsub("license", "licence", tolower(names(db))) + + licence_fields <- grep("^licence", names(db), value = TRUE) + stopifnot(length(licence_fields) > 0L) backbone <- data.frame( package = packages, @@ -30,7 +32,7 @@ getPackageLicences <- function( result <- backbone %>% merge( - y = db[, c("package", licence_fields)], + y = selectColumns(db, c("package", "version", licence_fields)), by = "package", all.x = TRUE ) %>% diff --git a/man/getPackageLicences.Rd b/man/getPackageLicences.Rd index 37a5c02..0ae46bc 100644 --- a/man/getPackageLicences.Rd +++ b/man/getPackageLicences.Rd @@ -4,14 +4,14 @@ \alias{getPackageLicences} \title{Which Licences are Specified for the Packages?} \usage{ -getPackageLicences(packages, db = as.data.frame(utils::installed.packages())) +getPackageLicences(packages, db = utils::installed.packages()) } \arguments{ \item{packages}{names of (installed) packages} \item{db}{optional. Package database, similar to what is returned by \code{\link[utils]{installed.packages}}. Default: -\code{as.data.frame(installed.packages())}} +\code{installed.packages()}} } \value{ data frame From 4a4c25067b35ccaa3136af9e0fa34ed5f85492a8 Mon Sep 17 00:00:00 2001 From: hsonne Date: Sun, 5 May 2024 11:25:42 +0200 Subject: [PATCH 90/90] Set version number to 0.4.0 --- DESCRIPTION | 2 +- NEWS.md | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 7752413..f086ed0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: kwb.package Title: Install / Unstall KWB Packages and Show Package Dependencies -Version: 0.3.0.9000 +Version: 0.4.0 Authors@R: c( person("Hauke", "Sonnenberg", , "hauke.sonnenberg@kompetenz-wasser.de", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-9134-2871")), diff --git a/NEWS.md b/NEWS.md index 6610309..8ad23b0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # Current Development +# [kwb.package 0.4.0](https://github.com/KWB-R/kwb.package/releases/tag/v0.4.0) 2024-05-05 + The following public functions were added: - getAuthors()