I run a GitHub pages Jekyll site with the minimal mistakes theme and have spent all day yesterday trying to knit a .Rmd
to .md
with the proper formatting and relative file paths. I ran into a file pathing issue which is perfectly described here. I tried her workaround and it works as described.
This is where my site lives locally:
~/Developer/mkruisbrink.github.io/
.Rproj
.Rmd
files: ~/Developer/mkruisbrink.github.io/_reports/
ggplot2
output from .Rmd: ~/Developer/mkruisbrink.github.io/_reports/figure/
Below you will find my repex .Rmd
where I'm trying to include both an image and an output from ggplot2
in the resulting .md
file.
---
title: "repex"
author: "Max Kruisbrink"
date: "`r Sys.Date()`"
output:
md_document:
variant: gfm
---
{r setup, include=FALSE}
library(knitr)
library(tidyverse)
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_knit$set(root.dir = rprojroot::find_rstudio_root_file())
# define knitr paths
base.dir <- "~/Developer/mkruisbrink.github.io/"
base.url <- "/"
fig.path <- "_reports/figure/"
# set knitr parameters
opts_knit$set(base.dir = base.dir, base.url = base.url)
opts_chunk$set(fig.path = fig.path)
{r tidyverse}
knitr::include_graphics("img/icons/r-packages/thumbs/tidyverse.png")
{r ggplot-examples}
# loads ggplot
library(tidyverse)
# using the starwars dataset
data <- starwars
# plot the height distribution
ggplot(data, aes(height)) +
geom_density(aes(color = sex))
And these are the two links included in the resulting .md
file
![](/img/icons/r-packages/thumbs/tidyverse.png)
![](/_reports/figure/ggplot-examples-1.png)
As you can see, the relative file paths are correct when considering Jekyll requires relative file paths from the root directory.
But... for some reason ONLY the tidyverse.png
image is loaded correctly when I build my site locally. I receive this error when I load the page on localhost with the relative links:
[2022-08-12 16:06:08] ERROR "/_reports/figure/ggplot-examples-1.png" not found.
When I use the full path ![](D:/Username/Developer/mkruisbrink.github.io/_reports/figure/ggplot-examples-1.png)
I don't get the error but there's no image either.
When I inspect the local page in devtools next to VSC I fail to see where the error is. The link appears correct to me?
The file is there! I'm at a loss. Anyone able to shine light on my case? I'm much obliged.
Live edits
.md
file locally with relative file paths, it loads no images at all. When I add the full paths both images are loaded.Anyone any ideas? Halp
for some reason, the whole _reports/figure/
folder wasn't recognized properly. When I changed the relative path for the .Rmd
report figures to img/rmd/
using the same method, the images loaded correctly.