Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
661 views
in Technique[技术] by (71.8m points)

r - NOTE or WARNING from package check when README.md includes images

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...