Search code examples
rr-packagerd

Documenting external data in R package for the inst/extdata folder?


I am working on a package in R, and am looking for a way to document the sources of external data stored in the inst/extdata folder. I know that data in the /data folder can be documented with roxygen as per this SO post.

The trouble seems to be that external data is not exported into the namespace of the package, and therefore tying an roxygen help document to it poses an issue. Is there a way to overcome this and to document external data similar to the method for items in the /data folder?


Solution

  • Here is the reproducible (on linux) example of solution I provided in comments.

    Code below will create minimal package

    • defining dummy DESCRIPTION file
    • example ext/data/data1.csv csv data file
    • example man/data1.Rd R documentation file

    Then it will build and install package.

    mkdir -p my.pkg
    cat > my.pkg/DESCRIPTION <<EOL
    Package: my.pkg
    Type: Package
    Title: My pkg
    Version: 1.0.0
    Description: Example my pkg.
    License: GPL-3
    EOL
    mkdir -p my.pkg/inst/extdata
    cat > my.pkg/inst/extdata/data1.sv <<EOL
    a,b,c
    1,a,2.5
    2,b,5.5
    EOL
    mkdir my.pkg/man
    cat > my.pkg/man/data1.Rd <<EOL
    \name{data1}
    \alias{data1}
    \alias{data5}
    \title{
    my data
    }
    \description{
    desc of data.
    }
    EOL
    R CMD build my.pkg
    R CMD INSTALL my.pkg_1.0.0.tar.gz
    

    Now see that manual can be found

    Rscript -e 'library(my.pkg); ?data1'
    
    Rscript -e 'library(my.pkg); ?data5'
    

    As you can see we can refer to documentation of extdata using any name defined in alias inside Rd file.