Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ThinkR-open/checkhelper

A package to help deal with devtools::check outputs
https://github.com/ThinkR-open/checkhelper

r r-package rstats

Last synced: 3 months ago
JSON representation

A package to help deal with devtools::check outputs

Awesome Lists containing this project

README

        

---
output: github_document
---

[![checkhelper status badge](https://thinkr-open.r-universe.dev/badges/checkhelper)](https://thinkr-open.r-universe.dev)
[![R-CMD-check](https://github.com/ThinkR-open/checkhelper/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/ThinkR-open/checkhelper/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/ThinkR-open/checkhelper/branch/main/graph/badge.svg)](https://app.codecov.io/gh/ThinkR-open/checkhelper/tree/main)
[![](https://cranlogs.r-pkg.org/badges/checkhelper)](https://cran.r-project.org/package=checkhelper)
[![CRAN status](https://www.r-pkg.org/badges/version/checkhelper)](https://CRAN.R-project.org/package=checkhelper)


# 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/

```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

## Installation

Install from CRAN

```r
install.packages("checkhelper")
```

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

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

Or from GitHub:
``` r
remotes::install_github("thinkr-open/checkhelper")
```

## Examples

- Check your current package under development and get all the globals missing: `no visible global variable` and `no visible global function`
- Detect exported functions with missing or empty `@return` / `@noRd` tags

### Directly in your package in development

- Use `checkhelper::find_missing_tags()` on your package in development to find which functions are exported but missing `@export` roxygen2 tag.
- CRAN policy asks for every exported function to have a value (named `@export` when using {roxygen2}).
- This also checks that not exported functions don't have roxygen title, or have `@noRd` in case you faced `Please add \value to .Rd files` CRAN message for documented but not exported functions.
- You can directly use `checkhelper::print_globals()` on your package instead of `devtools::check()`. This is a wrapper around `rcmdcheck::rcmdcheck()`. This will run the checks and directly list the potential "globalVariables" to add in a `globals.R` file.

```{r, eval=FALSE}
checkhelper::find_missing_tags()

checkhelper::print_globals(quiet = TRUE)
```

### Reproducible example with a fake package in tempdir

- Create a fake package with
- a function having global variables
- a function with `@export` but no `@return`
- a function with title but without `@export` and thus missing `@noRd`

```{r, eval=TRUE, results='hide'}
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 `@return` and find missing `@noRd` for not exported function with documentation

```{r}
find_missing_tags(pkg_path)
```

- Get global variables
```{r}
globals <- get_no_visible(pkg_path, quiet = TRUE)
globals
```

- Print globals to copy-paste
```{r, eval=TRUE}
print_globals(globals)
```

- Store the output of `print_globals()` in package using `usethis::use_r("globals")`.
Note that you can also transform all these variables with `.data[[variable]]`

### 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.

```{r examples-check_clean_userspace, eval=FALSE}
check_clean_userspace()
```
```{r, echo=FALSE, message=FALSE}
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.

```{r eval=FALSE}
# Check the current directory
check_as_cran()
```

## Code of Conduct

Please note that the checkhelper project is released with a [Contributor Code of Conduct](https://thinkr-open.github.io/checkhelper/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.