Search code examples
rpackagecran

How to refer to /data files in R package


I have submitted a R package to CRAN. I need to include example .csv files which I included under the /data directory.

To get the R CMD check to pass, I have to have the examples in the .Rd file to refer to data .csv files as below

 pkg-function(system.file("data", <csv file>, package = pkg-name),par1) -- (1)

Using this format passes the R CMD check and also works after the package is installed rather than actual path names.

But I want the user to be able refer to the .csv files in a simple way as follows

pkg-function(path-to-file, par1) -- (2)

Since the examples in the .Rd file will be in form (1) it will confuse the user.

Is there a clean way to call the package functions in the examples (.Rd) as format (2)


Solution

  • I would recommend a change in expectations in your case. Instead of trying to find a way to make a clear and obvious example in as little code as possible, perhaps you can write a little more code with comments to illustrate what you are doing.

    For example:

    #* retrieve the file path of a data file installed with
    #* [your package's name] 
    #* see '?system.file' for details.
    Path <- system.file (...)
    
    #* execute function
    pkg-function (Path, par1)