Very Basic Image Issue


I am trying to simply insert an image into RStudio but the photo is not showing up.
This is the code I'm using, and when I run it, it all turns green, but the photo is not showing up. This is exactly the way my example problem tells me to do it, so I'm not sure what is going wrong.



Hi! Welcome!

It sounds like you're working on an R Markdown document. An R Markdown document combines chunks of R code with plain text written with formatting code called "Markdown". An R Markdown file can be output into several different formats, such as HTML or PDF (and more). When the file is converted into an output format, the formatting code is applied to the plain text to produce formatted text, and the formatted text is combined with the code chunks and whatever results they produce.

So ![](imgs/starschema.png) is Markdown formatting code for inserting the image named starschema.png, found inside the imgs folder, into your document. Since it's Markdown code, it goes in the Markdown sections of the R Markdown document — those are the plain text areas in between the R chunks.

When you type the image inserting code into a Markdown section of an R Markdown file in RStudio, it won't do anything immediately. The image doesn't get inserted until the file is output (jargon: "knit") into your chosen output format. You usually do this by clicking the "Knit" button (this might be called the "Preview" button if your output format is an R Markdown Notebook).

Here's what's a little confusing: you have a # in front of the image inserting code, and you said

That makes me wonder if you've put this inside an R chunk? This code won't do anything inside an R chunk, for two reasons:

  1. The # is an R comment character, which tells R to ignore everything else on that line.
  2. Even if you remove the #, this is still Markdown, not R, so R will not be able to run it (you'll get an error if you try)

Maybe double check exactly where your example problem told you to put this line? If you did put it in a Markdown section of the document, try outputting the document (Knit or Preview button) to see the result of inserting the image.

P.S. Since this question is about R Markdown, I've moved it to that category