roxygen2 icon indicating copy to clipboard operation
roxygen2 copied to clipboard

Add @usage data('diamonds') to vignettes/rd-other.Rmd

Open zettlchen opened this issue 10 months ago • 2 comments

Dear developers, thank you for your great work!

When documenting a dataset, I followed the template you provide in vignettes/rd-other.Rmd.

This structure caused a warning in R CMD check --as-cran:

  • checking for code/documentation mismatches ... WARNING Variables with usage in Rd file 'datadoc.Rd' but not in code: ‘docdata’

After a bit of trial and error, this warning could be removed by adding a usage section to the documentation block: #' @usage data('docdata')

I'm convinced that if you were to add a simple @usage data('diamonds') to your example on data documentation, you could help many future users avoid unnecessary CRAN check warnings.

Best, Lena

zettlchen avatar Feb 11 '25 10:02 zettlchen

(Not a dev here.) I think this is the start of some great improvements against issues I've been finding.

For instance, if I have the following in ./R/mydata.R:

#' Some Data.
#'
#' Something goes here.
#'
#' @format data.frame
#'
#' @usage data("somedata")
"somedata"

(The @usage is a recent add due to your comment above.) I have ./data/somedata.rda. In a package function, I use somedata[, .(...)] (it's really a data.table, but that's not important here). devtools::check(..) complains:

    my_func: no visible binding for global variable 'somedata'

It is not exported. There is nothing fancy about it. But having done everything (afaict) that the roxygen2 docs say to do for data, I still get warnings about it. The only remedy I've found is rather nuclear, including this in one or more of my .R files (outside of a function definition):

utils::globalVariables("somedata")

I write this here as a comment and not as a new issue since I think it's all related. If y'all (OP and/or devs) think this is best as a new issue, I'll happily open one there too. Thanks!

r2evans avatar Apr 01 '25 18:04 r2evans

Possibly related to {codetools} bug:

https://gitlab.com/luke-tierney/codetools/-/issues/8

MichaelChirico avatar Oct 14 '25 18:10 MichaelChirico