knittr::include_graphics("image.png") - Cannot find files

I am getting an error when I am inserting an image in R Markdown file. Though, the image exists at the path, R markdown is unable to identify the image.

Note: Created this R markdown file as part of blogdown project.

Image attached.

Unless the file is not in the current working directory, it won't be found, even if it is in a subdirectory.

Install and load the here library. Create an Rproj file if one is not already present in the working directory.

Relative to the working directory provide the calling function with the relative pathname. Assuming that the file is in an immediate subdirectory of the working directory call img, use

here("img/name_of_file.png")

as the argument to any function seeking the file.

As it is a blogdown project, it is a bit different that other format. See about static files in blogdown

Also, this is something that people have asked before

You'll need to add error = FALSE or set the global option associated options(knitr.graphics.error = FALSE) so that the site build correctly.

To preview your post, you should use blogdown::serve_site

This error with include_graphics was introduced in knitr 1.29. For blogdown project, we may need to set the options to FALSE by default as it will always create issue with blogdown... :thinking:
Also chunk preview won't work for a blogdown website when you include with include_graphic

This may need to be improved...

Thank you @cderv. Your proposed solution has worked.

1 Like

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.