diff --git a/DESCRIPTION b/DESCRIPTION index 70b9d476..294bf198 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: rdev Title: R Development Tools -Version: 1.8.5 +Version: 1.8.6 Authors@R: person("John", "Benninghoff", , "jbenninghoff@mac.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-6230-4742")) @@ -11,6 +11,7 @@ URL: https://jabenninghoff.github.io/rdev/, https://github.com/jabenninghoff/rdev BugReports: https://github.com/jabenninghoff/rdev/issues Imports: + checkmate, cli, curl, desc, diff --git a/NEWS.md b/NEWS.md index 36bdd538..cebdce1c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# rdev 1.8.6 + +* Check function arguments with [checkmate](https://mllg.github.io/checkmate/index.html) + # rdev 1.8.5 * Changed `use_analysis_package()` to store `_freeze` directory in git per Quarto [guide](https://quarto.org/docs/projects/code-execution.html#using-freeze) diff --git a/R/build.R b/R/build.R index af10fc4f..ec65414c 100644 --- a/R/build.R +++ b/R/build.R @@ -59,6 +59,7 @@ unfreeze <- function() { #' #' @export build_quarto_site <- function(input = NULL, as_job = FALSE, unfreeze = FALSE, ...) { + checkmate::assert_flag(unfreeze) if (!fs::file_exists("README.Rmd")) { stop("README.Rmd does not exist") } diff --git a/R/ci.R b/R/ci.R index f7fa10f7..78c46908 100644 --- a/R/ci.R +++ b/R/ci.R @@ -12,6 +12,8 @@ #' } #' @export check_renv <- function(update = rlang::is_interactive()) { + checkmate::assert_flag(update) + writeLines("renv::status(dev = TRUE)") renv::status(dev = TRUE) @@ -117,6 +119,17 @@ ci <- function(renv = TRUE, # nolint: cyclocomp_linter. extra = TRUE, urls = TRUE, rcmdcheck = TRUE) { + checkmate::assert_flag(renv) + checkmate::assert_flag(missing) + checkmate::assert_flag(pkgdown) + checkmate::assert_flag(styler, null.ok = TRUE) + checkmate::assert_flag(lintr) + checkmate::assert_flag(document) + checkmate::assert_flag(normalize) + checkmate::assert_flag(extra) + checkmate::assert_flag(urls) + checkmate::assert_flag(rcmdcheck) + if (renv) { writeLines("renv::status(dev = TRUE)") status <- renv::status(dev = TRUE) diff --git a/R/helpers.R b/R/helpers.R index b03466c4..9bb1b8cd 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -26,9 +26,9 @@ #' } #' @export local_temppkg <- function(dir = fs::file_temp(), type = "usethis", env = parent.frame()) { - if (!(type %in% c("usethis", "rdev", "analysis", "quarto"))) { - stop("unrecognized package type, '", type, "'") - } + checkmate::assert_string(dir) + checkmate::assert_choice(type, c("usethis", "rdev", "analysis", "quarto")) + checkmate::assert_environment(env) # capture the current project - use try() since proj_get() will error within rcmdcheck() old_project <- NULL diff --git a/R/release.R b/R/release.R index a320721c..adfe2cf1 100644 --- a/R/release.R +++ b/R/release.R @@ -20,6 +20,10 @@ #' #' @export new_branch <- function(name, bump_ver = TRUE, current = FALSE) { + checkmate::assert_string(name) + checkmate::assert_flag(bump_ver) + checkmate::assert_flag(current) + if (gert::git_branch_exists(name, local = TRUE)) { stop("local branch exists") } @@ -66,6 +70,7 @@ get_release <- function(pkg = ".", filename = "NEWS.md") { if (pkg != ".") { stop('currently only get_release(pkg = ".") is supported') } + checkmate::assert_string(filename) pkg_obj <- devtools::as.package(pkg) header_regex <- paste0( @@ -134,6 +139,8 @@ stage_release <- function(pkg = ".", filename = "NEWS.md", host = getOption("rde if (pkg != ".") { stop('currently only stage_release(pkg = ".") is supported') } + checkmate::assert_string(filename) + checkmate::assert_string(host, null.ok = TRUE) rel <- get_release(pkg = pkg, filename = filename) @@ -236,6 +243,8 @@ merge_release <- function(pkg = ".", filename = "NEWS.md", host = getOption("rde if (pkg != ".") { stop('currently only merge_release(pkg = ".") is supported') } + checkmate::assert_string(filename) + checkmate::assert_string(host, null.ok = TRUE) rel <- get_release(pkg = pkg, filename = filename) pr_title <- paste0(rel$package, " ", rel$version) diff --git a/R/setup.R b/R/setup.R index eee801f2..5710124c 100644 --- a/R/setup.R +++ b/R/setup.R @@ -166,6 +166,8 @@ get_github_repo <- function() { #' @keywords internal #' @noRd fix_gitignore <- function(path = ".") { + checkmate::assert_string(path) + giti_path <- fs::path(path, ".gitignore") gitignore <- readLines(giti_path) gitignore <- gitignore[!grepl("^\\.Rproj\\.user$", gitignore)] @@ -203,6 +205,11 @@ fix_gitignore <- function(path = ".") { #' @export create_github_repo <- function(repo_name, repo_desc = "", org = NULL, host = getOption("rdev.host")) { + checkmate::assert_string(repo_name) + checkmate::assert_string(repo_desc) + checkmate::assert_string(org, null.ok = TRUE) + checkmate::assert_string(host, null.ok = TRUE) + conspicuous_place <- "usethis" %:::% "conspicuous_place" user_path_prep <- "usethis" %:::% "user_path_prep" @@ -343,6 +350,8 @@ get_server_url <- function() { #' #' @export use_rdev_package <- function(quiet = TRUE) { + checkmate::assert_flag(quiet) + rlang::local_interactive(value = !quiet) # add templates @@ -475,6 +484,8 @@ use_analysis_package <- function(use_quarto = TRUE, prompt = FALSE) { # workaround for lintr, R CMD check create <- gitignore <- rbuildignore <- NULL + checkmate::assert_flag(use_quarto) + analysis_layout <- tibble::tribble( ~pattern, ~create, ~gitignore, ~rbuildignore, "analysis", TRUE, FALSE, FALSE, diff --git a/R/to_document.R b/R/to_document.R index c44a38d2..f4fddbb1 100644 --- a/R/to_document.R +++ b/R/to_document.R @@ -17,6 +17,10 @@ #' } #' @export to_document <- function(file_path, new_path, overwrite = FALSE) { + checkmate::assert_string(file_path) + checkmate::assert_string(new_path) + checkmate::assert_flag(overwrite) + if (!(fs::path_ext(file_path) %in% c("Rmd", "rmd"))) { stop("'", file_path, "' is not an R Markdown (*.Rmd) file") } @@ -72,6 +76,8 @@ to_document <- function(file_path, new_path, overwrite = FALSE) { #' @return Named list containing analysis notebook title, URL, date, and description #' @export rmd_metadata <- function(file_path) { + checkmate::assert_string(file_path) + if (!(fs::path_ext(file_path) %in% c("Rmd", "rmd"))) { stop("'", file_path, "' is not an R Markdown (*.Rmd) file") } diff --git a/R/urlchecker.R b/R/urlchecker.R index 215a5f8f..1f3410b5 100644 --- a/R/urlchecker.R +++ b/R/urlchecker.R @@ -17,12 +17,12 @@ url_check <- urlchecker::url_check # cli is not recorded in Imports. This function is a workaround to ensure use of cli is also # detected by renv. url_update_renv_workaround <- function(...) { - cli::cli_alert_success(...) + cli::cli_alert_success(...) # nocov } # NOTE: use of curl::new_pool() is considered a dependency by renv but not by R CMD check. curl_new_pool_renv_workaround <- function(...) { - curl::new_pool(...) + curl::new_pool(...) # nocov } #' @rdname urlchecker-reexports diff --git a/R/utils.R b/R/utils.R index c0b749ab..c02749f4 100644 --- a/R/utils.R +++ b/R/utils.R @@ -20,6 +20,8 @@ #' } #' @export sort_file <- function(filename) { + checkmate::assert_string(filename) + if (!fs::file_exists(filename)) stop("cannot sort file, '", filename, "': no such file") writeLines(sort(readLines(filename)), filename) } @@ -47,6 +49,11 @@ sort_rbuildignore <- function() { #' @export spell_check_notebooks <- function(path = "analysis", glob = "*.Rmd", use_wordlist = TRUE, lang = NULL) { + checkmate::assert_string(path) + checkmate::assert_string(glob) + checkmate::assert_flag(use_wordlist) + checkmate::assert_string(lang, null.ok = TRUE) + if (is.null(lang)) { if (!fs::file_exists("DESCRIPTION")) { stop("DESCRIPTION not found") @@ -77,6 +84,7 @@ spell_check_notebooks <- function(path = "analysis", glob = "*.Rmd", use_wordlis #' @export update_wordlist_notebooks <- function(pkg = ".", vignettes = TRUE, path = "analysis", glob = "*.Rmd", confirm = TRUE) { + # nocov start as_package <- "spelling" %:::% "as_package" get_wordfile <- "spelling" %:::% "get_wordfile" get_wordlist <- spelling::get_wordlist @@ -94,6 +102,7 @@ update_wordlist_notebooks <- function(pkg = ".", vignettes = TRUE, path = "analy )), method = "radix" ) + # end change if (isTRUE(all.equal(old_words, new_words))) { cat(sprintf("No changes required to %s\n", wordfile)) } else { @@ -125,14 +134,14 @@ update_wordlist_notebooks <- function(pkg = ".", vignettes = TRUE, path = "analy "Added %d and removed %d words in %s\n", length(words_added), length(words_removed), wordfile )) } + # nocov end } deps_check <- function(type, exclude_base = TRUE) { - base_packages <- rownames(utils::installed.packages(priority = "base")) + checkmate::assert_choice(type, c("missing", "extra")) + checkmate::assert_flag(exclude_base) - if (!(type %in% c("missing", "extra"))) { - stop("invalid type '", type, "'") - } + base_packages <- rownames(utils::installed.packages(priority = "base")) renv_deps <- renv::dependencies() renv_deps <- renv_deps[!endsWith(renv_deps$Source, "/DESCRIPTION"), ] renv_deps <- renv_deps[!renv_deps$Package == pkgload::pkg_name("."), ] @@ -176,6 +185,8 @@ deps_check <- function(type, exclude_base = TRUE) { #' @export #' @rdname deps_check missing_deps <- function(exclude_base = TRUE) { + checkmate::assert_flag(exclude_base) + deps_check("missing", exclude_base) } diff --git a/README.md b/README.md index 6c17d223..d4695672 100644 --- a/README.md +++ b/README.md @@ -224,20 +224,20 @@ ci() #> * creating vignettes ... OK #> * checking for LF line-endings in source and make files and shell scripts #> * checking for empty or unneeded directories -#> * building ‘rdev_1.8.5.tar.gz’ +#> * building ‘rdev_1.8.6.tar.gz’ #> #> ── R CMD check ───────────────────────────────────────────────────────────────── -#> * using log directory ‘/private/var/folders/vn/cw5f9gws42v9m8mdsds_zbl00000gp/T/RtmpM8E6ri/filea8035355982a/rdev.Rcheck’ +#> * using log directory ‘/private/var/folders/vn/cw5f9gws42v9m8mdsds_zbl00000gp/T/RtmpC5kZVh/file180267d97952d/rdev.Rcheck’ #> * using R version 4.3.2 (2023-10-31) -#> * using platform: x86_64-apple-darwin20 (64-bit) +#> * using platform: aarch64-apple-darwin20 (64-bit) #> * R was compiled by #> Apple clang version 14.0.0 (clang-1400.0.29.202) #> GNU Fortran (GCC) 12.2.0 -#> * running under: macOS Monterey 12.7.1 +#> * running under: macOS Ventura 13.6.2 #> * using session charset: UTF-8 #> * using option ‘--no-manual’ #> * checking for file ‘rdev/DESCRIPTION’ ... OK -#> * this is package ‘rdev’ version ‘1.8.5’ +#> * this is package ‘rdev’ version ‘1.8.6’ #> * package encoding: UTF-8 #> * checking package namespace information ... OK #> * checking package dependencies ... OK @@ -295,9 +295,10 @@ ci() #> NONE #> * checking re-building of vignette outputs ... OK #> * DONE +#> #> Status: OK -#> ── R CMD check results ───────────────────────────────────────── rdev 1.8.5 ──── -#> Duration: 1m 1.2s +#> ── R CMD check results ───────────────────────────────────────── rdev 1.8.6 ──── +#> Duration: 31s #> #> 0 errors ✔ | 0 warnings ✔ | 0 notes ✔ ``` diff --git a/TODO.md b/TODO.md index d5837108..0523bbfc 100644 --- a/TODO.md +++ b/TODO.md @@ -5,6 +5,7 @@ - [x] Add README.Rmd - [x] Update `DESCRIPTION` and use description data in `README.Rmd` - [x] Add ORCID +- [ ] Update my ORCID details ## Package @@ -49,6 +50,9 @@ - [x] ~~Remove `pkgdown/extra.css` if is accepted~~ - [ ] Remove `preset: bootstrap` if is accepted - [ ] Replace `dev = TRUE` logic if is accepted +- [ ] Consider using RStudio [Extensions](https://rstudio.github.io/rstudio-extensions/index.html): + - [ ] Use Project [Templates](https://rstudio.github.io/rstudio-extensions/rstudio_project_templates.html) like [vertical](https://www.crumplab.com/vertical/) ? + - [ ] Add CSS to R Markdown [Template](https://rstudio.github.io/rstudio-extensions/rmarkdown_templates.html) instead of `assets/extra.css` ? - [ ] Update errors and messages after reading Advanced R [Conditions](https://adv-r.hadley.nz/conditions.html) and re-reading the Tidyverse [Style Guide](https://style.tidyverse.org/index.html) - [ ] Establish default [knitr options](https://yihui.org/knitr/options/), including `knitr::opts_chunk$set(fig.align = "center"")`, add to analysis template, also review [settings](https://github.com/hadley/adv-r/blob/master/common.R) for *Advanced R* - [ ] Reduce the number of Imports, per R CMD check: diff --git a/docs/404.html b/docs/404.html index e1b37827..9d7169e7 100644 --- a/docs/404.html +++ b/docs/404.html @@ -25,7 +25,7 @@ rdev - 1.8.5 + 1.8.6