Closed Bisaloo closed 5 months ago
A naive question as I'm not familiar with IP: does the step "Update year in license file" relate to all packages, or only those which have not yet had a release (GH or CRAN)? Is a license only valid until the year specified; how does this work?
@Bisaloo here is a function inspired by this issue that can be used to automate away some of the tasks listed.
It could potentially be converted to a Github workflow, and help to keep epiverse packages up to date with {packagetemplate}.
spring_clean <- function() {
# internal helper function
say <- function(x, crlf = FALSE) {
eol <- ifelse(crlf, "\n\n", "\n")
cat(paste0(x, eol))
}
# internal helper function
files_with <- function(file_list, pattern, return_logicals = TRUE) {
# index file_list with logical results of pattern search
y <- unlist( # remove list returned by lapply below
lapply(file_list, function(x) { # for each file in file_list
x <- paste(readLines(x), collapse = " ") # get file contents
grepl(pattern, x)
})
)
if (return_logicals == FALSE) {
y <- file_list[y]
}
y
}
package <- read.dcf("DESCRIPTION", "Package")
yml <- yaml::read_yaml("_pkgdown.yml")
webpage_url <- paste0("https://epiverse.github.io/", package)
api_url <- paste0("https://api.github.com/repos/epiverse-trace/", package)
# - [X] Verify that website URL is listed in `_pkgdown.yml`
result <- yml$url == webpage_url
result <- ifelse(result, "🟢", "❌")
say(paste(result, "Website URL is listed in _pkgdown.yml"))
# - [X] Verify pkgdown site is using epiversetheme
result <- yml$template$package == "epiversetheme"
result <- ifelse(result, "🟢", "❌")
say(paste(result, "pkgdown site is using epiversetheme"))
# - [ ] Add logo to `epiverse-trace/hex-stickers`
# - [X] Use svg version of logo
result <- file_test("-f", "man/figures/logo.svg")
result <- ifelse(result, "🟢", "❌")
say(paste(result, "svg version of logo used"))
say(paste(result, "Logo properly detected by pkgdown & r-universe"))
# - [ ] Verify logo is properly detected by pkgdown & r-universe
# (path and name need to be exactly
# `man/figures/logo.png` or `man/figures/logo.svg`)
# - [X] Add a pkgdown reference index
result <- !is.null(yml$reference)
result <- ifelse(result, "🟢", "❌")
say(paste(result, "Add a pkgdown reference index"))
# Use selectors (e.g., `starts_with()` or `contains()`) to select functions rather than an explicit list. This serves the double purpose of checking that functions follow a coherent naming scheme.
# - [ ] Verify intro vignette appears under 'Get started'
# - [ ] Verify vignettes are ordered correctly (if applicable)
# - [X] Verify all images include helpful alt-text
rmd_files <- list.files(pattern = "Rmd", recursive = TRUE)
with_plot <- files_with(rmd_files, "plot\\(") # covers ggplot as well
with_fig_alt <- files_with(rmd_files, "fig\\.alt")
result <- rmd_files[xor(with_fig_alt, with_plot)]
if (length(result) > 0) {
say("❌ No alt-text in the following files")
say(result)
say("[Example: ```{r, fig.alt = 'Alt text here'}]")
} else {
say("🟢 All images include helpful alt-text")
}
## Developer tools
# - [ ] Update lintr, roxygen, usethis, testthat, devtools to latest version
say("Updating lintr and devtools to the latest version")
pak::pak(c("lintr", "devtools"), dependencies = TRUE)
# - Copy from packagetemplate:
say("Getting latest updates from packagetemplate")
system("git clone https://github.com/epiverse-trace/packagetemplate")
# - [ ] [`.lintr`]
say("Copying .lintr")
system("mv -f packagetemplate/.lintr .")
# - [ ] [GitHub Actions worfklows]
say("Copying Github Actions workflows")
system("mv -f packagetemplate/.github/workflows/*.y* .github/workflows")
# - [ ] [`tools/`]
say("Copying tools/ folder")
system("rm -rf tools && mv packagetemplate/tools .")
# - [ ] [`tests/spelling.R`]
say("Copying tests/spelling.R")
system("mv -f packagetemplate/tests/spelling.R tests")
# - [ ] [`tests/testthat/helper-state.R`]
# - [ ] [`tests/testthat/setup-options.R`]
say("Copying test/testthat/*.R")
system("mv -f packagetemplate/tests/testthat/* tests/testthat/")
system("rm -rf packagetemplate")
# - [ ] Run `spelling::spell_check_package()`
say("Spell checking package")
spelling::spell_check_package()
## Misc good practice
# - [ ] Change files ending in `.r` to `.R` in `R/` and/or `tests/testthat/`"
say("Rename .r to
.R ")
system(
'for file in $(find . -name "*.r"); do mv "$file" "${file%.r}.R"; done'
)
# - [ ] Review usage of `# nolint` comments. New versions of lintr may have squashed previous bugs
nolint_files <- list.files(pattern = "R$", recursive = TRUE) |>
files_with("nolint", return_logicals = FALSE)
if (nolint_files |> length() > 0) {
say("❌ # nolint found in the following files")
say(nolint_files)
say("")
say("New versions of lintr may have squashed previous bugs")
say("Consider reviewing...")
}
# - [ ] Update year in license file
year <- api_url |>
readLines() |>
jsonlite::fromJSON() |>
(\(x) x$created_at)() |>
substr(1, 4)
readLines("LICENSE") |> # Update LICENSE
paste(collapse = "\n") |>
(\(x) gsub("YEAR:\\s*\\d{4}", paste("YEAR:", year), x))() |>
writeLines(con = "LICENSE")
say(paste("🟢 License file year updated to", year))
## Documentation
# - [X] Use roxygen2 markdown syntax (`usethis::use_roxygen_md()`)
say("Checking roxygen2 markdown syntax")
urlchecker::use_roxygen_md()
# - [ ] Add a related project section at the end of the `README`
# - [X] Check that all URLs are working, up-to-date
say("Checking URLs")
urlchecker::url_check()
# - [ ] Add package-level documentation page
say("Checking package-level documentation page")
urlchecker::use_package_doc()
# - [ ] Move package-level imports to the package-level documentation
# - [ ] Verify usage of all `@import` and `@importFrom` import functions
# - [ ] Identify potential for [reuse in documentation]
# - [X] Run `devtools::document()`
say("Generating package documentation")
devtools::document()
## `DESCRIPTION`
# - [ ] Verify if any package in `Remotes` is still necessary
# - [ ] Check that [package `Description`] is in line with the current scope
# - [ ] Make sure links to GitHub repository and issue tracker are listed
say("Checking GitHub links")
usethis::use_github_links()
# - [ ] Re-order and standardize `DESCRIPTION` with `desc::desc_normalize()`
say("Standardize DESCRIPTION")
desc::desc_normalize()
# - [ ] Submit a PR adding yourself as author to packagetemplate
## Final `R CMD check`
# - [ ] Run `devtools::check()` locally to catch `NOTE`s and `WARNING`s
say("Running devtools::check()")
devtools::check()
## GitHub
# - [ ] Check if issues are still relevant. If not, please close them,
# ideally with a link to the commit fixing them or a comment
# explaining why they no longer apply.
# - [ ] Check/close completed discussions you started
}
Please copy the following checklist in an issue in the package you're cleaning: