RMarkdown keeps losing track of images

Hi all,

I've been having an annoying issue with RMarkdown lately I'm hoping someone knows how to solve. When I insert images into an RMarkdown, it either can't find them (if I paste the file address in document), or it puts them there initially but can't find them later when I open my project back up the next day (happens when I use the visual editor mode to insert a picture). Any pointers would be appreciated.

Here's an example of the file path pasted into a document:
[Model A.](C:/Users/rschn/OneDrive/Ph.D. Program/Classes/SEM/SEM_class/Scripts/Homework assignments/imagesg/hw4ma.png)

And here's an example of using the RMarkdown visual editor:

Both give me the same error: "No image at path...."

Does this error happens when you render the document ? By Knitting with the button or calling rmarkdown::render() ?

Or is it something you see in RStudio directly ?

Both actually. Since these are homework assignments I will end up opening them, editing them, and sometimes knitting them multiple times to correct things or check formatting. When the document is knitted, the images don't appear, and when I'm looking in RStudio I get that error. What's throwing me off though is why they insert initially, but they get lost eventually.

Might it have something to do with repeatedly switching back and forth between the Visual Editor and the regular RMarkdown? I do that quite a bit.

It is possible but I don't know about that. If you happen to make it a reproducible example you could open an issue in RStudio Github repo. I'll add the IDE category here too.

It may also due to the fact you are using OneDrive maybe :man_shrugging:

I don't see why you would get a different path between visual editor and source mode

I'll try repro'ing it on a different location on my C: drive and see if the issue comes up again. If it does, I'll try and upload it to Github for you. Do you have any links on how to do that? I've never linked anything to Github before.

Also wondering if it could be the spaces in the file path (e.g., /Homework assignments/....). OneDrive could definitely make sense too; if OneDrive is syncing the images it might appear to RStudio like they're disappearing.

Just ran a test and got it to happen again immediately. I'll keep testing, but so far:

I've copied a duplicate folder into my "Sandbox" testing project to see if changing the location on my C: affected it. Once I opened the RMarkdowns in this new project, I re-inserted two of the same images as before, using the Visual Editor again. Then I saved and closed the project.

Immediately after opening the project again, the second image--the one that I left named as "Screenshot 2021-04-08 211622.png"--was giving the error. The first image though, which I renamed as Picture1.png, was fine.

I'll have to keep playing with it more to see if Picture1 disappears too, but from initial testing it looks like RStudio doesn't like something about the names Window's Snipping Tool gives by default.

1 Like

This topic was automatically closed 21 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.