Directories in `inst/extdata` are quietly ignored

I have an in-house R-package with some example data bundled in its inst/extdata directory.

The problem is that any directory containing "gold" as part of the directory name is quietly ignored by devtools::build() and by devtools::install().

Here is a reproducible example:

# Create packge
library(devtools)
usethis::create_package("~/reprexgold")

Then, within the created R-package project:

# Create some directories
dir.create("inst/extdata/gold", recursive = TRUE)
dir.create("inst/extdata/x_gold", recursive = TRUE)
dir.create("inst/extdata/silver", recursive = TRUE)
dir.create("inst/extdata/x_silver", recursive = TRUE)

# Populate directories
writeLines("hello world", "inst/extdata/gold/test.txt")
writeLines("hello world", "inst/extdata/x_gold/test.txt")
writeLines("hello world", "inst/extdata/silver/test.txt")
writeLines("hello world", "inst/extdata/x_silver/test.txt")

# List directories
dir("inst/extdata", recursive = TRUE)
# > [1] "gold/test.txt"     "silver/test.txt"   "x_gold/test.txt"   "x_silver/test.txt"

# Build package
devtools::install()

# List content of bundled 'extdata' directory
dir(system.file("extdata", package = "reprexgold"), recursive = TRUE)
# > [1] "silver/test.txt"   "x_silver/test.txt"

The inst/extdata/*gold directories are ignored in the build process. No warning is produced.

sessionInfo()
# R version 4.4.1 (2024-06-14)
# Platform: x86_64-pc-linux-gnu
# Running under: Ubuntu 22.04.4 LTS
# 
# Matrix products: default
# BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
# LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so;  LAPACK version 3.10.0
# 
# locale:
#   [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
# [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                 
# [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
# 
# time zone: Europe/Berlin
# tzcode source: system (glibc)
# 
# attached base packages:
#   [1] stats     graphics  grDevices utils     datasets  methods   base     
# 
# other attached packages:
#   [1] devtools_2.4.5 usethis_3.0.0 
# 
# loaded via a namespace (and not attached):
#   [1] vctrs_0.6.5       cli_3.6.3         rlang_1.1.4       stringi_1.8.4     purrr_1.0.2       pkgload_1.4.0    
# [7] promises_1.3.0    shiny_1.9.1       xtable_1.8-4      glue_1.7.0        htmltools_0.5.8.1 httpuv_1.6.15    
# [13] pkgbuild_1.4.4    ellipsis_0.3.2    fastmap_1.2.0     lifecycle_1.0.4   memoise_2.0.1     stringr_1.5.1    
# [19] compiler_4.4.1    miniUI_0.1.1.1    sessioninfo_1.2.2 fs_1.6.4          htmlwidgets_1.6.4 Rcpp_1.0.13      
# [25] urlchecker_1.0.1  rstudioapi_0.16.0 later_1.3.2       digest_0.6.37     R6_2.5.1          magrittr_2.0.3   
# [31] tools_4.4.1       mime_0.12         profvis_0.3.8     remotes_2.5.0     cachem_1.1.0   

I do not understand why this is. Thoughts?

I really-really want bundled example data in "gold"-directories... :slight_smile: Any suggestions that would allow me to include this feature?

Thanks,
//Carl

This seems like an issue with R CMD build, not devtools:

❯ find reprexgold/inst/extdata
reprexgold/inst/extdata
reprexgold/inst/extdata/silver
reprexgold/inst/extdata/silver/test.txt
reprexgold/inst/extdata/x_gold
reprexgold/inst/extdata/x_gold/test.txt
reprexgold/inst/extdata/gold
reprexgold/inst/extdata/gold/test.txt
reprexgold/inst/extdata/x_silver
reprexgold/inst/extdata/x_silver/test.txt
❯ R CMD build reprexgold
* checking for file ‘reprexgold/DESCRIPTION’ ... OK
* preparing ‘reprexgold’:
* checking DESCRIPTION meta-information ... OK
* checking for LF line-endings in source and make files and shell scripts
* checking for empty or unneeded directories
Removed empty directory ‘reprexgold/R’
* building ‘reprexgold_0.0.0.9000.tar.gz’
❯ tar tzf reprexgold_0.0.0.9000.tar.gz
reprexgold/DESCRIPTION
reprexgold/NAMESPACE
reprexgold/inst/
reprexgold/inst/extdata/
reprexgold/inst/extdata/silver/
reprexgold/inst/extdata/silver/test.txt
reprexgold/inst/extdata/x_silver/
reprexgold/inst/extdata/x_silver/test.txt

Thanks for taking the time! :pray:
I've asked for access to post the issue with the Bugzilla R bug tracking system.

//Carl

1 Like

Looks like this is the offending line: r-source/src/library/tools/R/build.R at 8a12fcfd91f477c5af8f3937dc56e772fc4136a2 ¡ wch/r-source ¡ GitHub

exclude <- exclude | (isdir & grepl("([Oo]ld|\\.Rcheck)$", bases))

So it will do it if the name ends in "old" or "Old". Extending your reprex with more variations of the "old" name, the names that don't end in "old" aren't excluded. "ld" without the "o" also isn't exluded.

dir("inst/extdata", recursive = TRUE)
# [1] "blahblahmoldblah/test.txt" "fold/test.txt"             "gold/test.txt"             "goldd/test.txt"           
# [5] "ld/test.txt"               "old/test.txt"              "Old/test.txt"              "silver/test.txt"          
# [9] "x_gold/test.txt"           "x_silver/test.txt"    

# Build package
devtools::install()

# List content of bundled 'extdata' directory
dir(system.file("extdata", package = "reprexgold"), recursive = TRUE)
# [1] "blahblahmoldblah/test.txt" "goldd/test.txt"            "ld/test.txt"               "silver/test.txt"          
# [5] "x_silver/test.txt"              

Well done for finding a fun bug in R

Can you put something after "gold"? e.g. "gold-tier"

2 Likes