16

I have a package with a README.Rmd that I pass to rmarkdown::render() producing README.md and a directory README_files, which contains images in README.md. This looks like the tree below.

README_files is not a standard package directory, so if it isn't in .Rbuildignore, checking the package with R CMD check shows a note:

* checking top-level files ... NOTE Non-standard file/directory found at top level: README_files

But including the directory in .Rbuildignore leads to a warning, if and only if checking the package --as-cran. IIUC Pandoc tries to generate HTML from README.md, but the images are unavailable, in the ignored README_files directory.

Conversion of ‘README.md’ failed:
pandoc: Could not fetch README_files/unnamed-chunk-14-1.png
README_files/unnamed-chunk-14-1.png: openBinaryFile: does not exist (No such file or directory)

Is there any way to get a clean check --as-cran here?

├── README_files │   └── figure-markdown_github │   ├── unnamed-chunk-14-1.png │   ├── unnamed-chunk-15-1.png │   ├── unnamed-chunk-16-1.png │   ├── unnamed-chunk-26-1.png │   └── unnamed-chunk-27-1.png ├── README.md ├── README.Rmd

effel
  • 1,421
  • 1
  • 9
  • 17
  • It seems the standard is to just put those images in the top directory instead, see e.g. [`ggplot2`](https://github.com/tidyverse/ggplot2) or [`ggraph`](https://github.com/thomasp85/ggraph). – Axeman May 22 '17 at 13:24
  • Oh, I assumed pngs in the top directory would also generate a NOTE. I'll try it. – effel May 22 '17 at 13:30
  • 2
    I don't see how e.g. ggplot2 is [avoiding](https://github.com/tidyverse/ggplot2/blob/master/cran-comments.md) a note or warning. I get a note when I [put pngs in the top-level directory](https://github.com/tidyverse/ggplot2), and a warning when I [add them to .Rbuildignore](https://github.com/tidyverse/ggplot2/blob/master/.Rbuildignore). – effel May 22 '17 at 14:16

3 Answers3

20

The current preferred solution (at least as used by ggplot2) is to store the images in man/figures/. So in the README.Rmd file, include something like the following setup chunk.

```{r, echo = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-"
)
```

That keeps the images tucked away in a place that won't generate cran check errors, but they are still part of the package. So you don't have to store them elsewhere or use calls to png::readPNG.

Rob Hyndman
  • 30,301
  • 7
  • 73
  • 85
  • I believe this is the best answer, but only the third option is relevant to this question (fig.path = ...). – rcorty Mar 13 '18 at 00:14
3

There are a few options. Update: I think Rob Hyndman's solution is now better than the things I list here.

  1. Store the image online somewhere, and include the URL in the README.
  2. As @Axeman noted, you can follow the ggplot2 approach of storing the images at the top level, and mentioning them in .Rbuildignore.
  3. You can store them in inst/image, and use png::readPNG(system.file("image/yourpic.png", package = "yourpkg")) to read it. Then show it in the README using a plot.
Richie Cotton
  • 118,240
  • 47
  • 247
  • 360
  • Thanks. (1) works well for me here and (3) could be a good option. Oddly I can't get (2) to work, although apparently it does for ggplot. It's the same issue as when they're in a folder; I get `NOTE Non-standard file/directory found at top level: ...` unless they're in `.Rbuildignore`, in which case I get the file-not-found warning from Pandoc. – effel May 22 '17 at 15:04
  • I don't think this issue is truly solved. (1) Would work, but then it's not truly "packaged" -- others can only read the README.md when they have internet connection. (2) I don't think this works because if I share the .tar.gz of my package, and someone untars it and installs, README.md won't have images. (3) This requires manually changing things after knitting and won't be reproducible if I make a change to README.rmd. – rcorty Mar 13 '18 at 00:03
  • in addition, readPNG will dump a load of odd html, and not add an html img tag. There may be a knitr chunk option to overcome this, but without more data, I'm afraid I don't see any of the options above working. – Jack Wasey Jul 19 '18 at 04:23
2

I followed http://r-pkgs.had.co.nz/release.html. same error when putting them in top level and add to .Rbuildignore.

As Richie suggested, after adding images to inst/image, and refer to as ![](inst/image/README-unnamed-chunk-1-1.png)

Jun Cheng
  • 171
  • 1
  • 8