From 04115296f36bfb729d71e5723b7a567f47ab927d Mon Sep 17 00:00:00 2001 From: hsonne Date: Thu, 9 Nov 2023 18:16:06 +0100 Subject: [PATCH 1/3] Use private funcs without R CMD check warnings --- DESCRIPTION | 2 +- NAMESPACE | 1 + R/deploy_site_github_with_extra_files.R | 5 +++-- R/use_badges.R | 3 ++- R/use_codecov.R | 5 +++-- R/use_pkg_skeleton.R | 9 +++++++-- 6 files changed, 17 insertions(+), 8 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5d19095..aa5ed1f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -53,4 +53,4 @@ Remotes: ByteCompile: true Encoding: UTF-8 LazyData: true -RoxygenNote: 7.2.1 +RoxygenNote: 7.2.3 diff --git a/NAMESPACE b/NAMESPACE index 2704fe2..00d995d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -74,5 +74,6 @@ importFrom(usethis,use_git_ignore) importFrom(usethis,use_mit_license) importFrom(usethis,use_pkgdown) importFrom(usethis,use_template) +importFrom(utils,getFromNamespace) importFrom(utils,tail) importFrom(withr,with_dir) diff --git a/R/deploy_site_github_with_extra_files.R b/R/deploy_site_github_with_extra_files.R index 0120b6c..a5c3c5b 100644 --- a/R/deploy_site_github_with_extra_files.R +++ b/R/deploy_site_github_with_extra_files.R @@ -220,6 +220,7 @@ copy_files_from_vignettes_dir_to_deploy_dir <- function( #' jekyll rendering. #' @param ... Additional arguments passed to pkgdown::build_site() #' @inheritParams deploy_site_github_with_extra_files +#' @importFrom utils getFromNamespace #' @export deploy_to_branch_with_extra_files <- function(pkg = ".", vignettes_file_pattern_to_copy = "\\.json", @@ -258,7 +259,7 @@ deploy_to_branch_with_extra_files <- function(pkg = ".", if (clean) { rule("Cleaning files from old site", line = 1) - pkgdown:::clean_site(pkg) + pkgdown::clean_site(pkg) } pkgdown::build_site(pkg, devel = FALSE, preview = FALSE, install = FALSE, ...) @@ -271,7 +272,7 @@ deploy_to_branch_with_extra_files <- function(pkg = ".", ) if (github_pages) { - pkgdown:::build_github_pages(pkg) + utils::getFromNamespace("build_github_pages", "pkgdown")(pkg) } github_push(dest_dir, commit_message, remote, branch) diff --git a/R/use_badges.R b/R/use_badges.R index 9255450..259b1c2 100644 --- a/R/use_badges.R +++ b/R/use_badges.R @@ -137,10 +137,11 @@ use_badge_codecov <- function(repo = NULL, user = "KWB-R", domain = "github") #' valid arguments are: "experimental", "maturing", "stable", "retired", #' "archived", "dormant", "questioning"), (default: "experiment") #' @return generates lifecycle badge link +#' @importFrom utils getFromNamespace #' @export use_badge_lifecycle <- function(stage = "experimental") { - stages <- usethis:::stages + stages <- utils::getFromNamespace("stages", "usethis") stage <- match.arg(tolower(stage), names(stages)) kwb.utils::resolve( diff --git a/R/use_codecov.R b/R/use_codecov.R index cda178a..77deced 100644 --- a/R/use_codecov.R +++ b/R/use_codecov.R @@ -3,11 +3,12 @@ #' Adds codecov.yml #' @return writes codecov.yml and adds it .Rbuildignore #' @importFrom usethis use_template +#' @importFrom utils getFromNamespace #' @export use_codecov <- function() { - usethis:::check_uses_github_actions() - usethis:::use_dependency("covr", "Suggests") + utils::getFromNamespace("check_uses_github_actions", "usethis")() + utils::getFromNamespace("use_dependency", "usethis")("covr", "Suggests") if (! usethis::use_template("codecov.yml", ignore = TRUE)) { return(invisible(FALSE)) diff --git a/R/use_pkg_skeleton.R b/R/use_pkg_skeleton.R index c981b85..25390c2 100644 --- a/R/use_pkg_skeleton.R +++ b/R/use_pkg_skeleton.R @@ -7,6 +7,7 @@ #' @importFrom usethis use_template use_git_ignore #' @importFrom fs dir_create file_create #' @importFrom desc desc_set +#' @importFrom utils getFromNamespace #' @examples #' ## valid pkg folder #' pkg_name <- "pkgname" @@ -27,10 +28,14 @@ use_pkg_skeleton <- function(pkg_name) usethis::use_git_ignore(".Rproj.user") - if (usethis:::is_package()) { + if (utils::getFromNamespace("is_package", "usethis")()) { usethis::use_build_ignore(c( - rproj_file, ".Rhistory", ".RData", ".Rproj.user" , ".here" + rproj_file, + ".Rhistory", + ".RData", + ".Rproj.user" , + ".here" )) } From 0409626a5552d72fad33bad85e5d7b34bc51c24c Mon Sep 17 00:00:00 2001 From: hsonne Date: Thu, 9 Nov 2023 18:17:42 +0100 Subject: [PATCH 2/3] Extract get_markdown_for_index_or_readme() to be used by both use_index_md() and use_readme_md(), respectively. --- R/get_markdown_for_index_or_readme.R | 62 ++++++++++++++++++++++++++++ R/use_index_md.R | 26 +++++------- R/use_readme_md.R | 41 ++++-------------- 3 files changed, 81 insertions(+), 48 deletions(-) create mode 100644 R/get_markdown_for_index_or_readme.R diff --git a/R/get_markdown_for_index_or_readme.R b/R/get_markdown_for_index_or_readme.R new file mode 100644 index 0000000..5709d1c --- /dev/null +++ b/R/get_markdown_for_index_or_readme.R @@ -0,0 +1,62 @@ +# get_markdown_for_index_or_readme --------------------------------------------- + +#' @importFrom kwb.utils selectElements +get_markdown_for_index_or_readme <- function( + is_readme, + user = "KWB-R", + domain = "github", + stage = "experimental" +) +{ + pkg <- read_description() + + name <- kwb.utils::selectElements(pkg, "name") + + doc_lines <- if (is_readme) { + markdown_documentation_links(user, domain, name = name) + } + + title_lines <- if (is_readme) { + c("", sprintf("# %s", pkg$name)) + } + + c( + use_badge_ghactions(name, user), + use_badge_codecov(name, user, domain), + use_badge_lifecycle(stage), + use_badge_cran(name), + use_badge_runiverse(name), + title_lines, + "", + pkg$desc, + "", + use_installation(name, user, domain), + doc_lines + ) +} + +# markdown_documentation_links ------------------------------------------------- +markdown_documentation_links <- function(user, domain, name) +{ + url_release <- sprintf( + "https://%s.%s.io/%s", + tolower(user), + tolower(domain), + tolower(name) + ) + + c( + "", + "## Documentation", + "", + paste("Release:", markdown_link(url_release)), + "", + paste("Development:", markdown_link(paste0(url_release, "/dev"))) + ) +} + +# markdown_link ---------------------------------------------------------------- +markdown_link <- function(x) +{ + sprintf("[%s](%s)", x, x) +} diff --git a/R/use_index_md.R b/R/use_index_md.R index ab50a5a..7c24904 100644 --- a/R/use_index_md.R +++ b/R/use_index_md.R @@ -13,26 +13,20 @@ #' @importFrom desc desc use_index_md <- function( - user = "KWB-R", domain = "github", stage = "experimental" + user = "KWB-R", + domain = "github", + stage = "experimental" ) { - pkg <- read_description() - - index_md <- c( - use_badge_ghactions(pkg$name, user), - use_badge_codecov(pkg$name, user, domain ), - use_badge_lifecycle(stage), - use_badge_cran(pkg$name), - use_badge_runiverse(pkg$name), - "", - pkg$desc, - "", - use_installation(pkg$name, user, domain) + content <- get_markdown_for_index_or_readme( + is_readme = FALSE, + user = user, + domain = domain, + stage = stage ) - writeLines(index_md, "index.md") - + writeLines(content, "index.md") write_to_rbuildignore(ignore_pattern = "^index\\.md$") - index_md + content } diff --git a/R/use_readme_md.R b/R/use_readme_md.R index d3d4f15..588c466 100644 --- a/R/use_readme_md.R +++ b/R/use_readme_md.R @@ -13,41 +13,18 @@ #' @importFrom desc desc use_readme_md <- function( - user = "KWB-R", - domain = "github", - stage = "experimental" + user = "KWB-R", + domain = "github", + stage = "experimental" ) { - pkg <- read_description() - - docu_release <- sprintf( - "https://%s.%s.io/%s", - tolower(user), tolower(domain), tolower(pkg$name) + content <- get_markdown_for_index_or_readme( + is_readme = TRUE, + user = user, + domain = domain, + stage = stage ) - docu_dev <- sprintf("%s/dev", docu_release) - - readme_md <- c( - use_badge_ghactions(pkg$name, user), - use_badge_codecov(pkg$name, user, domain ), - use_badge_lifecycle(stage), - use_badge_cran(pkg$name), - use_badge_runiverse(pkg$name), - "", - sprintf("# %s", pkg$name), - "", - pkg$desc, - "", - use_installation(pkg$name, user, domain), - "", - "## Documentation", - "", - sprintf("Release: [%s](%s)", docu_release, docu_release), - "", - sprintf("Development: [%s](%s)", docu_dev, docu_dev) - ) - - writeLines(readme_md, "README.md") - + writeLines(content, "README.md") write_to_rbuildignore(ignore_pattern = "^README\\.md$") } From 0f6e91f36bc296bbba1ce1160e12a45f5e0528bd Mon Sep 17 00:00:00 2001 From: hsonne Date: Sun, 5 May 2024 09:37:52 +0200 Subject: [PATCH 3/3] Remove "rematch2" dependency (not used) --- DESCRIPTION | 3 +-- NAMESPACE | 1 - R/deploy_site_github_with_extra_files.R | 1 - 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index aa5ed1f..ae05000 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -33,7 +33,6 @@ Imports: openssl, pkgdown, processx, - rematch2, sessioninfo, stringr, usethis, @@ -53,4 +52,4 @@ Remotes: ByteCompile: true Encoding: UTF-8 LazyData: true -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 diff --git a/NAMESPACE b/NAMESPACE index 00d995d..8b325a9 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -62,7 +62,6 @@ importFrom(magrittr,"%>%") importFrom(openssl,base64_decode) importFrom(pkgdown,build_site) importFrom(processx,run) -importFrom(rematch2,re_match) importFrom(sessioninfo,package_info) importFrom(stringr,str_detect) importFrom(stringr,str_remove) diff --git a/R/deploy_site_github_with_extra_files.R b/R/deploy_site_github_with_extra_files.R index a5c3c5b..2252225 100644 --- a/R/deploy_site_github_with_extra_files.R +++ b/R/deploy_site_github_with_extra_files.R @@ -127,7 +127,6 @@ github_push <- function(dir, commit_message) { #' folder to "gh-pages" #' @export #' @importFrom fs dir_create file_temp dir_delete file_chmod -#' @importFrom rematch2 re_match #' @importFrom pkgdown build_site #' @importFrom callr rcmd #' @importFrom openssl base64_decode