Package: don't include folder from /inst when creating a package

Hi guys.

I am looking for a way how to tell R to not include specific folder from inside /inst when creating a package. There's bunch of .png tiles inside the folder, which slows down package creation considerably.

I am using environmental variables to tell R (packaged shiny app) to use either offline or online mode. In online mode no tiles are needed (OSM from api are used by default) which is actually better for package testing.

In the same vein, I would like to use some if/else to check on environmental variables when creating a package. If the variable says "offline", it would include the folder when creating the package, if "online" it would skip it.


I think .Rbuildignore is what you're looking for here! Now as for the if/else logic, I think you'll probably need to build your own Makefile or shell script or something to handle that control logic (which can then change the .Rbuildignore, concatenate piecemeal .Rbuildignores into what you use, etc). I.e. you might have .Rbuildignore.offline and and concatenate together or write over .Rbuildignore with one of them.

That said, I think there may be better patterns for this than the pattern you are taking (building the package two different ways). Maybe have a function that retrieves the images or something? Perhaps others will have thoughts :slight_smile:


I'll try it with Rbuildignore, thanks Cole. Other options are cumbersome. Essentially, you need to either accept that R takes 10 more minutes to package the app + 5 more for next docker step or make changes in code & move files when trying out different setups. Also, this settings may change after deployment making it a candidate for an env variable. You just restart a docker container with your changes in env variables instead of recreating the whole package, docker image and whatnot.

1 Like

Hi. I've added a function that checks on env variables and writes into .Rbuildignore like this, but it does not exclude the folder when building the package (the package stays the same size):

Also tried to leave out the inst but it does not work either:

The tiles are inside folder inst/mapTiles/OSM

I believe you should be using relative paths from the root of the package for .Rbuildignore. Probably something more like ^inst/MapTiles$ or ^inst/MapTiles/OSM$. Absolute paths from the home directory are definitely not what you want :slight_smile:


I've used here::here() to create the paths. It looks like it works with your changes. Thanks!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.