image (.png) files into RMarkdown

Viewed 421

I'm new here. I have seen some posts on the inclusion of image files in RMarkdown code. And I have been successful doing it myself. But when it works, it usually follows an hour or more of frustrating tries that should seemingly work, and then suddenly it does without insight.

I am working on a company (university) RStudio server. My yaml has this stuff

output: 
  html_document:
    toc: true
    toc_depth: 2
    number_sections: true
  learnr::tutorial:
    progressive: true
    allow_skip: true
    df_print: default
runtime: shiny_prerendered

and then is followed by a setup code block that imports images, including knitr. On its first compile, if my source file is called "testR.Rmd", the process builds a folder in the same directory called "testR_files", and inside that folder is a subfolder titled "figure-html"; I believe figures generated in code blocks go there. When I want to include a .png file I've generated in some other way, I upload it, often placing it in that same directory "./testR_files/figure-html" (though I've tried other places as well), and then the odyssey begins. In my source file I've done each of these:

knitr::include_graphics("testR_files/figure-html/myimage.png")

Both produce an empty image space in my output file. At least the first one puts an actual image in the source file editor, making it appear that it has found the file, but then doesn't add it to the resulting document.

I have other RMarkdown documents in the same directory, all with their own support file structure. I can copy a call like those above from a different .Rmd file, say testaR.Rmd, that now compiles (I don't know why) when testaR.Rmd is knit, and has the same introductory yaml and setup code, put it in testR.Rmd (only the command to access it; the location of the file has not been changed), and it will now produce an empty graphic. If I place "myimage.png", the one I want to compile with testR.Rmd, into "testaR_files/figure-html/" and try to pull it from there with testaR.Rmd, it works, but not if I try to pull it from there with testR.Rmd.

Is there some sort of elaborate permission thing happening here? If I "git add, commit, push" the new image and "figure-html" folder, will it all be magically fixed?

This has eaten up half of my afternoon without success, and it isn't the first time.

0 Answers
Related