diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 2bf5cb4..8b25c04 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -32,15 +32,16 @@ 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 - - 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 +77,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 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: | diff --git a/.gitignore b/.gitignore index 9569181..37da325 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ .Rhistory .RData .Ruserdata -R/\.* \ No newline at end of file +R/\.* +inst/doc +tests/testthat/Rplots.pdf diff --git a/DESCRIPTION b/DESCRIPTION index 286744e..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 +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")), @@ -19,19 +19,23 @@ 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), + magrittr, mvbutils, networkD3, remotes, withr Suggests: covr, - pkgmeta + knitr, + pkgmeta, + rmarkdown, + testthat (>= 3.0.0) Remotes: github::kwb-r/kwb.utils, github::kwb-r/pkgmeta Encoding: UTF-8 -RoxygenNote: 7.1.2 +RoxygenNote: 7.3.1 +VignetteBuilder: knitr +Config/testthat/edition: 3 diff --git a/NAMESPACE b/NAMESPACE index 6f0877f..86f3add 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,35 +1,45 @@ # Generated by roxygen2: do not edit by hand +export("%>%") export(addNodeLabels) export(anglesToPoints) export(archivedCranVersions) export(compareInstalledVersions) export(copyBasePackages) +export(cranVersions) export(detachAllNonSystemPackages) export(detachRecursively) export(downloadGitHubPackage) export(downloadPackagesFromSnapshot) export(drawDependencies) -export(drawLink) export(equidistantAngles) export(exampleLinksAndNodes) +export(getAuthors) +export(getCranPackageDatabase) +export(getDependencyData) export(getPackageFilesToInstall) +export(getPackageLicences) export(getRVersionMajorMinor) export(githubVersions) export(gradToRad) +export(hasGplLicence) export(initLocalCRAN) export(installGithubPackages) export(installRemotes) export(installedDependencies) export(installedKwbPackages) export(packageDependencies) +export(packageDependenciesByType) export(packageString) export(plotAllDependencies) export(plotDependencies) export(plotNodes) +export(plotPackageVersions) export(plotSankeyNetwork) export(provideInLocalCRAN) export(setOptionsForPackrat) +export(sortedDependencies) +export(stopIfNotInstalled) export(systemPackages) export(toLinksAndNodes) export(toNodes) @@ -38,23 +48,33 @@ importFrom(gh,gh) importFrom(grDevices,rainbow) importFrom(graphics,arrows) importFrom(graphics,plot) -importFrom(kwb.utils,assignPackageObjects) importFrom(kwb.utils,catAndRun) +importFrom(kwb.utils,catIf) importFrom(kwb.utils,createDirectory) 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,hsRenameColumns) -importFrom(kwb.utils,moveColumnsToFront) +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) 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/NEWS.md b/NEWS.md index 01b1b71..8ad23b0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,57 @@ +# 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() +- getCranPackageDatabase() +- getDependencyData() +- 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 public functions were deleted: + +- drawLink(): It was a one-liner and only used once within the package + +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) diff --git a/R/allDeps.R b/R/allDeps.R new file mode 100644 index 0000000..bd152d2 --- /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 <- excludeNull(child_deps, dbg = FALSE) + + if (length(child_deps) > 0L) { + deps <- rbind(deps, do.call(rbind, child_deps)) + } + + deps +} diff --git a/R/archivedCranVersions.R b/R/archivedCranVersions.R index 008e4ee..b617f73 100644 --- a/R/archivedCranVersions.R +++ b/R/archivedCranVersions.R @@ -1,76 +1,10 @@ -# isOnCran --------------------------------------------------------------------- -isOnCran <- function(name) -{ - nrow(currentCranVersion(name)) > 0L -} - -# cranVersions ----------------------------------------------------------------- -#' @noMd -#' @noRd -#' @keywords internal -#' @importFrom kwb.utils removeColumns safeRowBind -cranVersions <- function(name) -{ - current <- currentCranVersion(name) - - if (nrow(current) == 0L) { - 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)) - - if (is.null(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 #' @param ref_date default: NULL #' @export -#' @importFrom kwb.utils extractSubstring noFactorDataFrame #' @examples #' packages <- c("ggplot2", "swmmr", "kwb.hantush") #' archivedCranVersions(packages) @@ -86,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)), @@ -99,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( @@ -124,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 new file mode 100644 index 0000000..624c41a --- /dev/null +++ b/R/cranVersions.R @@ -0,0 +1,43 @@ +# cranVersions ----------------------------------------------------------------- + +#' 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) + + 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 <- safeRowBind(archived, current) + + removeColumns(result, "archive_file") +} diff --git a/R/cran_helpers.R b/R/cran_helpers.R new file mode 100644 index 0000000..73654c4 --- /dev/null +++ b/R/cran_helpers.R @@ -0,0 +1,54 @@ +# currentCranVersion ----------------------------------------------------------- + +#' @noMd +#' @noRd +#' @keywords internal +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(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]) + } + + noFactorDataFrame( + package = name, + version = extract("Version"), + date = as.Date(extract("Published")), + date_type = "published" + ) +} + +# getCranPackageDatabase ------------------------------------------------------- + +#' Get Matrix with Information on All CRAN Packages +#' +#' @export +getCranPackageDatabase <- function() +{ + 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 --------------------------------------------------------------------- +isOnCran <- function(name) +{ + nrow(currentCranVersion(name)) > 0L +} diff --git a/R/detach.R b/R/detach.R index f80e019..430f9a7 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)) @@ -63,79 +64,90 @@ 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 -#' +#' @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 -#' -sortedDependencies <- function(package, pattern = ".*", dbg = FALSE) +#' @export +sortedDependencies <- function(package, dbg = FALSE) { - dependingOn <- grep( - pattern, - packageDependencies(package, recursive = TRUE)[[1]], - value = TRUE - ) + fullDependencies <- packageDependencies(package, recursive = TRUE) + + # Put all unique package names from the dependency tree into a vector + packages <- unique(unname(unlist(fullDependencies))) - dependencies <- packageDependencies(dependingOn, recursive = FALSE) + # 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) - allLeafs <- character() + allLeaves <- character() - while (length(dependencies) > 0) { + while (length(dependencies)) { - numberOfDependencies <- sapply(dependencies, FUN = function(x) { - length(grep(pattern, x)) - }) + nDependencies <- lengths(dependencies) printAndWaitIf(dbg, list( dependencies = dependencies, - numberOfDependencies = numberOfDependencies + nDependencies = nDependencies )) - - # Extract the "leafs" from the dependencies - leafs <- names(dependencies)[numberOfDependencies == 0] - dependencies <- dependencies[numberOfDependencies > 0] + + # Which dependency is a "leaf" (i.e. does not have further dependencies)? + isLeaf <- nDependencies == 0L + # Extract the "leaves" from the dependencies + leaves <- names(dependencies)[isLeaf] + + # Remove the names of the leaf packages from the dependency tree dependencies <- sapply( - dependencies, - function(x) {setdiff(x, leafs)}, + dependencies[!isLeaf], + FUN = setdiff, + y = 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) + allLeaves } # packageDependencies ---------------------------------------------------------- #' Package Dependencies +#' +#' This is just a wrapper around \code{\link[tools]{package_dependencies}} with +#' some defaults defined. #' -#' @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 #' @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, + verbose = FALSE ) { tools::package_dependencies( packages, - db = utils::installed.packages(), + db = db, + which = which, recursive = recursive, - reverse = reverse + reverse = reverse, + verbose = verbose ) } # printAndWaitIf --------------------------------------------------------------- - printAndWaitIf <- function(dbg, variables) { if (dbg) { @@ -149,7 +161,7 @@ printAndWaitIf <- function(dbg, variables) } } -# systemPackages -------------------------------------------------------------- +# systemPackages --------------------------------------------------------------- #' Names of Base R Packages #' @@ -169,5 +181,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..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{ @@ -58,7 +57,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/downloadPackagesFromSnapshot.R b/R/downloadPackagesFromSnapshot.R index da89203..86b1b5c 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 <- getUrl("mran_snapshot", date = snapshot_date) if (is.null(destdir)) { @@ -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/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/R/getDependencyData.R b/R/getDependencyData.R new file mode 100644 index 0000000..20fe26d --- /dev/null +++ b/R/getDependencyData.R @@ -0,0 +1,69 @@ +# 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") + + lapply(intersect(fields, names(db)), function(field) { + catAndRun( + sprintf("Analysing %s field", field), + packages %>% + toDependencyData(selectColumns(db, field)) %>% + cbind(type = tolower(field)) + ) + }) %>% + 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/getPackageLicences.R b/R/getPackageLicences.R new file mode 100644 index 0000000..f2fc756 --- /dev/null +++ b/R/getPackageLicences.R @@ -0,0 +1,45 @@ +# getPackageLicences ----------------------------------------------------------- + +#' 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{installed.packages()} +#' @return data frame +#' @importFrom utils installed.packages +#' @export +getPackageLicences <- function( + packages, + db = utils::installed.packages() +) +{ + #kwb.utils::assignPackageObjects("kwb.package");stop.on.error = FALSE + #`%>%` <- magrittr::`%>%` + #db <- kwb.utils:::get_cached("package_db") + #packages <- db$Package + + 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, + stringsAsFactors = FALSE + ) + + result <- backbone %>% + merge( + y = selectColumns(db, c("package", "version", licence_fields)), + by = "package", + all.x = TRUE + ) %>% + renameColumns(list(license = "licence")) %>% + orderBy("package") + + result[["licence"]] <- defaultIfNa(result[["licence"]], "") + + result +} diff --git a/R/githubPackageVersions.R b/R/githubPackageVersions.R index c13eae8..5c2b0de 100644 --- a/R/githubPackageVersions.R +++ b/R/githubPackageVersions.R @@ -1,12 +1,12 @@ # githubVersions --------------------------------------------------------------- -#' Title + +#' Get Versions of Packages on GitHub #' #' @param name package name #' @param github_user name of github account, default: "KWB-R" #' #' @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") @@ -18,13 +18,14 @@ 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 ) { #kwb.utils::assignPackageObjects("kwb.package") #repo = "cran/kwb.hantush";verbose=TRUE;reduced=TRUE + stopifnot(is.character(repo)) if (length(repo) > 1L) { @@ -40,9 +41,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 +55,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 +65,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() + 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 +99,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 +133,5 @@ getGithubReleaseInfo <- function( return(result) } - kwb.utils::removeColumns(result, "sha") + removeColumns(result, "sha") } - diff --git a/R/helpers.R b/R/helpers.R new file mode 100644 index 0000000..5aecd24 --- /dev/null +++ b/R/helpers.R @@ -0,0 +1,108 @@ +# dirPackageZips --------------------------------------------------------------- +dirPackageZips <- function(package, path) +{ + dir(path, paste0("^", package, "_"), full.names = TRUE) +} + +# getUrl ----------------------------------------------------------------------- +#' @noMd +#' @noRd +#' @keywords internal +getUrl <- function(key, ...) +{ + urls <- 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" + )) + + selectElements(urls, key) +} + +# githubRepo ------------------------------------------------------------------- +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) %>% + selectColumns("licence") %>% + grep(pattern = "GPL", ignore.case = TRUE) +} + +# packageInDestdir ------------------------------------------------------------- +#' @noMd +#' @noRd +#' @keywords internal +packageInDestdir <- function(package, destdir, verbose = TRUE) +{ + files <- dirPackageZips(package, safePath(destdir)) + + file_exists <- length(files) > 0L + + if (verbose && file_exists) { + message("Skipping already downloaded package '", package, "'") + } + + structure(file_exists, path = if (file_exists) lastElement(files)) +} + + +# readDescription -------------------------------------------------------------- +readDescription <- function(package, stop.on.error = TRUE) +{ + if (stop.on.error) { + stopIfNotInstalled(package) + } + + file <- system.file("DESCRIPTION", package = package) + + if (!file.exists(file) ) { + return(NULL) + } + + result <- read.dcf(file) + + colnames(result) <- tolower(colnames(result)) + + result +} + +# stopIfNotInstalled ----------------------------------------------------------- + +#' 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(utils::installed.packages()) + + if (!package %in% available) { + stopFormatted("The package '%s' is not installed.", package) + } +} diff --git a/R/install.R b/R/install.R index e662e1e..22dea84 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 @@ -51,20 +39,27 @@ updateKwbPackages <- function } } - # getServername ------------------------------------------------------------ #' 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 == "") { + stopFormatted( + paste( + "Enviroment variable '%s' not defined!", + "Please define with Sys.setenv(%s = 'kwb-servername')", + sep = "\n" + ), + variable, + variable + ) + } servername } @@ -125,18 +120,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( @@ -210,17 +202,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 2b250b6..d8b3642 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,9 +56,9 @@ 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 = "https://cran.rstudio.org") + install.packages("remotes", repos = getUrl("cran_rstudio")) for (repo in repos) { 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 c4fbc24..56cddee 100644 --- a/R/loadDescriptionFromArchiveUrl.R +++ b/R/loadDescriptionFromArchiveUrl.R @@ -1,16 +1,55 @@ # loadDescriptionFromArchiveUrl ------------------------------------------------ + #' @noRd #' @noMd #' @keywords internal #' @importFrom utils download.file -loadDescriptionFromArchiveUrl <- function(url) +loadDescriptionFromArchiveUrl <- function(url, path = tempfile()) { - stopifnot(endsWith(url, ".tar.gz")) + untarDescriptionFromUrl(url, path) + + # see remotes:::load_pkg_description + desc <- remotes_read_dcf(path) + names(desc) <- tolower(names(desc)) + desc$path <- path - destfile <- tempfile() + desc +} + +# untarDescriptionFromUrl ------------------------------------------------------ +untarDescriptionFromUrl <- function(url, target = NULL, destdir = tempdir()) +{ + stopifnot(endsWith(url, ".tar.gz")) + tarname <- basename(url) + + # Download .tar.gz file + destfile <- file.path(destdir, tarname) utils::download.file(url, destfile) on.exit(unlink(destfile)) - remotes:::load_pkg_description(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 <- defaultIfNull(target, pathDescription(tarname, destdir)) + + file.copy(target_tmp, target) + + target +} + +# 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/loadDescriptionFromWeb.R b/R/loadDescriptionFromWeb.R index 1451f0a..db90d29 100644 --- a/R/loadDescriptionFromWeb.R +++ b/R/loadDescriptionFromWeb.R @@ -2,26 +2,48 @@ #' @noMd #' @noRd #' @keywords internal -#' @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", + path = tempdir(), + cache = list(descriptions = list(), versions = list()) ) { + #kwb.utils::assignPackageObjects("kwb.package") + #kwb.utils::assignArgumentDefaults(loadDescriptionFromWeb) #name = "sema.berlin";version = "1.6.1";github_user = "KWB-R" - if (isOnCran(name)) { - - versions <- cranVersions(name) + + # Try to load DESCRIPTION from cache + 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)) { + cleanStop("loadDescriptionFromWeb(): !is.null(versions) not implemented!") + #description <- select_version(cran_versions) + } else { + versions <- cranVersions(name, dbg = FALSE) + } + + 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) { - stop_(kwb.utils:::noSuchElements(version, versions$version, "version")) + cleanStop(noSuchElements(version, versions$version, "version")) } url <- versions$package_source_url[versions$version == version] - return(loadDescriptionFromArchiveUrl(url)) + return(loadDescriptionFromArchiveUrl(url, path)) } # Look on KWB's Github account @@ -34,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) { - stop_(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/packageDependenciesByType.R b/R/packageDependenciesByType.R new file mode 100644 index 0000000..9384c1a --- /dev/null +++ b/R/packageDependenciesByType.R @@ -0,0 +1,69 @@ +# 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(type) { + + dependencies <- tools::package_dependencies( + packages, + db = db, + which = type, + recursive = recursive, + reverse = reverse, + verbose = verbose + )[[1L]] + + if (length(dependencies)) { + data.frame( + package = packages, + type = rep(type, length(dependencies)) + ) + } + + }) %>% + stats::setNames(which) %>% + excludeNULL(dbg = FALSE) %>% + do.call(what = rbind) %>% + resetRowNames() +} diff --git a/R/parsePackageDeps.R b/R/parsePackageDeps.R index 86bbf37..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") + parsed <- lapply(pkg[intersect(deps, names(pkg))], remotes_parse_deps) + rbindAll(parsed, nameColumn = "type") } diff --git a/R/plot.R b/R/plotAllDependencies.R similarity index 62% rename from R/plot.R rename to R/plotAllDependencies.R index a92c8e9..12ea003 100644 --- a/R/plot.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, @@ -71,76 +71,13 @@ 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 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 @@ -156,19 +93,19 @@ gradToRad <- function(grad) #' @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)), + ... ) { - 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 -------------------------------------------------------------------- @@ -231,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) { - - stopNodes <- dependencies[[startNode]] - - for (stopNode in stopNodes) { - - drawLink( - nodes, startNode, stopNode, 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/R/plot_package_versions.R b/R/plot_package_versions.R new file mode 100644 index 0000000..e674a34 --- /dev/null +++ b/R/plot_package_versions.R @@ -0,0 +1,107 @@ +# plotPackageVersions ---------------------------------------------------------- + +#' 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 +plotPackageVersions <- 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(selectColumns(versions, "date")), + y_range = r_range + ) + + X <- split(versions, 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 <- 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) +{ + gradToRad(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 = 1) +{ + data <- r * c(cos(phi), sin(phi)) + matrix(data, ncol = 2L, dimnames = list(NULL, c("x", "y"))) +} diff --git a/R/readGithubPackageDescription.R b/R/readGithubPackageDescription.R index be87c7c..4a4d370 100644 --- a/R/readGithubPackageDescription.R +++ b/R/readGithubPackageDescription.R @@ -1,32 +1,44 @@ #' 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 -#' @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) content <- try(gh::gh(endpoint, .token = auth_token), silent = TRUE) if (inherits(content, "try-error")) { + message("Error: ", content) return(NULL) } - txt <- kwb.utils::selectElements(content, "message") + # Save to local DESCRIPTION file + file <- tempfile() + on.exit(unlink(file)) + + contentLines <- strsplit(selectElements(content, "message"), "\r?\n")[[1L]] + + writeLines(contentLines, file) + + # Read local DESCRIPTION file + desc <- remotes_read_dcf(file) - # Read DESCRIPTION from character instead of file - read_dcf <- function(...) { - con <- textConnection(txt) - on.exit(close(con)) - read.dcf(con, ...) - } + # Use package name and version to generate a name for the cached + # DESCRIPTION file. Copy the DESCRITPION file to a file of that name. - # See remotes:::read_dcf - fields <- colnames(read_dcf()) - desc <- as.list(read_dcf(keep.white = fields)[1L, ]) + file.copy(file, file.path(destdir, getUrl( + "cached_desc", + package = selectElements(desc, "Package"), + version = selectElements(desc, "Version") + ))) # See remotes:::load_pkg_description names(desc) <- tolower(names(desc)) diff --git a/R/remotes_imports.R b/R/remotes_imports.R new file mode 100644 index 0000000..8c81d77 --- /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("parse_deps", "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/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-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/R/utils.R b/R/utils.R index a0e12e6..5392d07 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,52 +1,130 @@ -# getUrl ----------------------------------------------------------------------- -#' @noMd -#' @noRd -#' @keywords internal -#' @importFrom kwb.utils selectElements -getUrl <- function(key, ...) +# 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) { - urls <- kwb.utils::resolve(..., x = list( - cran = "https://cran.r-project.org", - 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" - )) - - kwb.utils::selectElements(urls, key) + polar_to_xy(gradToRad(angles.grad)) } -# githubRepo ------------------------------------------------------------------- -githubRepo <- function(github_user, name) +# catAndRun -------------------------------------------------------------------- + +#' @importFrom kwb.utils catAndRun +catAndRun <- kwb.utils::catAndRun + +# catIf ------------------------------------------------------------------------ + +#' @importFrom kwb.utils catIf +catIf <- kwb.utils::catIf + +# cleanStop -------------------------------------------------------------------- +cleanStop <- function(...) { - paste(github_user, name, sep = "/") + stop(..., call. = FALSE) } -# packageInDestdir ------------------------------------------------------------- -#' @noMd -#' @noRd -#' @keywords internal -#' @importFrom kwb.utils safePath -packageInDestdir <- function(package, destdir, verbose = TRUE) +# createDirectory -------------------------------------------------------------- +#' @importFrom kwb.utils createDirectory +createDirectory <- kwb.utils::createDirectory + +# defaultIfNa ------------------------------------------------------------------ +#' @importFrom kwb.utils defaultIfNA +defaultIfNa <- kwb.utils::defaultIfNA + +# defaultIfNull ---------------------------------------------------------------- +#' @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) { - 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)) + seq(from, by = 360/n, length.out = n) +} + +# excludeNull ------------------------------------------------------------------ +#' @importFrom kwb.utils excludeNULL +excludeNull <- kwb.utils::excludeNULL + +# extractSubstring ------------------------------------------------------------- +#' @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 + +# getHomedir ------------------------------------------------------------------- +#' @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 + +# 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) { @@ -59,14 +137,51 @@ readLinesFromUrl <- function(url, silent = TRUE) result } -# stop_ ------------------------------------------------------------------------ -stop_ <- function(...) -{ - stop(..., call. = FALSE) -} +# removeColumns ---------------------------------------------------------------- +#' @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 + +# runInDirectory --------------------------------------------------------------- +#' @importFrom kwb.utils runInDirectory +runInDirectory <- kwb.utils::runInDirectory + +# safePath --------------------------------------------------------------------- +#' @importFrom kwb.utils safePath +safePath <- kwb.utils::safePath + +# safeRowBind ------------------------------------------------------------------ +#' @importFrom kwb.utils safeRowBind +safeRowBind <- kwb.utils::safeRowBind + +# selectColumns ---------------------------------------------------------------- +#' @importFrom kwb.utils selectColumns +selectColumns <- kwb.utils::selectColumns + +# selectElements --------------------------------------------------------------- +#' @importFrom kwb.utils selectElements +selectElements <- kwb.utils::selectElements + +# stopFormatted ---------------------------------------------------------------- +#' @importFrom kwb.utils stopFormatted +stopFormatted <- kwb.utils::stopFormatted + +# removeColumns ---------------------------------------------------------------- +#' @importFrom kwb.utils removeColumns +removeColumns <- kwb.utils::removeColumns -# dirPackageZips --------------------------------------------------------------- -dirPackageZips <- function(package, path) -{ - dir(path, paste0("^", package, "_"), full.names = TRUE) -} 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 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/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/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{ 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..674e9a8 --- /dev/null +++ b/man/cranVersions.Rd @@ -0,0 +1,17 @@ +% 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) +} +\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 +} 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} diff --git a/man/drawDependencies.Rd b/man/drawDependencies.Rd index bd9f6de..8ad3611 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} @@ -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/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/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 +} 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 +} 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 +} diff --git a/man/getPackageLicences.Rd b/man/getPackageLicences.Rd new file mode 100644 index 0000000..0ae46bc --- /dev/null +++ b/man/getPackageLicences.Rd @@ -0,0 +1,21 @@ +% 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, 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{installed.packages()}} +} +\value{ +data frame +} +\description{ +Which Licences are Specified for the Packages? +} 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") 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} 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? +} diff --git a/man/packageDependencies.Rd b/man/packageDependencies.Rd index e49a427..d772c8f 100644 --- a/man/packageDependencies.Rd +++ b/man/packageDependencies.Rd @@ -4,15 +4,47 @@ \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, + verbose = 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{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..e4d2d0f --- /dev/null +++ b/man/packageDependenciesByType.Rd @@ -0,0 +1,49 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/packageDependenciesByType.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 +} 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} 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/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 +} 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 +} diff --git a/man/sortedDependencies.Rd b/man/sortedDependencies.Rd index ef4dd81..fd3e736 100644 --- a/man/sortedDependencies.Rd +++ b/man/sortedDependencies.Rd @@ -4,14 +4,13 @@ \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{package}{name of package(s) 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} +\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, 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? +} 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} 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/test-function-addNodeLabels.R b/tests/testthat/test-function-addNodeLabels.R new file mode 100644 index 0000000..6ad926e --- /dev/null +++ b/tests/testthat/test-function-addNodeLabels.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("addNodeLabels() works", { + + f <- kwb.package::addNodeLabels + + expect_error( + f() + # Argument "nodes" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-allDeps.R b/tests/testthat/test-function-allDeps.R new file mode 100644 index 0000000..3e6693f --- /dev/null +++ b/tests/testthat/test-function-allDeps.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("allDeps() works", { + + f <- kwb.package:::allDeps + + expect_error( + f() + # Argument "name" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-anglesToPoints.R b/tests/testthat/test-function-anglesToPoints.R new file mode 100644 index 0000000..aef9492 --- /dev/null +++ b/tests/testthat/test-function-anglesToPoints.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("anglesToPoints() works", { + + f <- kwb.package::anglesToPoints + + expect_error( + f() + # Argument "angles.grad" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-archivedCranVersions.R b/tests/testthat/test-function-archivedCranVersions.R new file mode 100644 index 0000000..db956ba --- /dev/null +++ b/tests/testthat/test-function-archivedCranVersions.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("archivedCranVersions() works", { + + f <- kwb.package::archivedCranVersions + + expect_error( + f() + # Argument "package" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-cleanStop.R b/tests/testthat/test-function-cleanStop.R new file mode 100644 index 0000000..f1f370d --- /dev/null +++ b/tests/testthat/test-function-cleanStop.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("cleanStop() works", { + + f <- kwb.package:::cleanStop + + expect_error( + f() + # + ) + +}) diff --git a/tests/testthat/test-function-compareInstalledVersions.R b/tests/testthat/test-function-compareInstalledVersions.R new file mode 100644 index 0000000..776b0b5 --- /dev/null +++ b/tests/testthat/test-function-compareInstalledVersions.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("compareInstalledVersions() works", { + + f <- kwb.package::compareInstalledVersions + + expect_error( + f() + # Argument "lib1" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-copyBasePackages.R b/tests/testthat/test-function-copyBasePackages.R new file mode 100644 index 0000000..f803d36 --- /dev/null +++ b/tests/testthat/test-function-copyBasePackages.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("copyBasePackages() works", { + + f <- kwb.package::copyBasePackages + + expect_error( + f() + # Argument "target_lib" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-cranVersions.R b/tests/testthat/test-function-cranVersions.R new file mode 100644 index 0000000..20670b6 --- /dev/null +++ b/tests/testthat/test-function-cranVersions.R @@ -0,0 +1,17 @@ +# +# 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("cranVersions() works", { + + f <- kwb.package::cranVersions + + expect_error( + f() + # Argument "name" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-currentCranVersion.R b/tests/testthat/test-function-currentCranVersion.R new file mode 100644 index 0000000..aaa3a8e --- /dev/null +++ b/tests/testthat/test-function-currentCranVersion.R @@ -0,0 +1,12 @@ +#library(testthat) + +test_that("currentCranVersion() works", { + + f <- kwb.package:::currentCranVersion + + result <- f() + + expect_s3_class(result, "data.frame") + expect_identical(names(result), c("package", "version", "date", "date_type")) + +}) diff --git a/tests/testthat/test-function-defaultLocalCRAN.R b/tests/testthat/test-function-defaultLocalCRAN.R new file mode 100644 index 0000000..b2ceda3 --- /dev/null +++ b/tests/testthat/test-function-defaultLocalCRAN.R @@ -0,0 +1,10 @@ +#library(testthat) + +test_that("defaultLocalCRAN() works", { + + f <- kwb.package:::defaultLocalCRAN + + result <- f() + expect_true(endsWith(result, "/local-cran")) + +}) diff --git a/tests/testthat/test-function-defaultPackageDir.R b/tests/testthat/test-function-defaultPackageDir.R new file mode 100644 index 0000000..e5b3366 --- /dev/null +++ b/tests/testthat/test-function-defaultPackageDir.R @@ -0,0 +1,12 @@ +#library(testthat) + +test_that("defaultPackageDir() works", { + + f <- kwb.package:::defaultPackageDir + + result <- f() + + expect_type(result, "character") + expect_length(result, 1L) + +}) diff --git a/tests/testthat/test-function-detachAllNonSystemPackages.R b/tests/testthat/test-function-detachAllNonSystemPackages.R new file mode 100644 index 0000000..51b5c12 --- /dev/null +++ b/tests/testthat/test-function-detachAllNonSystemPackages.R @@ -0,0 +1,11 @@ +#library(testthat) + +testthat::skip("Do not detach testthat!") + +test_that("detachAllNonSystemPackages() works", { + + f <- kwb.package::detachAllNonSystemPackages + + expect_output(f()) + +}) diff --git a/tests/testthat/test-function-detachRecursively.R b/tests/testthat/test-function-detachRecursively.R new file mode 100644 index 0000000..bac3ece --- /dev/null +++ b/tests/testthat/test-function-detachRecursively.R @@ -0,0 +1,11 @@ +#library(testthat) + +testthat::skip("Do not detach testthat!") + +test_that("detachRecursively() works", { + + f <- kwb.package::detachRecursively + + expect_error(f()) + +}) diff --git a/tests/testthat/test-function-dirPackageZips.R b/tests/testthat/test-function-dirPackageZips.R new file mode 100644 index 0000000..dc762a0 --- /dev/null +++ b/tests/testthat/test-function-dirPackageZips.R @@ -0,0 +1,9 @@ +#library(testthat) + +test_that("dirPackageZips() works", { + + f <- kwb.package:::dirPackageZips + + expect_error(f()) + +}) diff --git a/tests/testthat/test-function-downloadGitHubPackage.R b/tests/testthat/test-function-downloadGitHubPackage.R new file mode 100644 index 0000000..860cc48 --- /dev/null +++ b/tests/testthat/test-function-downloadGitHubPackage.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("downloadGitHubPackage() works", { + + f <- kwb.package::downloadGitHubPackage + + expect_error( + f() + # Argument "repo" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-downloadPackagesFromSnapshot.R b/tests/testthat/test-function-downloadPackagesFromSnapshot.R new file mode 100644 index 0000000..69e3344 --- /dev/null +++ b/tests/testthat/test-function-downloadPackagesFromSnapshot.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("downloadPackagesFromSnapshot() works", { + + f <- kwb.package::downloadPackagesFromSnapshot + + expect_error( + f() + # Argument "packages" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-drawDependencies.R b/tests/testthat/test-function-drawDependencies.R new file mode 100644 index 0000000..fa922b0 --- /dev/null +++ b/tests/testthat/test-function-drawDependencies.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("drawDependencies() works", { + + f <- kwb.package::drawDependencies + + expect_error( + f() + # Argument "nodes" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-draw_circles.R b/tests/testthat/test-function-draw_circles.R new file mode 100644 index 0000000..e28e5b1 --- /dev/null +++ b/tests/testthat/test-function-draw_circles.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("draw_circles() works", { + + f <- kwb.package:::draw_circles + + expect_error( + f() + # Argument "r" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-equidistantAngles.R b/tests/testthat/test-function-equidistantAngles.R new file mode 100644 index 0000000..ba1a226 --- /dev/null +++ b/tests/testthat/test-function-equidistantAngles.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("equidistantAngles() works", { + + f <- kwb.package::equidistantAngles + + expect_error( + f() + # Argument "n" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-exampleLinksAndNodes.R b/tests/testthat/test-function-exampleLinksAndNodes.R new file mode 100644 index 0000000..ca6f691 --- /dev/null +++ b/tests/testthat/test-function-exampleLinksAndNodes.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("exampleLinksAndNodes() works", { + + f <- kwb.package::exampleLinksAndNodes + + expect_error( + f() + # line 8 did not have 4 elements + ) + +}) diff --git a/tests/testthat/test-function-findPackageFilename.R b/tests/testthat/test-function-findPackageFilename.R new file mode 100644 index 0000000..a7536f8 --- /dev/null +++ b/tests/testthat/test-function-findPackageFilename.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("findPackageFilename() works", { + + f <- kwb.package:::findPackageFilename + + expect_error( + f() + # Argument "tarfile" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-getAuthors.R b/tests/testthat/test-function-getAuthors.R new file mode 100644 index 0000000..ce9bb5d --- /dev/null +++ b/tests/testthat/test-function-getAuthors.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("getAuthors() works", { + + f <- kwb.package::getAuthors + + expect_error( + f() + # Argument "package" fehlt (ohne Standardwert) + ) + +}) diff --git a/tests/testthat/test-function-getBinaryPaths.R b/tests/testthat/test-function-getBinaryPaths.R new file mode 100644 index 0000000..65ee84b --- /dev/null +++ b/tests/testthat/test-function-getBinaryPaths.R @@ -0,0 +1,12 @@ +#library(testthat) + +test_that("getBinaryPaths() works", { + + f <- kwb.package:::getBinaryPaths + + result <- f() + + expect_type(result, "character") + expect_true(length(result) > 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..3946035 --- /dev/null +++ b/tests/testthat/test-function-getCranPackageDatabase.R @@ -0,0 +1,12 @@ +#library(testthat) + +test_that("getCranPackageDatabase() works", { + + f <- kwb.package::getCranPackageDatabase + + result <- f() + + expect_s3_class(result, "data.frame") + expect_true(all(c("Package", "Depends", "Imports") %in% names(result))) + +}) 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) + ) + +}) 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..97aa359 --- /dev/null +++ b/vignettes/tutorial.Rmd @@ -0,0 +1,112 @@ +--- +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". + +### 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") +``` + +### What licences are specified for (installed) packages? + +```{r eval = FALSE} +kwb.package::getPackageLicences(kwb.package::systemPackages()) +```