R包devtools::check()检测到顶级目录README.Rmd问题未解决
Troubleshooting R CMD CHECK NOTE for README Images
Hey there, I know it’s frustrating when the usual fixes don’t resolve that stubborn R CMD CHECK note about README images. Let’s walk through some targeted checks and fixes that might help you out:
1. Verify your .Rbuildignore rules are comprehensive
You mentioned adding ^README-.*\.png$, but maybe your image files don’t fit that pattern. Try expanding the rule to cover more cases:
- If your README renders into a
README_filesdirectory (common with knitr), add^README_files/to.Rbuildignore - For all image types in the root tied to README, use
^README.*\.(png|jpg|jpeg|gif)$ - Double-check there are no conflicting rules (like lines starting with
!that might re-include files you meant to ignore) - You can test what gets included by running
devtools::check_built()then inspecting the built package directory to see if any stray images are still present
2. Ensure README.Rmd’s image output is correctly directed
Even if you’re saving to /man/figures/, small misconfigurations can cause issues:
- Make sure you set the figure path early in your README.Rmd (in a setup chunk):
knitr::opts_chunk$set(fig.path = "man/figures/", echo = TRUE) - If you’re using
ggsave()manually, confirm the path is absolute relative to the package root:ggsave("man/figures/my_plot.png", plot = my_plot_object) - Check if any code chunks are overriding the
fig.pathsetting individually—look for chunk options likefig.path = "plots/"that might dump images elsewhere
3. Dig into the exact NOTE message
The specific wording of the note matters a lot. For example:
- If it’s a "Non-standard file/directory found at top level" note: You’re still leaving image files in the package root, so double-check the above steps
- If it’s a note about image size: R CMD CHECK might flag overly large images. You can compress them using the
magickpackage:library(magick) img <- image_read("man/figures/my_plot.png") img_compressed <- image_compress(img, format = "png", quality = 80) image_write(img_compressed, "man/figures/my_plot.png")
4. Clean up caches and update tools
Sometimes old cached files or outdated packages cause weird behavior:
- Run
devtools::clean_dll()anddevtools::clean_vignettes()to wipe build caches - Update devtools to the latest version:
devtools::install_github("r-lib/devtools") - Ensure your
knitrandrmarkdownpackages are also up to date
If you can share the full text of the NOTE you’re getting, that’ll help narrow things down even more!
内容的提问来源于stack exchange,提问作者Indrajeet Patil
相关产品推荐
相关产品推荐

