R-markdown self_contained - r

I'm using R-markdown for a couple of reports. I do it with self contained graphics because I send it via email.
This worked till recently. But now the images are not shown anymore (with the error of a cross in a box). It might be that I updated the Version of RStudio. I used this a the top of the script:
---
title: "blablablab"
author: "blablablab"
output:
html_document:
fig_caption: yes
toc: no
toc_depth: 2
toc_float: no
number_sections: false
self_contained: yes
---
I know that this question is not very specific. I just wanted to ask if there is anybody which also had self contained graphics which suddenly didn't work anymore.
Thanks for the help in advance!
Greetings Dani

I just had same problem. In RStudio i had previously:
output:
html_document:
self_contained: yes
and it always worked properly producing self-contained HTML. TODAY it stopped working properly. I did update Rstudio a few weeks ago and might not have noticed problem, not sure. SO now i changed to:
output:
html_document:
self_contained: yes
mode: selfcontained
Which seems strange and redundant with two separate lines trying to make things self-contained BUT it worked.

As a sanity check, make sure that you do not have the option include=FALSE in your global chunk options opts_chunk$set
When that is the case, the images are created and stored in the figure-html directory, but not embedded in the html file.

Related

R Bookdown: Append chapter without re-rending whole book

I am rather experienced with R but new to markdown and especially bookdown. I wonder how to render a single chapter and merge it with the existing book without re-building the whole book. The reason why I am asking is that I am creating a book that contains parameterised chapters and each chapter runs very long (1-2 hours). All in all, it will be hundreds of chapters with the same analysis, but different input data and would time-wise add up. I am aware of the knit-and-merge approach, in fact, that's the reason why I chose bookdown, but somehow it is not working as expected.
I am honestly also a little bit confused by the different rendering possibilities. There is the built-book button, the knit button, serve_book(), render_book(), preview_chapter(), ... I figured that one should avoid using the knit button in bookdown and that serve_book() will automatically compile changes. My approach so far is entering serve_book() into console, where it renders the whole book, then I create a new chapter, hit save and it runs the chunks of only that chapter (exactly what I want!) and the single HTML file of the new chapter appears. However, it doesn't show them when I look at the book via the index.html file.
I am only interested in an HTML book and do not need any other output formats.
In order to recreate the problem, I am just using the bookdown example and adding chapters to it.
_bookdown.yaml
book_filename: "book_name"
new_session: yes #true
before_chapter_script: _common.R
delete_merged_file: true
language:
ui:
chapter_name: "Chapter "
_output.html
bookdown::bs4_book:
css: style.css
theme:
primary: "#10395B"
#repo: https://github.com/rstudio/bookdown-demo
bookdown::pdf_book:
includes:
in_header: preamble.tex
latex_engine: xelatex
citation_package: natbib
keep_tex: yes
bookdown::epub_book: default
_index.yaml
---
title: |
![](./Logo_PureGene.png){width=200px}|
|-|
||
author: "Name"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
#output: bookdown::bs4_book
documentclass: book
bibliography: [book.bib, packages.bib]
# url: your book url like https://bookdown.org/yihui/bookdown
# cover-image: path to the social sharing image like images/cover.jpg
description: |
This is a minimal example of using the bookdown package to write a book.
The HTML output format for this example is bookdown::bs4_book,
set in the _output.yml file.
biblio-style: apalike
csl: chicago-fullnote-bibliography.csl
---
# About {-}
I would appreciate any help!
Thanks in advance :)

Change default YAML of Rmarkdown file

I want to change the default template of the Rmarkdown document. I edited the file named document.Rmd in the templates in the RStudio application folder so that the YAML is:
---
title: 'document'
output:
html_document:
self_contained: true
toc: true
toc_float: true
bookdown::pdf_document2:
extra_dependencies: ["float"]
toc: true
---
However, when I open a new Rmarkdown document from RStudio, I get a prompt that asks what type of Rmarkdown document I want. I choose HTML, click OK, and then I get the file opened with these two YAMLs!
---
title: "Untitled"
output: html_document
---
---
title: 'document'
output:
html_document:
self_contained: true
toc: true
toc_float: true
bookdown::pdf_document2:
extra_dependencies: ["float"]
toc: true
---
I do not want to go through the hustle of creating a package or a template. This simple solution should work, I think.
My question: Does anybody know how to work around this? Thank you in advance!
After reading your question, I found this source, which indicated that you could add a template. I also read that document.RMD does not include the YAML. That's why you are getting a double-YAML.
Since I had never added a template for R Markdown, I went through the steps to see how it all came together. That led me to create a repository on Github, and well, here we are. Essentially, I made a Github repository that you can install with the exact template you wanted.
You can also look at the code, as well. Since it was created just to answer this question, if you wanted it to be different, you can change it, as well.
You'll find the repository here: fraupflaume/customYAML
If you want to install it:
devtools::install_github("fraupflaume/customYAML")
To use it, you don't have to call the library (there's no R code). Start an R Markdown script, select "From Template," then choose "Custom YAML."

citation-package: biblatex not working in R bookdown

EDIT: After some investigation, this question is really about the following option in the output yml:
citation-package: biblatex
Without this option, bookdown is using the default citeproc and it's not clear how to modify the number of authors. However, when this option is used, the referencing is not working anymore and my document contains only the refnames in bold instead of inline citations. So I really need to know why the citation-package: biblatex is not working
===== original question below
I can't get bookdown to honour my maxcitename=2 settings. I have tried using this output yml
output:
bookdown::pdf_book:
includes:
in_header: preamble.tex
keep_tex: yes
toc_depth: 3
toc_appendix: yes
with this line in the preamble.tex file:
\usepackage[backend=bibtex, maxcitenames=2, style=authoryear]{biblatex}
I have also tried using this output yml:
bibliography: [likertimputebiblio.bib, packages.bib]
biblatexoptions: [maxcitenames=2]
csl: harvard-university-of-wolverhampton.csl
link-citations: true
nocite: |
#R-bookdown
and I have also tried this output yml:
site: bookdown::bookdown_site
documentclass: book
header-includes:
- \usepackage[backend=bibtex, maxcitenames=2, style=authoryear]{biblatex}
but nothing seems to work.
Please help. Thanks.
The solution to this problem was found after much perseverence!
When setting the output yml, indented under output: etc...
citation_package: biblatex
... the in line references were failing to link to the .bib file and so the refnames were just showing up in bold and failing to make any inline citations.
The expected solution should be to use the additional option:
biblatexoptions: [backend=bibtex, maxcitenames=2]
(maxcitenames=2 is the main reason I want to use biblatex) but this was failing with the error "option backend not recognized."
Finally the solution was to modify the default template in the directory
C:\Program Files\R-3.4.0\library\rmarkdown\rmd\latex
at line 100, from
\usepackage$if(biblio-style)$[style=$biblio-style$]$endif${biblatex}
to
\usepackage$if(biblio-style)$[backend=bibtex, style=$biblio-style$]$endif${biblatex}
I would like to suggest to the package author that this is a bug that needs fixing, because backend=bibtex is a valid option and should have been passed through

How to specify figure sizes with rmarkdown html notebooks

I have not been able to get an rmarkdown html notebook to pay attention to figure sizes that I specify. I've tried using knitr::opts_chunk$set(fig.width=7) and I've tried including the following:
output:
html_notebook:
fig_height: 5
fig_width: 7
toc: yes
toc_float:
collapsed: yes
What is the proper way to specify sizes and how does one vary the image size for different code chunks?
I'm confused about html notebook workflow in general, e.g., to run all the code then render it I've been using Run ... Run All then clicking on Preview. Is that the preferred method?
I'm using the latest version of the rmarkdown and knitr packages, R, and RStudio preview.

Specifying multiple simultaneous output formats in knitr

I would like to be able to specify multiple output formats at the same time, for instance html_document and a pdf_document. I know that this can be done very simply with something like
---
output: [html_document, pdf_document]
---
I might have some of that syntax off, but I can not seem to find the documentation anywhere. I have recently discovered knitr-bootstrap and love it. It is what I have been looking for to be able to dynamically hide my code and output blocks.
Unfortunately, by default, the YAML block for the knitr-bootstrap invocation is quite complex and I do not know how to specify multiple outputs for this.
I have looked at the YAML spec and tried a few different things but I am at a loss. Below is my current YAML frontmatter.
---
title: "Beta Regression Comparison"
opset: bootstrap
output:
knitrBootstrap::bootstrap_document:
title: "Beta Regression Comparison"
theme: Simplex
highlight: Solarized - Light
theme.chooser: FALSE
highlight.chooser: FALSE
menu: FALSE
pdf_document
---
The solution is to change pdf_document to pdf_document: default. I can't unfortunately find a reference for this syntax in the official documentation. If however you open a RMarkdown document in a recent version of RStudio, click Knit HTML and then Knit PDF, it uses this : default syntax.
The syntax is:
---
output:
html_document:
keep_md: yes
pdf_document: default
---
In my case, I tried to knit multiple output-documents using bookdown and found this post which allowed me to get the desired result.
You can write the output-definition in your YAML header as follows:
---
output:
bookdown::pdf_document2:
template: "path-to-my-template"
bookdown::word_document2:
default
knit: (function(inputFile, encoding){
rmarkdown::render(inputFile, encoding = encoding,
output_dir = "my-output-path", output_format = "all") })
---

Resources