'Pandoc cannot find image path referenced in external HTML file pulled into R Markdown, despite using here() package
I am producing an HTML document through R Markdown, which uses a few external HTML documents for headers and footers. I am also using the here() package to allow relative paths throughout my project. However, when using YAML to include the external HTML through R code, the relative paths within those files do not work.
This is the YAML header of the R Markdown code:
---
title: "Test"
output:
html_document:
includes:
in_header: !expr "here::here('FORMATTING','favicon.html')"
---
The file 'favicon.html' has the following code:
<link rel="icon" type="image/png" href="favicon.ico"/>
My folder structure is:
Main
│ └──.here
├──SCRIPTS
│ └──test_code.Rmd
├──FORMATTING
│ └──favicon.html
│ └──favicon.ico
When I run the script using 'Knit' button in RStudio, I get the following error:
File favicon.ico not found in resource path
Error: pandoc document conversion failed with error 99
It seems that pandoc can find the HTML files just fine using there R code, but then it seems to want an absolute file path for the actual image.
How can I ensure pandoc finds the images without having to resort to absolute paths?
Solution 1:[1]
I habe exactly the same problem. The solution proposed by Modern_ibex (<link rel="icon" type="image/png" href=".\..\FORMATTING\favicon.ico"/>
) does not work for me.
My favicon.html and logo.png are stored in folder "Data".
In favicon.html: "<link rel="shortcut icon" href="Data/logo.png" />"
project.Rproj
|
|___ Data (- favicon.html
| - logo.png)
|
|___ Scripts
|__ Rmds (- my file.rmd)
|
|__ ...
My rmd file is stored in "Scripts/Rmds". My YAML looks like:
title: "Analysis"
author: "me"
date: "`r format(Sys.time(), '%d. %B %Y')`"
output:
html_document:
includes:
in_header: !expr here::here("Data/favicon.html")
when running I get an error message: File Data/logo.png not found in resource path Error: pandoc document conversion failed with error 99 So favicon.html is read but the href is not interpreted. I tried divers href in favicon.html with ~ or . or .. or / or \ or r code but no results.
thanks in advance for help!
Solution 2:[2]
My solution:
In .Rmd YAML
:
title: "Analysis"
author: "me"
date: "`r format(Sys.time(), '%d. %B %Y')`"
output:
html_document:
includes:
in_header: !expr here::here("Data/favicon.html")
In favicon.html
:
<link rel="shortcut icon" href="../../Data/logo.png" />
File structure:
project.Rproj
|
|___ Data (- favicon.html
| - logo.png)
|
|___ Scripts
|__ Rmds (- my file.rmd)
|
|__ ...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Claire |
Solution 2 | Zach Jensz |