embedding svg figures in rmarkdown child files - r

I have a Rmd report that looks like this:
---
output:
pdf_document:
latex_engine: xelatex
---
Some text
```{r child="children/stuff.Rmd", results="asis", cache=FALSE}
```
The stuff.Rmd file is in a subfolder of the project called children. The image I want to include is in a subfolder of the project called figures.
stuff.Rmd looks like this, and the image preview in RStudio works:
something, something
![this is a picture](figures/school_stages.svg)
It seems to be erroring out on the child rmd not being able to find the _school_stages.svg_, you can see this error when editing the child
(no image at path figures/school_stages.svg)
knitting the file gives an error, apparently from the child Rmd:
! Unable to load picture or PDF file 'figures/school_stages.svg'.
Changing figure.Rmd to:
something, something
![this is a picture](../figures/school_stages.svg)
gets rid of the error in edit mode but on knitting gives:
! Unable to load picture or PDF file '../figures/school_stages.svg'.
Any idea how to resolve this?
RStudio Version 1.2.1335
Knitr version 1.23

This is highly dependent on the image type. .png and .pdf are fine, but .svg (plain or inkscape versions don't currently work)

Related

R markdown landscape-only word document

I am trying to knit an .Rmd file to a word document that is entirely in landscape format.
Based on this post, I have tried using a reference doc. I created a Word document, changed the layout to landscape and saved it in the same folder as the .Rmd. However, this doesn't seem to work for me. Maybe I am missing something and saving a file in landscape format is not enough?
Previously, I was using the HTML comments/tags <!---BLOCK_LANDSCAPE_START---> and <!---BLOCK_LANDSCAPE_STOP---> from {officedown}, but since those can only be placed before and after code chunks, the title of the document would end up on a separate page that is portrait. Also, it gives a last page that is blank and portrait and that I don't know how to get rid of.
The current YAML header looks as follows:
---
title: "Summary Report"
output:
officedown::rdocx_document:
reference_docx: landscape_template.docx
---
I am also sure that the reference file is used because I get a warning in the console about not having set a Figure style:
Warning message:
paragraph style for plots "Figure" has not been found in the reference_docx document. Style 'Normal' will be used instead.
Does anyone have any suggestions on what I am missing?
After reaching out to the developer of {officedown} on GitHub, here is the very simple solution to the problem:
YAML header of .Rmd file:
---
output:
officedown::rdocx_document:
page_size:
orient: "landscape"
---

Rmd: Make the figure larger when clicked on it

I have a Rmarkdown file where I include figures with
knitr::include_graphics
The figures show up in the knitted document nicely. However, when I'm reading the knitted document, if I want to focus on one figure, I use the zoom option of the browser, which is not ideal.
Is it possible to add open the figure in a larger window when clicked on it?
PS: I use gitbook and/or bookdown::html for the output format of my Rmd files.
You can try out the themes from rmdformats package which implement this feature. They call it lightbox. To enable,you just need to set lightbox to true in the RMD yaml.
Example:
---
title: "My document"
output:
rmdformats::downcute:
lightbox: true
---

Rmd output format not compiled correctly in blogdown when HTML file already exists

I have a webpage (www.vegardlysne.no) built with blogdown, using the academic theme. In one section of my page, I publish my notes taken during conferences and courses I attend, and I want them to be knitted with a different output format. I store these .Rmd files in the static folder, and specified a "build.R" script to knit .Rmd files in the static folder to HTML before compiling the page.
Specifically, I want to knit these files with theme: darkly and a floating toc, properly specified in the YAML header. This has worked perfectly before, and in principle still works when compiling an Rmd file for the first time.
The problem, however, occur when the Rmd file is updated when they have been previously knitted (corresponding HTML file exists in the static folder). When I update the Rmd file, the HTML file lose the formatting and is compiled as text on white background, with the YAML header as a single line at the top like this:
--- title: "My title" output: html_document: toc: true toc_depth: 2 toc_float: true theme: darkly ---
I can escape the problem by deleting the HTML file in the static folder before running blogdown::build_site(). Then the HTML is knitted properly, but once I make changes to the Rmd file, the problem reoccurs.
I don't know what causes this behavior, and would appreciate any input. I have not updated the theme (Academic 4.6.0) or hugo version (0.59.1, minimum required for the theme version is 0.58). I have the latest version of R and Rstudio.
You might have run into a bug that was fixed two months ago in the development version of blogdown:
remotes::install_github('rstudio/blogdown')
Please restart R, and try to knit the document again.

Displaying figures from RMarkdown with github_document output

I am trying to display figures on github from RMarkdown without success.
The figure is displayed on the local html preview.
After pushing on Github the md file the figure is not displayed.
title: "Untitled"
output: github_document
summary(cars)
plot(pressure)
Need to push the images files containing figures too.

How to add feature or thumbnail image for post in .Rmd file

I'm currently trying to setup a hugo blog with blogdown and can't find a way to add feature or thumbnail images to posts from within .Rmd files, which would like this with the tranquilpeak theme:
As far as I understand, it is easy to do in .md files by just adding some syntax like this:
+++
featuredImage = "img/foobar.jpg"
+++
I found this in the minos theme and in a discourse post. But how can I do this inside a .Rmd file?
It does not matter whether you use .md or .Rmd: if the theme supports the featuredImage option, you can also use it in .Rmd. The only thing you need to make sure is to write metadata in YAML instead of TOML if the post format is .Rmd (see documentation), i.e.,
---
featuredImage: "img/foobar.jpg"
---
One option is to change the .Rmd filename to index.Rmd and use the featured.png/jpg image in the page's folder.
Works fine for me.

Resources