簡體   English   中英

Pandoc 找不到在外部 HTML 文件中引用的圖像路徑,該文件被拉入 R Markdown,盡管在此處使用()ZEFE40A8E6034AZF678C

[英]Pandoc cannot find image path referenced in external HTML file pulled into R Markdown, despite using here() package

我正在通過 R Markdown 生成 HTML 文檔,該文檔使用一些外部 Z4C4AD5FCA2E7A3F74DBB1ACED 文檔和頁腳。 我還使用 here() package 來允許整個項目中的相對路徑。 但是,當使用 YAML 通過 R 代碼包含外部 HTML 時,這些文件中的相對路徑不起作用。

這是 R Markdown 的 YAML header

---
title: "Test"
output:
  html_document:
    includes:
      in_header: !expr "here::here('FORMATTING','favicon.html')"
---

文件“favicon.html”具有以下代碼:

<link rel="icon" type="image/png" href="favicon.ico"/>

我的文件夾結構是:

Main
│   └──.here
├──SCRIPTS
│   └──test_code.Rmd
├──FORMATTING
│   └──favicon.html
│   └──favicon.ico

當我使用 RStudio 中的“編織”按鈕運行腳本時,出現以下錯誤:

File favicon.ico not found in resource path
Error: pandoc document conversion failed with error 99

似乎 pandoc 可以使用 R 代碼很好地找到 HTML 文件,但它似乎需要實際圖像的絕對文件路徑。

如何確保 pandoc 找到圖像而不必求助於絕對路徑?

我habe完全一樣的問題。 Modern_ibex ( <link rel="icon" type="image/png" href=".\..\FORMATTING\favicon.ico"/> )提出的解決方案對我不起作用。

我的 favicon.html 和 logo.png 存儲在文件夾“數據”中。 在 favicon.html 中: "<link rel="shortcut icon" href="Data/logo.png" />"

project.Rproj
|
|___ Data (- favicon.html
|          - logo.png)
|
|___ Scripts
           |__ Rmds (- my file.rmd)
           |
           |__ ...

我的 rmd 文件存儲在“腳本/Rmds”中。 我的 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")

運行時我收到一條錯誤消息:在資源路徑中找不到文件數據/logo.png 錯誤:pandoc 文檔轉換失敗並出現錯誤 99所以 favicon.html 已讀取,但未解釋 href。 我在 favicon.html 中用 ~ 或嘗試了 divers href。 或.. 或 / 或 \ 或 r 代碼但沒有結果。

提前感謝您的幫助!

我的解決方案:

.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")

favicon.html中:

<link rel="shortcut icon" href="../../Data/logo.png" />

文件結構:

project.Rproj
|
|___ Data (- favicon.html
|          - logo.png)
|
|___ Scripts
           |__ Rmds (- my file.rmd)
           |
           |__ ...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM