inst and extdata folders in R Packaging
You were both very close and essentially had this. A formal reference from 'Writing R Extensions' is:
1.1.3 Package subdirectories
The contents of the
instsubdirectory will be copied recursively
to the installation directory. Subdirectories of
interfere with those used by R (currently,
Meta, and earlier versions
R-ex). The copying of the
is built so its
Makefilecan create files to be installed. Prior to
R 2.12.2, the files were installed on POSIX platforms with the permissions in the package sources, so care should be taken to ensure
these are not too restrictive:
R CMD buildwill make suitable
adjustments. To exclude files from being installed, one can specify a
list of exclude patterns in file
.Rinstignorein the top-level
source directory. These patterns should be Perl-like regular
expressions (see the help for
regexpin R for the precise details),
one per line, to be matched(10) against the file and directory paths,
doc/.*[.]png$will exclude all PNG files in
the (lower-case) extension.
Documenting external data in R package for the inst/extdata folder?
Here is the reproducible (on linux) example of solution I provided in comments.
Code below will create minimal package
- defining dummy
ext/data/data1.csvcsv data file
man/data1.RdR documentation file
Then it will build and install package.
mkdir -p my.pkg
cat > my.pkg/DESCRIPTION <<EOL
Title: My pkg
Description: Example my pkg.
mkdir -p my.pkg/inst/extdata
cat > my.pkg/inst/extdata/data1.sv <<EOL
cat > my.pkg/man/data1.Rd <<EOL
desc of data.
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
R: Meaning of extdata ?
This is a convention, not a formally defined term. (However, it's a convention defined by the package authors and coded in the package structure; it's not something you can change unless you mess around with the package structure yourself.) "extdata" is presumably short for "external data".
However, this doesn't mean that you need to use "extdata" when you are structuring your own code; you only need it when finding the files that are included by the package.
cron_rscript("~/my_cron_jobs/foo.R") should work fine (provided you actually have something there, and provided that the
~ == home directory shortcut works across OS, which I think it does).
system.file() takes a
package argument, but otherwise strings its arguments together into a file path; i.e.
system.file(package = "cronR", "extdata", "helloworld.R") means
- look in the system folder that R has set up for the
cronRpackage (in my case that is
/usr/local/lib/R/site-library/cronR, but the precise location will vary by OS and configuration)
- within that folder look in the
- within that folder look for
So this command will refer in my case to
Since "/" works as a path separator (at least when used from within R) for all current operating systems, you would get the same results from
When should data go in /data, and when should it go in /inst/extdata?
data directory supplies data for the
data() function and is expected to follow certain customs in terms of file formats and extensions.
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
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")
How to properly organise vignettes and inst folders when creating new R package
This is a bit late but, the error went as soon as I stopped saving my built vignettes within the R package.
Instead I only have the rmd file and associated plots in the
/vignette folder and have an
/inst folder which does not contain any vignette associated material.
Avoid String Printed to Console Getting Truncated (In Rstudio)
Calculate Cumsum() While Ignoring Na Values
Remove Null Elements from List of Lists
Equivalent to Unix "Less" Command Within R Console
Pass Function Arguments to Both Dplyr and Ggplot
Embedded Nul in String' Error When Importing CSV with Fread
Using Cbind on an Arbitrarily Long List of Objects
Delete "" from CSV Values and Change Column Names When Writing to a CSV
Plot One Numeric Variable Against N Numeric Variables in N Plots
Spread with Duplicate Identifiers (Using Tidyverse and %>%)
Replace Values in a Vector Based on Another Vector
R Function with No Return Value
Replace Na Values by Row Means
Group Integer Vector into Consecutive Runs
Sorting Each Row of a Data Frame
Processing Negative Number in "Accounting" Format
R Function Not Returning Values
How to Create Two Independent Drill Down Plot Using Highcharter