knitr::opts_chunk$set(collapse = FALSE)

Create a fake package for examples

# 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()
}
", 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)

Avoid missing return value for exported functions

CRAN does not like when exported functions do not have returned value. Using find_missing_tags(), you can detect exported functions with missing or empty @return tag

tags <- find_missing_tags(pkg_path)
tags
tags$functions

Deal with check outputs

# Get globals
globals <- get_no_visible(pkg_path, quiet = TRUE)
globals

# Print globals to copy-paste
print_globals(globals)
# Store in package using usethis::use_r("globals")
# Run but keep eval=FALSE to avoid infinite loop
# Execute in the console directly
fusen::inflate(flat_file = "dev/flat_deal-with-check-outputs.Rmd", vignette_name = "Deal with check outputs", check = FALSE, document = TRUE, open_vignette = FALSE)

# Pre-compilation of the vignette over itself to avoid too long calculation during checks
knitr::knit(
  input = here::here("vignettes/deal-with-check-outputs.Rmd"),
  output = here::here("vignettes/deal-with-check-outputs.Rmd")
)

rstudioapi::navigateToFile("dev/0-dev_history.Rmd", line = 96)


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