1

I'm writing a package in R and I'd like to include some sample objects in it that would be easily accessible for users to play with. The problem is they contain non-ASCII characters, and R CMD check won't allow this in .rda files in data. It will, however, allow Unicode in inst/extdata. I could just have these datasets read and wrapped in objects when the package is loaded. I tried assign and <<-, but I couldn't make either work.

Alternately, they could be loaded and saved as .rda files during the installation of the package. This would be preferable, in fact, but from what I read this seemed to be less possible.

Probably irrelevant but possibly interesting bit of history: I started the package on Debian unstable. I saved those datasets as .rda and they passed the check just fine. At one point I made a little correction, resaved them, and got a warning. I saved them again, and the warning disappeared. Then I moved to Debian stable, added some new datasets, resaved them all, and now I can't get rid of the warning in any way. When I save them from r-devel, however, I only get a note, not a warning.

Kamil S.
  • 406
  • 3
  • 10
  • 1
    Could you perhaps use a function instead? Have the function read from `extdata` and have the user load the object from the function? https://stackoverflow.com/questions/12598242/global-variables-in-packages-in-r –  Sep 17 '20 at 15:07
  • Thank you so much! When you mentioned functions, I realized I was so intent on defining the variables as global I didn't think to simply export them through roxygen. I'm ashamed to say I spent two days on this, and I could have just asked you. – Kamil S. Sep 17 '20 at 17:46

1 Answers1

0

The answer is embarrassingly simple: read the data and prepare the variables in one of the files in the R folder, and #' @export them. No need to assign or anything.

Kamil S.
  • 406
  • 3
  • 10
  • Except R 4.0 or thereabouts introduces staged install which makes it impossible to use `system.file` for this. I ended up `dput`ting all the objects, pasting them into a file in the R folder, and escaping all the Unicode characters… which Windows doesn't know how to translate to native encoding. This is ridiculous. – Kamil S. Sep 17 '20 at 20:09