51

I am interested in excluding two directories inst\docs and inst\examples while building and installing the package. I know that an easy way out is just to move docs and examples to the root directory and they won't get installed. However, I want to keep them in inst for other reasons.

I tried adding the following lines to .Rbuildignore

inst/docs
inst/examples

I use RStudio v 0.97 and devtools to build and install the package from source. However, when I do that, I still see that inst\docs and inst\examples get installed. I tried different regexes, but nothing seemed to work.

Am I doing something wrong?

Ramnath
  • 54,439
  • 16
  • 125
  • 152
  • 1
    I have the same issue. When using `install` in devtools the folders are ignored. When building and install from the command line the folders are ignored. But when using the 'Build & Reload' button in RStudio the folders get installed. Seems like an RStudio problem – Dason Nov 01 '12 at 17:56
  • 2
    You are right. I used `devtools:install` and it worked perfectly. I am going to leave this question on here in case someone else has the same issue. – Ramnath Nov 01 '12 at 18:15
  • How do I see the .Rbuildignore folder? I can't seem to find it. – NelsonGon Feb 07 '19 at 08:08
  • `.Rbuildignore` should be a text file in the package root directory; you will need to create this manually (perhaps using `usethis::use_build_ignore`) if it doesn't already exist – Martin Smith Jan 13 '22 at 08:34

5 Answers5

32

You can do

usethis::use_build_ignore(c("yourfolder1", "yourfolder2", "yourfile"))
Martin Smith
  • 3,687
  • 1
  • 24
  • 51
Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225
  • 15
    updating, two years later: `use_build_ignore()` is now part of `usethis` and the `devtools` fxn is deprecated, so now instead do `usethis::use_build_ignore(c("yourfolder1", "yourfolder2", "yourfile"))` – Frederick Solt Jul 20 '19 at 14:37
19

This appears to be an issue with RStudio. Using install from the devtools package seems to cause the folders to be ignored. Building and installing directly from the command line also seems to cause the folders to be ignored. The 'Build & Reload' button in RStudio, however, seems to not take into account the .Rbuildignore for those folders.

Dason
  • 60,663
  • 9
  • 131
  • 148
  • 4
    Posted [issue](http://support.rstudio.org/help/discussions/problems/3771-build-and-reload-package-does-not-respect-rbuildignore?unresolve=true) with RStudio – Ramnath Nov 02 '12 at 15:33
  • 6
    @Ramnath any reply to the above filed issue? The link no longer works and still experiencing RStudio ignoring `.Rbuildignore` – Daniel Krizian Oct 26 '14 at 17:31
  • 3
    @DanielKrizian I think you should file the issue with devtools or rstudio if it is not resolved as yet. – Ramnath Oct 27 '14 at 13:53
  • 4
    Same [issue](https://support.rstudio.com/hc/en-us/community/posts/200654836-Build-and-Reload-Package-does-not-respect-Rbuildignore), but updated link. – swihart Nov 30 '16 at 15:39
4

I find that I obtain the most consistent behaviour when treating each line of the .Rbuildignore file as a regular expression. In your case I would manually create a text file in the root directory of the project named .Rbuildignore with the contents

^inst/docs
^inst/examples

The expression ^inst/docs matches any file or folder that begins with (^) the string inst/docs. usethis::use_build_ignore() adds a trailing $ to each expression, which I have found can cause files within these folders not to be captured by the pattern (and thus not being ignored).

Martin Smith
  • 3,687
  • 1
  • 24
  • 51
3

An old post but it still seems to be an issue when building binary packages. The following hack seems to work though (i.e., build source package and then build binary from that source package).

f <- devtools::build("mypackage")
system(paste0("R CMD INSTALL --build ", f))
Vincent
  • 5,063
  • 3
  • 28
  • 39
3

Just to update, as of the latest versions, devtools::use_build_ignore has been moved to:

usethis::use_build_ignore(c("yourfolder1", "yourfolder2", "yourfile"))
Carrol
  • 1,225
  • 1
  • 16
  • 29