checkhelper status badge R-CMD-check Codecov test coverage CRAN status

checkhelper

A package to help you deal with devtools::check() outputs and helps avoids problems with CRAN submissions

Complete documentation in the {pkgdown} site: https://thinkr-open.github.io/checkhelper/

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

Installation

Install from CRAN

install.packages("checkhelper")

You can install the last version of checkhelper from r-universe with:

install.packages('checkhelper', repos = 'https://thinkr-open.r-universe.dev')

Or from GitHub:

remotes::install_github("thinkr-open/checkhelper")

Examples

Directly in your package in development

checkhelper::find_missing_tags()

checkhelper::print_globals(quiet = TRUE)

Reproducible example with a fake package in tempdir

library(checkhelper)

# Create fake package ----
pkg_path <- tempfile(pattern = "pkg.")
dir.create(pkg_path)

# Create fake package
usethis::create_package(pkg_path, open = FALSE)

# Create function no visible global variables and missing documented functions
cat("
#' Function
#' @importFrom dplyr filter
#' @export
my_fun <- function() {
data %>%
filter(col == 3) %>%
mutate(new_col = 1) %>%
ggplot() +
  aes(x, y, colour = new_col) +
  geom_point()
}

#' Function not exported but with doc
my_not_exported_doc <- function() {
  message('Not exported but with title, should have @noRd')
}
", file = file.path(pkg_path, "R", "function.R"))

attachment::att_amend_desc(path = pkg_path)

# Files of the package
fs::dir_tree(pkg_path, recurse = TRUE)
find_missing_tags(pkg_path)
globals <- get_no_visible(pkg_path, quiet = TRUE)
globals
print_globals(globals)

Experimental: Check that the user space is clean after checks

Have you faced a note on CRAN about non-standard things in the check directory ?

Check: for non-standard things in the check directory
Result: NOTE
    Found the following files/directories:
     extrapackage 

Maybe you do not understand where these files came from.
Then, you can run check_clean_userspace() in your package directory to detect every files that you created during the check.
They could be issued from examples, tests or vignettes: check_clean_userspace() will tell you.

check_clean_userspace()
pkgload::load_all()
path <- suppressWarnings(create_example_pkg())
dir.create(file.path(path, "tests", "testthat"), recursive = TRUE)
# Add a test that let file in the testthat dir
cat(
  "cat(\"#in tests\", file = \"in_test.R\")",
  file = file.path(path, "tests", "testthat", "test-in_test.R")
)

# Add an example that let file in tempdir
cat(
  "#' Function",
  "#' @return 1",
  "#' @export",
  "#' @examples",
  "#' text <- \"in_example\"",
  "#' file <- tempfile(\"in_example\")",
  "#' cat(text, file = file)",
  "in_example <- function() {",
  "1",
  "}",
  sep = "\n",
  file = file.path(path, "R", "in_example.R")
)

suppressWarnings(attachment::att_amend_desc(path = path))

check_output <- tempfile("check_output")

suppressMessages(
  all_files <- check_clean_userspace(pkg = path, check_output = check_output),
)
all_files

Experimental: Check as CRAN with CRAN global variables

Use the exploration of CRAN scripts by the RConsortium to check a package as CRAN does it with their env. variables. See https://github.com/RConsortium/r-repositories-wg/issues/17 for more details.

# Check the current directory
check_as_cran()

Code of Conduct

Please note that the checkhelper project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.



ThinkR-open/checkhelper documentation built on Jan. 26, 2024, 4:16 p.m.