Using Inst/Extdata with Vignette During Package Checking R 2.14.0

Using inst/extdata with vignette during package checking R 2.14.0

Have you tried using system.file instead of hardcoded relative paths?

EC1 <- dot2HPD(file = system.file("inst", "extdata", "E_coli", "ecoli.dot", package = "your_package+name"))
node.inst <- system.file("inst", "extdata", "E_coli", "NodeInst.csv", package = "your_package_name")

When should data go in /data, and when should it go in /inst/extdata?

The data directory supplies data for the data() function and is expected to follow certain customs in terms of file formats and extensions.

The inst/extdata directory becomes extdata/ when installed and is more of a wild west and you can do whatever you want and it is expected that you write your own accessors.

It may be useful to look at empirics. On my machine, among around 240-some installed packages, a full 77 (or not quite a third) have data/, but only 4 (including one of mine) have extdata..

How to add arbitrary content to R package using vignette?

I am pretty sure you can't do that, and it doesn't really make sense to try. Vignettes are supposed to be runnable by users to duplicate the results you got, or to make small changes to see how they work out. Users shouldn't expect that to change the contents of the package.

If you want your vignette to produce files for the user, they should by default be in the temporary directory, so they won't make permanent changes to the user's file system.

I think the approach in your final paragraph is the only way that will work. You run some Makefile before building the package, and perhaps it runs the vignette to install files into inst somewhere. One way to do this would be for your vignette to look at environment variables to find the destination where it puts its file. Your Makefile can set the env var before it processes the vignette. But if a user (or the R CMD build system) runs your vignette without that env var, the files won't be produced, or will be deleted at the end of the run.

Vignette can't find data files during devtools::check

To use a file in the vignette, you can add the file to the vignette folder.

An example of this is in the package tidyr at https://github.com/hadley/tidyr/blob/master/vignettes/tidy-data.Rmd

Try putting your csv file directly to the vignette folder

How to include inst/REFERENCES.bib in vignette

It appears the solution is to omit "inst" in the system.file call. Thanks to a comment from @Martin Morgan here. The working YAML header now reads

bibliography: '`r system.file("REFERENCES.bib", package="mypackage")`'

and the build succeeded on all systems with GitHub Actions as well as on my local machine.

Example input data with example output using relative pathway in vignette of R package?

The standard way to refer to a file in a package is:

# gives root package directory
system.file(package="myPackage")

# specific file
system.file("extdata/InputFiles/exampleData.csv", package="myPackage")

# best is to use cross-platform way to write a file path:
system.file("extdata", "InputFiles", "exampleData.csv", package="myPackage")

When developing with devtools, the inst subdirectory is ignored, so you never need to worry about absolute paths. This should work in a vignette. Note that a vignette, I think, only ever uses the installed version of a package, not the one you may have loaded in your development environment (specifically, devtools::load_all() does not change the code which is used to build the vignette, you must install() it first).

Finally, using data() is a bit old fashioned. Hadley and others recommend using lazy data, so the data appears in the namespace automatically. Try the following in your DESCRIPTION.

LazyData: true
LazyDataCompression: xz

How to add external data file into developing R package?

You should manually create inst/extdata/file.csv in the base directory for your project (where DESCRIPTION is). You can put all the files you want to access in that directory.

Then to get the files in function examples or your vignette:

files <- lapply(list.files(system.file('extdata', package = 'my_package'), full.names = TRUE), read.csv)

system.file() returns the path to the extdata folder, then list.files() will create a vector of all the files in extdata. Finally, running lapply() with read.csv() should read the contents of all the files into a single list for you.

Writing an R package vignette that reads in an example file?

You can use system.file('doc', 'example', package = 'mypackage') to refer to that directory, because R will install the package before building vignettes, as you can see when you run R CMD build mypackage.



Related Topics



Leave a reply



Submit