0

I'm building my first R package and sorting through the differences between the ext-data, data, and raw-data folders (and Hadley dev methods).

I have a script in raw-data that generates a file that is used to test data loading and parsing.

In that script, should I use: library('gdata'), or should I include gdata (or another package) in the DESCRIPTION for the package?

I know Hadley advises not including packages with library, but I wasn't sure if that only applied to the scripts bundled into the final package, or if it also applied to the raw-data folder.

Union find
  • 7,759
  • 13
  • 60
  • 111
  • 1
    I think the official rule of thumb for these scenarios is to place `gdata` in the suggests (of the description) and surround any instance where you need the package with `if(require(gdata)){ }`. This will allow you to keep your loaded namespace relatively free and no requiring unnecessary R package for building and install the package. But will also not cause problems in examples if the package isn't present in someone else's install. I may be wrong though. What is wrong with placing the given data in data/ as a `.rda` format? – TJGorrie Mar 19 '18 at 17:02
  • Thanks, TJ. I need it to stay in raw format. The package is a file parser. The script builds example data files. @TJGorrie – Union find Mar 19 '18 at 17:03
  • 1
    I see. Are you intending this script to be used in the vignettes or examples of the package? My thought process is that if your R package is a file parser, you technically do not need a script to parse files for examples and the vignette as you could just use your own tools for that. Again you can provide optional and controlled analysis using if(require(gdata)) if packages are necessary for examples but you will need to place said packages into imports/depends for the vignette. – TJGorrie Mar 19 '18 at 17:13
  • I did intend it to be used in the vignettes and tests, yes. When you say, use your own tools, what do you mean? The script I'm using builds example files, so it's not being used for parsing. I'm putting it in raw-data to build the test/vignette data files used for parsing by the files in /R/ @TJGorrie – Union find Mar 19 '18 at 17:18
  • 1
    Own tools as in the functions you are providing in your package :). If you are using the script to build example files just put the outputs into ext-data and leave the script out of the R package entirely? Or you could incorporate the R script as another function in your package (doesn't need to be exported) that will generate the example files (just remember to include `unlink` at the end of every example). – TJGorrie Mar 19 '18 at 17:24
  • That's great, thanks. Feel free to submit an answer and I can accept. – Union find Mar 19 '18 at 17:28

0 Answers0