diff --git a/R/create_pkg_codemeta.R b/R/create_pkg_codemeta.R index a591a62..d02251b 100644 --- a/R/create_pkg_codemeta.R +++ b/R/create_pkg_codemeta.R @@ -9,30 +9,46 @@ #' @importFrom glue glue #' @importFrom utils installed.packages #' @export -create_pkg_codemeta <- function(pkgs = get_github_packages(), - libpath = Sys.getenv("R_LIBS_USER"), - dbg = TRUE) { - kwb.utils::catAndRun("Creating codemeta object", - expr = { - withr::with_libpaths( - new = libpath, - code = { - lapply( - pkgs$name, - function(x) { - if (x %in% utils::installed.packages()[, "Package"]) { - print(glue::glue("Writing codemeta for R package {x}")) - codemetar::create_codemeta(pkg = x) - } - else { - message(sprintf("Package '%s' is not installed in - %s", x, libpath)) - } - } - ) - } - ) - }, - dbg = dbg - ) +create_pkg_codemeta <- function( + pkgs = get_github_packages(), + libpath = Sys.getenv("R_LIBS_USER"), + dbg = TRUE +) +{ + cat_and_run <- function(msg, expr) { + kwb.utils::catAndRun(msg, expr, dbg = dbg, newLine = 3L) + } + + # Get package names from input data frame + packages <- kwb.utils::selectColumns(pkgs, "name") + + cat_and_run("Creating codemeta object", { + + withr::with_libpaths(libpath, { + + package_db <- utils::installed.packages() + + is_installed <- packages %in% package_db[, "Package"] + + if (any(!is_installed)) { + n <- sum(!is_installed) + message(sprintf( + "%d %s not installed in '%s': %s", + n, + ifelse(n > 1L, "packages are", "package is"), + libpath, + kwb.utils::stringList(sort(packages[!is_installed])) + )) + } + + lapply(packages[is_installed], function(package) { + cat_and_run( + sprintf("Writing codemeta for R package %s", package), + try(codemetar::create_codemeta(file.path(libpath, package))) + ) + }) + + }) + + }) } diff --git a/R/create_universe_pkgs_json.R b/R/create_universe_pkgs_json.R index 1c0e5d6..55b980c 100644 --- a/R/create_universe_pkgs_json.R +++ b/R/create_universe_pkgs_json.R @@ -12,14 +12,19 @@ #' create_universe_pkgs_json() #' #' -create_universe_pkgs_json <- function(group = "KWB-R", - ignore_pkgs = NULL, - non_r_packages = kwb.pkgstatus::get_non_r_packages(), - github_token = Sys.getenv("GITHUB_PAT")) { - get_github_packages(group = group, - ignore_pkgs = ignore_pkgs, - non_r_packages = non_r_packages, - github_token = github_token) %>% +create_universe_pkgs_json <- function( + group = "KWB-R", + ignore_pkgs = NULL, + non_r_packages = kwb.pkgstatus::get_non_r_packages(), + github_token = Sys.getenv("GITHUB_PAT") +) +{ + get_github_packages( + group = group, + ignore_pkgs = ignore_pkgs, + non_r_packages = non_r_packages, + github_token = github_token + ) %>% dplyr::select(.data$name, .data$url) %>% dplyr::rename(package = .data$name) %>% jsonlite::toJSON(pretty = TRUE) diff --git a/R/download_github.R b/R/download_github.R index a75f5ea..af61181 100644 --- a/R/download_github.R +++ b/R/download_github.R @@ -16,15 +16,18 @@ #' @import remotes #' @importFrom stringr str_split #' -download_github <- function(repo, - ref = NULL, - dest_dir = tempdir(), - use_zip = FALSE, - quiet = FALSE, - auth_token = Sys.getenv("GITHUB_PAT")) { - repo_sep <- as.vector(stringr::str_split(repo, pattern = "/|@", n = 3, simplify = TRUE)) - - +download_github <- function( + repo, + ref = NULL, + dest_dir = tempdir(), + use_zip = FALSE, + quiet = FALSE, + auth_token = Sys.getenv("GITHUB_PAT") +) +{ + repo_sep <- as.vector( + stringr::str_split(repo, pattern = "/|@", n = 3, simplify = TRUE) + ) reference <- if (repo_sep[3] == "") { ref @@ -41,8 +44,8 @@ download_github <- function(repo, ) x$ref <- ifelse(is.null(ref), "" , sprintf("@%s", ref)) + # if(use_zip) { - # # file_ext <- ".zip" # src_dir <- "/zipball/" # } else { @@ -53,7 +56,6 @@ download_github <- function(repo, file_ext <- ifelse(use_zip, ".zip", ".tar.gz") src_dir <- ifelse(use_zip, "/zipball/", "/tarball/") - dest <- file.path(dest_dir, paste0(x$repo, file_ext)) if (!quiet) { @@ -63,7 +65,6 @@ download_github <- function(repo, ) } - src_root <- remotes:::build_url(x$host, "repos", x$username, x$repo) src <- paste0(src_root, src_dir, utils::URLencode(x$ref, reserved = TRUE)) remotes:::download(dest, src, auth_token = x$auth_token) diff --git a/R/get_gh_ratelimit.R b/R/get_gh_ratelimit.R index 4fb703d..d14bab4 100644 --- a/R/get_gh_ratelimit.R +++ b/R/get_gh_ratelimit.R @@ -4,14 +4,15 @@ #' Sys.getenv("GITHUB_PAT") #' @return overview of rate limit #' @export +#' @importFrom dplyr bind_rows #' @importFrom gh gh -#' @importFrom dplyr bind_rows +#' @importFrom kwb.utils selectElements #' @examples #' get_gh_ratelimit() -get_gh_ratelimit <- function(github_token = Sys.getenv("GITHUB_PAT")) { - - res <- gh::gh(endpoint = "https://api.github.com/rate_limit", - .token = github_token) - - dplyr::bind_rows(res$resources,.id = "id") +get_gh_ratelimit <- function(github_token = Sys.getenv("GITHUB_PAT")) +{ + "https://api.github.com/rate_limit" %>% + gh::gh(.token = github_token) %>% + kwb.utils::selectElements("resources") %>% + dplyr::bind_rows(.id = "id") } diff --git a/R/get_github_packages.R b/R/get_github_packages.R index 25d0c37..0a14ec4 100644 --- a/R/get_github_packages.R +++ b/R/get_github_packages.R @@ -16,23 +16,30 @@ #' head(pkgs) #' } #' -get_github_packages <- function(group = "KWB-R", - ignore_pkgs = NULL, - non_r_packages = kwb.pkgstatus::get_non_r_packages(), - github_token = Sys.getenv("GITHUB_PAT")) { +get_github_packages <- function( + group = "KWB-R", + ignore_pkgs = NULL, + non_r_packages = kwb.pkgstatus::get_non_r_packages(), + github_token = Sys.getenv("GITHUB_PAT") +) +{ repos <- kwb.pkgstatus::get_github_repos(group, github_token) pkgs <- repos[!repos$name %in% non_r_packages, ] - if (!is.null(ignore_pkgs)) { - ignore_condition <- pkgs$name %in% ignore_pkgs - if (any(ignore_condition)) { - message(sprintf( - "Ignoring R packages %s as requested!", - paste(ignore_pkgs, collapse = ", ") - )) - pkgs <- pkgs[!ignore_condition, ] - } + if (is.null(ignore_pkgs)) { + return(pkgs) } - return(pkgs) + + if (any(is_ignored <- pkgs$name %in% ignore_pkgs)) { + + message(sprintf( + "Ignoring R packages %s as requested!", + paste(ignore_pkgs, collapse = ", ") + )) + + pkgs <- pkgs[!is_ignored, ] + } + + pkgs } diff --git a/R/get_pkg_dependencies.R b/R/get_pkg_dependencies.R index 78dafeb..99e4c34 100644 --- a/R/get_pkg_dependencies.R +++ b/R/get_pkg_dependencies.R @@ -1,3 +1,5 @@ +# get_pkg_dependencies --------------------------------------------------------- + #' Get package dependencies #' #' @param pkgs character vector with package names @@ -13,23 +15,84 @@ #' get_pkg_dependencies(pkgs$name) #' } #' -get_pkg_dependencies <- function(pkgs, - library_path = .libPaths(), - dbg = TRUE, - ...) { +get_pkg_dependencies <- function( + pkgs, + library_path = .libPaths(), + dbg = TRUE, + ... +) +{ + get_pkg_dependencies_impl( + pkgs, + recursive = FALSE, + ..., + library_path = library_path, + dbg = dbg + ) +} +# get_recursive_pkg_dependencies ----------------------------------------------- + +#' Get recursive package dependencies +#' +#' @param pkgs character vector with package names +#' @param library_path character vector with path(s) to R library (default: .libPaths()) +#' @param dbg logical if debug should be shown (default: TRUE) +#' @param ... additional arguments passed to packrat:::getPackageDependencies() +#' @return list with recursive package dependencies +#' @importFrom stats setNames +#' @export +#' @examples +#' \dontrun{ +#' pkgs <- pkgmeta::get_github_packages() +#' get_recursive_pkg_dependencies(pkgs$name) +#' } +#' +get_recursive_pkg_dependencies <- function( + pkgs, + library_path = .libPaths(), + dbg = TRUE, + ... +) +{ + get_pkg_dependencies_impl( + pkgs, + recursive = TRUE, + ..., + library_path = library_path, + dbg = dbg + ) +} - pkgs_installed <- pkgs[pkgs %in% rownames(installed.packages(lib.loc = library_path))] +# get_pkg_dependencies_impl ---------------------------------------------------- +get_pkg_dependencies_impl <- function( + pkgs, + recursive, + ..., + library_path = .libPaths(), + dbg = TRUE +) +{ + dependency_function <- if (recursive) { + packrat:::recursivePackageDependencies + } else { + packrat:::getPackageDependencies + } - stats::setNames(lapply(pkgs_installed, function(pkg) { - kwb.utils::catAndRun(sprintf("Getting recursive dependencies for '%s'", pkg), - expr = { - packrat:::getPackageDependencies(pkg, - lib.loc = library_path, - ... - ) - }, - dbg = dbg)}), - nm = pkgs_installed) + package_db <- installed.packages(lib.loc = library_path) + pkgs_installed <- pkgs[pkgs %in% rownames(package_db)] + pkgs_installed %>% + lapply(function(pkg) { + kwb.utils::catAndRun( + sprintf( + "Getting %s dependencies for '%s'", + ifelse(recursive, "recursive", "non-recursive"), + pkg + ), + dependency_function(pkg, lib.loc = library_path, ...), + dbg = dbg + ) + }) %>% + stats::setNames(pkgs_installed) } diff --git a/R/get_recursive_pkg_dependencies.R b/R/get_recursive_pkg_dependencies.R deleted file mode 100644 index a5b8396..0000000 --- a/R/get_recursive_pkg_dependencies.R +++ /dev/null @@ -1,32 +0,0 @@ -#' Get recursive package dependencies -#' -#' @param pkgs character vector with package names -#' @param library_path character vector with path(s) to R library (default: .libPaths()) -#' @param dbg logical if debug should be shown (default: TRUE) -#' @param ... additional arguments passed to packrat:::getPackageDependencies() -#' @return list with recursive package dependencies -#' @importFrom stats setNames -#' @export -#' @examples -#' \dontrun{ -#' pkgs <- pkgmeta::get_github_packages() -#' get_recursive_pkg_dependencies(pkgs$name) -#' } -#' -get_recursive_pkg_dependencies <- function(pkgs, library_path = .libPaths(), - dbg = TRUE, - ...) { - - - pkgs_installed <- pkgs[pkgs %in% rownames(installed.packages(lib.loc = library_path))] - - stats::setNames(lapply(pkgs_installed, function(pkg) { - kwb.utils::catAndRun(sprintf("Getting recursive dependencies for '%s'", pkg), - expr = { - packrat:::recursivePackageDependencies(pkg, - lib.loc = library_path, - ...)}, - dbg = dbg)}), - nm = pkgs_installed) - -} diff --git a/R/github_commits.R b/R/github_commits.R index 509dbd3..bf9fc5b 100644 --- a/R/github_commits.R +++ b/R/github_commits.R @@ -15,47 +15,62 @@ #' pkg_commits <- pkgmeta::get_github_commits("kwb-r/kwb.utils") #' head(pkg_commits ) #'} -get_github_commits <- function(repo, github_token = Sys.getenv("GITHUB_PAT")) +get_github_commits <- function( + repo, + github_token = Sys.getenv("GITHUB_PAT") +) { + get_commits <- function(repo, per_page = 100L) { + n_results <- per_page + page <- 1L + commits_list <- list() - get_commits <- function(repo, per_page = 100) { - - n_results <- per_page - page <- 1L - commits_list <- list() - while(n_results == per_page) { - message(sprintf("Getting commits for repo %s (page = %d)", repo, page)) - commits_list[[page]] <- gh::gh(endpoint = sprintf("GET /repos/%s/commits?page=%d&per_page=%d", - repo, - page, - per_page), - .token = github_token) - n_results <- length(commits_list[[page]]) - page <- page + 1L - } + while(n_results == per_page) { + + message(sprintf("Getting commits for repo %s (page = %d)", repo, page)) + + commits_list[[page]] <- gh::gh( + endpoint = sprintf( + "GET /repos/%s/commits?page=%d&per_page=%d", + repo, + page, + per_page + ), + .token = github_token + ) - do.call(what = c, args = commits_list) + n_results <- length(commits_list[[page]]) + page <- page + 1L + } + + do.call(what = c, args = commits_list) } + commits <- get_commits(repo) commits_list <- lapply(seq_along(commits), function(commit_id) { - sel_commit <- commits[[commit_id]] - - data.frame(repo = repo, - sha = sel_commit$sha, - author_login = ifelse(is.null(sel_commit$author$login), - NA_character_, - sel_commit$author$login), - author_name = sel_commit$commit$committer$name, - author_email = sel_commit$commit$committer$email, - datetime = lubridate::as_datetime(sel_commit$commit$author$date), - message = sel_commit$commit$message) - }) + sel_commit <- commits[[commit_id]] + + data.frame( + repo = repo, + sha = sel_commit$sha, + author_login = ifelse( + is.null(sel_commit$author$login), + NA_character_, + sel_commit$author$login + ), + author_name = sel_commit$commit$committer$name, + author_email = sel_commit$commit$committer$email, + datetime = lubridate::as_datetime(sel_commit$commit$author$date), + message = sel_commit$commit$message + ) - dplyr::bind_rows(commits_list) %>% dplyr::arrange(dplyr::desc(.data$datetime)) + }) + dplyr::bind_rows(commits_list) %>% + dplyr::arrange(dplyr::desc(.data$datetime)) } #' Get Github Commits for Multiple Repos @@ -76,39 +91,42 @@ get_github_commits <- function(repo, github_token = Sys.getenv("GITHUB_PAT")) #' pkgs_commits <- pkgmeta::get_github_commits_repos(repos) #' head(pkgs_commits) #' } -get_github_commits_repos <- function(repos, github_token = Sys.getenv("GITHUB_PAT")) +get_github_commits_repos <- function( + repos, + github_token = Sys.getenv("GITHUB_PAT") +) { + pkg_commit_list <- lapply(repos, function(repo) { + kwb.utils::catAndRun( + sprintf("Repo: %s", repo), + try(get_github_commits(repo, github_token = github_token)) + ) + }) -pkg_commit_list <- lapply(repos, function(repo) { - kwb.utils::catAndRun(messageText = sprintf("Repo: %s", repo), - expr = { - try(get_github_commits(repo, github_token = github_token))})}) - -has_commit <- which(!sapply(seq_len(length(pkg_commit_list)), - function(i) { - attr(pkg_commit_list[[i]], "class") == "try-error" - }) - ) - -dplyr::bind_rows(pkg_commit_list[has_commit ]) %>% -tidyr::separate("repo", c("owner", "repo"), sep = "/") %>% -dplyr::mutate(author_login = dplyr::if_else(is.na(.data$author_login), - .data$author_name, - .data$author_login)) %>% -dplyr::mutate(author_login = kwb.utils::multiSubstitute(.data$author_login, - replacements = list("Andreas Matzinger" = "amatzi", - "Hauke Sonnenberg" = "hsonne", - "Mathias Riechel" = "mriech", - "Roberto Tatis-Muvdi|RobertoTatisMuvdi" = "robetatis", - "Michael Stapf" = "mstapf1", - "Mathias Riechel" = "mriech", - "Michael Rustler" = "mrustl", - "praktikant20" = "klaaskenda", - "Fabian Mor\u00F3n Zirfas|ff6347" = "fabianmoronzirfas", - "kwb.pkgbuild::use_autopkgdown\\(\\)|SarvaPulla|sarva|Sarva|jirikadlec2|Jeremy Fowler|rfun|jsadler2|rizts|testuser" = "external")) - ) %>% -dplyr::filter(.data$author_login != "external") - - + has_commit <- which(!sapply(pkg_commit_list, inherits, "try-error")) + + dplyr::bind_rows(pkg_commit_list[has_commit ]) %>% + tidyr::separate("repo", c("owner", "repo"), sep = "/") %>% + dplyr::mutate( + author_login = dplyr::if_else( + is.na(.data$author_login), + .data$author_name, + .data$author_login + ) + ) %>% + dplyr::mutate( + author_login = kwb.utils::multiSubstitute(.data$author_login, list( + "Andreas Matzinger" = "amatzi", + "Hauke Sonnenberg" = "hsonne", + "Mathias Riechel" = "mriech", + "Roberto Tatis-Muvdi|RobertoTatisMuvdi" = "robetatis", + "Michael Stapf" = "mstapf1", + "Mathias Riechel" = "mriech", + "Michael Rustler" = "mrustl", + "praktikant20" = "klaaskenda", + "Fabian Mor\u00F3n Zirfas|ff6347" = "fabianmoronzirfas", + "kwb.pkgbuild::use_autopkgdown\\(\\)|SarvaPulla|sarva|Sarva|jirikadlec2|Jeremy Fowler|rfun|jsadler2|rizts|testuser" = "external" + )) + ) %>% + dplyr::filter(.data$author_login != "external") } - diff --git a/R/github_package_versions.R b/R/github_package_versions.R index 3e1f677..4c9dc12 100644 --- a/R/github_package_versions.R +++ b/R/github_package_versions.R @@ -15,21 +15,22 @@ #' pkg_versions <- pkgmeta::github_package_versions("kwb-r/kwb.utils") #' head(pkg_versions) #'} -github_package_versions <- function(repo, github_token = Sys.getenv("GITHUB_PAT")) +github_package_versions <- function( + repo, + github_token = Sys.getenv("GITHUB_PAT") +) { - releases_url <- function(repo) sprintf( - "https://api.github.com/repos/%s/releases", repo - ) - - releases <- gh::gh(endpoint = releases_url(repo), - per_page = 100, - .token = github_token) + releases <- "https://api.github.com/repos/%s/releases" %>% + sprintf(repo) %>% + gh::gh(per_page = 100L, .token = github_token) - owner_repo <- as.character(stringr::str_split_fixed(repo, pattern = "/", n = 2)) + owner_repo <- repo %>% + stringr::str_split_fixed(pattern = "/", n = 2L) %>% + as.character() data.frame( - owner = owner_repo[1], - repo = owner_repo[2], + owner = owner_repo[1L], + repo = owner_repo[2L], tag = sapply(releases, kwb.utils::selectElements, "tag_name"), date = as.Date(sapply(releases, kwb.utils::selectElements, "published_at")), author_id = purrr::map_chr(purrr::map(releases, "author"), "login") @@ -51,16 +52,22 @@ github_package_versions <- function(repo, github_token = Sys.getenv("GITHUB_PAT" #' pkgs_versions <- pkgmeta::github_packages_versions(repos) #' head(pkgs_versions) #' } -github_packages_versions <- function(repos, github_token = Sys.getenv("GITHUB_PAT")) +github_packages_versions <- function( + repos, + github_token = Sys.getenv("GITHUB_PAT") +) { versions <- lapply(repos, function(repo) { - kwb.utils::catAndRun(sprintf("Repo: %s", repo), expr = try( - github_package_versions(repo, github_token = github_token), - silent = TRUE - )) + kwb.utils::catAndRun( + sprintf("Repo: %s", repo), + expr = try( + github_package_versions(repo, github_token = github_token), + silent = TRUE + ) + ) }) - has_release <- ! sapply(versions, inherits, "try-error") + has_release <- !sapply(versions, inherits, "try-error") dplyr::bind_rows(versions[has_release]) } diff --git a/R/install_kwb_github_packages.R b/R/install_kwb_github_packages.R index 7aeee6a..427d00a 100644 --- a/R/install_kwb_github_packages.R +++ b/R/install_kwb_github_packages.R @@ -9,21 +9,21 @@ #' @export #' @importFrom remotes install_github -install_kwb_github_packages <- function(pkgs_kwb, - dependencies = TRUE, - quiet = TRUE, - ...) { - pkgs_kwb_github <- sprintf("KWB-R/%s", pkgs_kwb) +install_kwb_github_packages <- function( + pkgs_kwb, + dependencies = TRUE, + quiet = TRUE, + ... +) +{ + sapply(paste0("KWB-R/", pkgs_kwb), function(repo) { + message("Installing R package: ", repo) + try(remotes::install_github( + repo = repo, + dependencies = dependencies, + quiet = quiet, + ... + )) + }) - - sapply( - pkgs_kwb_github, - FUN = function(gh_repo) { - message(sprintf("Installing R package: %s", gh_repo)) - try(remotes::install_github(repo = gh_repo, - dependencies = dependencies, - quiet = quiet, - ...)) - } - ) } diff --git a/R/plot_commits_github.R b/R/plot_commits_github.R index 9bb422b..273e80f 100644 --- a/R/plot_commits_github.R +++ b/R/plot_commits_github.R @@ -16,14 +16,17 @@ #' pkgmeta::plot_commits_github(repos_commits) #' } #' -plot_commits_github <- function(repos_commits) { +plot_commits_github <- function(repos_commits) +{ n_commits <- repos_commits %>% dplyr::count(.data$author_login) %>% dplyr::rename(n_commits = .data$n) repos_commits %>% dplyr::left_join(n_commits, by = "author_login") %>% - dplyr::mutate(user = sprintf("%s (n = %d)", .data$author_login, .data$n_commits)) %>% + dplyr::mutate( + user = sprintf("%s (n = %d)", .data$author_login, .data$n_commits) + ) %>% ggplot2::ggplot(ggplot2::aes( x = as.Date(.data$datetime) , y = forcats::fct_reorder(.data$repo, .data$datetime), @@ -39,5 +42,4 @@ plot_commits_github <- function(repos_commits) { y = "Repo", x = "Date" ) - } diff --git a/R/plot_r_releases.R b/R/plot_r_releases.R index 81667b5..3bee9dd 100644 --- a/R/plot_r_releases.R +++ b/R/plot_r_releases.R @@ -9,33 +9,53 @@ #' @examples #' releases <- get_r_releases() #' head(releases) -get_r_releases <- function(releases = rversions::r_versions(dots = TRUE)) { +get_r_releases <- function(releases = rversions::r_versions(dots = TRUE)) +{ releases %>% - tidyr::separate(col = "version", - into = c("major", "minor", "patch"), - sep = "\\.", - remove = FALSE) %>% - dplyr::mutate(patch = dplyr::if_else(is.na(.data$patch), 0L, as.integer(.data$patch)), - major = as.integer(.data$major), - minor = as.integer(.data$minor), - diff.major = .data$major - dplyr::lag(.data$major, n = 1L), - diff.minor = .data$minor - dplyr::lag(.data$minor, n = 1L), - diff.patch = .data$patch - dplyr::lag(.data$patch, n = 1L), - release_type = dplyr::if_else(.data$diff.major > 0, - "Major", - dplyr::if_else(.data$diff.minor > 0, - "Minor", - dplyr::if_else(.data$diff.patch > 0, - "Patch", - "Initial")))) %>% - dplyr::mutate(release_type = dplyr::if_else(is.na(.data$release_type), - "Initial", - .data$release_type), - label = sprintf("v%s (%s): %s", - .data$version, - .data$date, - .data$release_type)) - + tidyr::separate( + col = "version", + into = c("major", "minor", "patch"), + sep = "\\.", + remove = FALSE + ) %>% + dplyr::mutate( + patch = dplyr::if_else( + is.na(.data$patch), + 0L, + as.integer(.data$patch) + ), + major = as.integer(.data$major), + minor = as.integer(.data$minor), + diff.major = .data$major - dplyr::lag(.data$major, n = 1L), + diff.minor = .data$minor - dplyr::lag(.data$minor, n = 1L), + diff.patch = .data$patch - dplyr::lag(.data$patch, n = 1L), + release_type = dplyr::if_else( + .data$diff.major > 0, + "Major", + dplyr::if_else( + .data$diff.minor > 0, + "Minor", + dplyr::if_else( + .data$diff.patch > 0, + "Patch", + "Initial" + ) + ) + ) + ) %>% + dplyr::mutate( + release_type = dplyr::if_else( + is.na(.data$release_type), + "Initial", + .data$release_type + ), + label = sprintf( + "v%s (%s): %s", + .data$version, + .data$date, + .data$release_type + ) + ) } #' Plot R Releases @@ -50,22 +70,28 @@ get_r_releases <- function(releases = rversions::r_versions(dots = TRUE)) { #' \dontrun{ #' plot_r_releases() #' } -plot_r_releases <- function(r_releases = get_r_releases(), - title = "R Releases") { - -g <- r_releases %>% -ggplot2::ggplot(ggplot2::aes_string(x = "date", - y = "major", - col = "release_type", - label = "label")) + -ggplot2::geom_point(ggplot2::aes(alpha = 0.5)) + -ggplot2::theme_bw() + -ggplot2::scale_y_discrete() + -ggplot2::labs(title = title, - x = "Date", - y = "Major Release Version", - color = "Type", - alpha = "") +plot_r_releases <- function( + r_releases = get_r_releases(), + title = "R Releases" +) +{ + g <- r_releases %>% + ggplot2::ggplot(ggplot2::aes_string( + x = "date", + y = "major", + col = "release_type", + label = "label" + )) + + ggplot2::geom_point(ggplot2::aes(alpha = 0.5)) + + ggplot2::theme_bw() + + ggplot2::scale_y_discrete() + + ggplot2::labs( + title = title, + x = "Date", + y = "Major Release Version", + color = "Type", + alpha = "" + ) -plotly::ggplotly(g, tooltip = "label") + plotly::ggplotly(g, tooltip = "label") } diff --git a/R/plot_rpackages.R b/R/plot_rpackages.R index 344550f..84422d0 100644 --- a/R/plot_rpackages.R +++ b/R/plot_rpackages.R @@ -16,14 +16,19 @@ #' pkgs <- get_github_packages() #' plot_github_pkgs_over_time(pkgs)} #' -plot_github_pkgs_over_time <- function(df_pkgs, - last_update = Sys.time()) { - fakin_date_start <- lubridate::as_datetime("2017-05-01") +plot_github_pkgs_over_time <- function( + df_pkgs, + last_update = Sys.time() +) +{ + as_date <- lubridate::as_datetime + + fakin_date_start <- as_date("2017-05-01") df_pkgs %>% dplyr::mutate( - created_at = lubridate::as_datetime(.data$created_at), - pushed_at = lubridate::as_datetime(.data$pushed_at) + created_at = as_date(.data$created_at), + pushed_at = as_date(.data$pushed_at) ) %>% ggplot2::ggplot(ggplot2::aes( x = .data$created_at, @@ -33,9 +38,11 @@ plot_github_pkgs_over_time <- function(df_pkgs, xintercept = fakin_date_start, size = 2, alpha = 0.5, col = "grey" ) + - ggplot2::geom_segment(ggplot2::aes(yend = .data$name, xend = .data$pushed_at), + ggplot2::geom_segment( + ggplot2::aes(yend = .data$name, xend = .data$pushed_at), size = 1.3, - arrow = ggplot2::arrow(length = ggplot2::unit(0.1, "inches")) + arrow = ggplot2::arrow(length = ggplot2::unit(0.1, "inches") + ) ) + ggplot2::theme_bw() + ggplot2::labs( @@ -43,9 +50,12 @@ plot_github_pkgs_over_time <- function(df_pkgs, subtitle = glue::glue("Last update: {last_update}"), y = "Repository Name", x = "Date", - caption = glue::glue("Start of the arrow is the first release on Github, while the end of the arrow -represents the lasted 'push' activity to the repository. The vertical grey line -stands for the start date ({fakin_date_start}) of the FAKIN project at KWB which -serves as a booster of this publishing process (last update: {last_update}") + caption = glue::glue(paste0( + "Start of the arrow is the first release on Github, while the end of ", + "the arrow represents the lasted 'push' activity to the repository. ", + "The vertical grey line stands for the start date ", + "({fakin_date_start}) of the FAKIN project at KWB which serves as a ", + "booster of this publishing process (last update: {last_update})" + )) ) } diff --git a/R/plot_rpackages_releases.R b/R/plot_rpackages_releases.R index ac291d1..65b0576 100644 --- a/R/plot_rpackages_releases.R +++ b/R/plot_rpackages_releases.R @@ -18,8 +18,11 @@ #' plot_github_pkgs_releases(pkgs_releases) #' } #' -plot_github_pkgs_releases <- function(pkgs_releases, - last_update = Sys.time()) { +plot_github_pkgs_releases <- function( + pkgs_releases, + last_update = Sys.time() +) +{ # fakin_date_start <- lubridate::as_date("2017-05-01") pkgs_releases %>% diff --git a/R/travis_pkg_install_script.R b/R/travis_pkg_install_script.R index 480bd66..b596ad2 100644 --- a/R/travis_pkg_install_script.R +++ b/R/travis_pkg_install_script.R @@ -1,18 +1,17 @@ #' Travis Package Install Script +#' #' @description Needs to be Run before rendering vignettes #' @param pkgs dataframe with R packages as retrieved by #' get_github_packages() #' @return installs kwb-r packages #' @export -travis_pkg_install_script <- function(pkgs = pkgmeta::get_github_packages()) { - sapply( - pkgs$full_name, - FUN = function(pkg) { - try(remotes::install_github( - repo = pkg, - dependencies = TRUE, - upgrade = "always" - )) - } - ) +travis_pkg_install_script <- function(pkgs = pkgmeta::get_github_packages()) +{ + sapply(pkgs$full_name, function(pkg) { + try(remotes::install_github( + repo = pkg, + dependencies = TRUE, + upgrade = "always" + )) + }) } diff --git a/R/write_github_repos_json.R b/R/write_github_repos_json.R index de3da8d..69eac0a 100644 --- a/R/write_github_repos_json.R +++ b/R/write_github_repos_json.R @@ -6,45 +6,46 @@ #' @importFrom tibble tibble #' @importFrom dplyr bind_rows #' -get_github_topics <- function(full_names = get_github_full_names()) { +get_github_topics <- function(full_names = get_github_full_names()) +{ + repos <- lapply(full_names, function(full_name) { - - repos <- lapply(full_names, FUN = function(full_name) { topics <- try(silent = TRUE, gh::gh( - endpoint = "GET /repos/:full_name/topics", - full_name = full_name, - .send_headers = c(Accept = "application/vnd.github.mercy-preview+json") - )) - - if (! inherits(topics, "try-error")) { + endpoint = "GET /repos/:full_name/topics", + full_name = full_name, + .send_headers = c(Accept = "application/vnd.github.mercy-preview+json") + )) + + na_entry <- tibble::tibble( + full_name = full_name, + topics = NA_character_ + ) + + if (inherits(topics, "try-error")) { + return(na_entry) + } topics_vector <- unlist(topics$names) - if(length(topics_vector) > 0) { - - tibble::tibble(full_name = full_name, - topics = topics_vector) - } else { - tibble::tibble(full_name = full_name, - topics = NA_character_) + if (length(topics_vector) == 0L) { + return(na_entry) } - } else { - - tibble::tibble(full_name = full_name, - topics = NA_character_) - } + tibble::tibble( + full_name = full_name, + topics = topics_vector + ) }) dplyr::bind_rows(repos) - } #' @keywords internal #' @noRd #' -get_github_full_names <- function(github_repos = get_github_repos()) { +get_github_full_names <- function(github_repos = get_github_repos()) +{ vapply(github_repos, "[[", "", "full_name") } @@ -57,23 +58,26 @@ get_github_full_names <- function(github_repos = get_github_repos()) { #' https://developer.github.com/v3/ (e.g. type = "public") #' @importFrom gh gh #' @export -get_github_repos <- function (group = "KWB-R", - github_token = Sys.getenv("GITHUB_PAT"), - dbg = TRUE, - ...) { - - msg <- sprintf(paste("\nFetching Github metadata for", - "repos of organisation '%s' at '%s'"), - group, - sprintf("https://github.com/%s/", group)) - - kwb.utils::catAndRun(msg, - expr = { - gh_repos <- gh::gh(endpoint = sprintf("GET /orgs/%s/repos?per_page=100", - group), .token = github_token, - ...)}, - dbg = dbg) - +get_github_repos <- function ( + group = "KWB-R", + github_token = Sys.getenv("GITHUB_PAT"), + dbg = TRUE, + ... +) +{ + kwb.utils::catAndRun( + messageText = sprintf( + "\nFetching Github metadata for repos of organisation '%s' at '%s'", + group, + sprintf("https://github.com/%s/", group) + ), + dbg = dbg, + expr = gh::gh( + endpoint = sprintf("GET /orgs/%s/repos?per_page=100", group), + .token = github_token, + ... + ) + ) } #' Write Github Metadata to JSON @@ -87,29 +91,27 @@ get_github_repos <- function (group = "KWB-R", #' @importFrom jsonlite toJSON write_json #' @importFrom kwb.utils catAndRun #' @export -write_github_repos_json <- function(github_repos = get_github_repos(), - file = file.path(getwd(), "github.json"), - dbg = TRUE) { - - - repo_html_url <- vapply(github_repos, "[[", "", "html_url") - repo_html_url <- repo_html_url[order(repo_html_url)] - repo_names <- vapply(github_repos, "[[", "", "name") - repo_names <- repo_names[order(repo_names)] - - n_repos <- length(repo_names) +write_github_repos_json <- function( + github_repos = get_github_repos(), + file = file.path(getwd(), "github.json"), + dbg = TRUE +) +{ + fetch_sorted <- function(what) { + sort(vapply(github_repos, "[[", "", what)) + } - kwb.utils::catAndRun(sprintf("Writting '%s' file for %d repos:\n%s", - file, - n_repos, - paste0("- ", - repo_names, - ": ", - repo_html_url, - collapse = "\n")), - expr = { - jsonlite::write_json(github_repos, file) - }, - dbg = dbg + repo_html_url <- fetch_sorted(what = "html_url") + repo_names <- fetch_sorted(what = "name") + + kwb.utils::catAndRun( + sprintf( + "Writting '%s' file for %d repos:\n%s", + file, + length(repo_names), + paste0("- ", repo_names, ": ", repo_html_url, collapse = "\n") + ), + expr = jsonlite::write_json(github_repos, file), + dbg = dbg ) } diff --git a/R/write_pkg_codemeta_json.R b/R/write_pkg_codemeta_json.R index 1e0f959..7d6986e 100644 --- a/R/write_pkg_codemeta_json.R +++ b/R/write_pkg_codemeta_json.R @@ -9,17 +9,20 @@ #' @importFrom jsonlite write_json #' @importFrom kwb.utils catAndRun #' @export -write_pkg_codemeta_json <- function(codemeta = create_pkg_codemeta(), - file = file.path(getwd(), "codemetar.json"), - dbg = TRUE) { - kwb.utils::catAndRun(sprintf("Writting codemeta to '%s'", file), - expr = { - jsonlite::write_json(codemeta, file, - useBytes = TRUE, - pretty = TRUE, - auto_unbox = TRUE - ) - }, - dbg = dbg +write_pkg_codemeta_json <- function( + codemeta = create_pkg_codemeta(), + file = file.path(getwd(), "codemetar.json"), + dbg = TRUE +) +{ + kwb.utils::catAndRun( + sprintf("Writting codemeta to '%s'", file), + dbg = dbg, + expr = jsonlite::write_json( + codemeta, file, + useBytes = TRUE, + pretty = TRUE, + auto_unbox = TRUE + ) ) } diff --git a/man/get_recursive_pkg_dependencies.Rd b/man/get_recursive_pkg_dependencies.Rd index f865fef..41c942e 100644 --- a/man/get_recursive_pkg_dependencies.Rd +++ b/man/get_recursive_pkg_dependencies.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/get_recursive_pkg_dependencies.R +% Please edit documentation in R/get_pkg_dependencies.R \name{get_recursive_pkg_dependencies} \alias{get_recursive_pkg_dependencies} \title{Get recursive package dependencies}