rr-packagecranroxygen2data-files

R Roxygen2 Warning: Variables with usage in documentation object but not in code


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:

Advice is appreciated.


Solution

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