0

I am trying to make an R package that contains data files.

One data file, mydata.Rd, is annotated with the following Roxygen2 code:

#' My Title
#' @docType data
#' @keywords datasets
#' @references my name
#' (\\href{https://doi.org/etc.})
#' @source \\href{https://source}
"mydata"

I get the error:

Variables with usage in documentation object 'mydata' but not in code: ‘mydata’

I've tried multiple things to fix this error. For example:

  • I have checked to make sure that the DESCRIPTION has LazyData: true
  • I removed the @usage tag that was originally in my Roxygen2 code
  • I have made sure that the .Rd file and the corresponding .R file both exist.

Advice is appreciated.

generic
  • 302
  • 1
  • 3
  • 14
  • What if you take out `#' @examples data(mydata)`? If you use lazy data you usually don't use `data()` to load the data. The variables are basically just promises that are loaded as neeed. – MrFlick Jan 05 '23 at 20:37
  • Thanks for the suggestion! I removed `#' @examples data(mydata)` but the issue persists. I'll remove it from my question to avoid confusion. – generic Jan 05 '23 at 20:45
  • Can you create a minimal reproducible example so we can run the code ourselves and verify where the error is occurring? (perhaps post example to github.) What version of roxygen2 and R are you using? – MrFlick Jan 05 '23 at 20:53
  • Good idea. I will work on that and post it to GitHub. – generic Jan 05 '23 at 21:11

1 Answers1

3

The problem is your .Rbuildignore file.

You had the line

^data/.+$

and the syntax for these entries is a perl-like regular expressions. I'm guessing you wanted to hide all files that started with a dot? But in regular expressions, a dot matches any character. So you were ignoring all your data files. You should have see this in your build log

─  checking for empty or unneeded directories
   Removed empty directory ‘hansardr/data’
   Omitted ‘LazyData’ and ‘LazyDataCompression’ from DESCRIPTION

The /data/ folder was empty because everything was ignored. You need to escape a dot with a slash in a regular expression

^data/\.+$

Then you won't get that particular error any more because your data files will actually exist when the code goes to check the variable names.

MrFlick
  • 195,160
  • 17
  • 277
  • 295