-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathREADME.Rmd
198 lines (149 loc) · 6.08 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
<!-- badges: start -->
[](https://thinkr-open.r-universe.dev)
[](https://github.com/ThinkR-open/checkhelper/actions/workflows/R-CMD-check.yaml)
[](https://app.codecov.io/gh/ThinkR-open/checkhelper/tree/main)
[](https://cran.r-project.org/package=checkhelper)
[](https://CRAN.R-project.org/package=checkhelper)
<!-- badges: end -->
# 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.