I'm struggling with what to Google to start solving this one. It might be a Windows question and not an R question but I could do with some help.
I am using rmarkdown::render to generate html reports. I have a master.Rmd which calls some child_docs. I use the argument output_file = to name the html document. This works fine and I can successfully generate documents called my_report1.html. When I open the html document in my browser (both Chrome and FireFox) the browser tab is labelled as master.utf8.md:
In the past the tab label used to be my_report1.html. I want to fix this because I regularly have multiple reports open and navigating between the tabs to find which report I want is now painful.
Any thoughts on what to check?
The YAML:
---
output:
html_document:
toc: true
toc_float: true
params:
lot: 1
editor_options:
chunk_output_type: console
---
Chunk setup:
```{r setup, include=FALSE}
## GLobal chunk options
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
```
Update: I think this is to do with the YAML title:. I'm going to open a new question with a better example.
I managed to cobble together a work around for this. The tab name in a browser comes from the title declared in the YAML even if you supply a file name to output_file in rmarkdown::render. I wanted to set my title dynamically and this can be done with using the methods described here, example:
---
output: html_document
---
```{r}
title_var <- "Sample Title"
```
---
title: `r title_var`
---
However, I needed an extra work around to suppress the title because I didn't actually want it to make a title. This can be done by using the following css (top of doc or separate file):
<style>
.title{
display: none;
}
</style>
Related
I'm currently writing something in R Markdown. Whenever I Knit the document, RStudio's preview takes me back to the very beginning of the document. Is there a way to make this new preview display a location closer to where I've been working by default? For example, can I make it preview at a location near where my cursor for typing is?
The comments have suggested a number of workarounds. So far, my best is to just type the section number of the section where I'm working in to the search bar that RStudio's preview window provides. I'd click on the relevant entry in the table of contents, but I use output: github_document: toc: true number_sections: true, which is waiting on a patch to its numbered tables of contents.
Not quite as simple as you had in mind, but it is possible to use javascript to control what section of an html document is displayed:
---
title: "Untitled"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
```{js}
location.hash = "#goto";
```
```{r, results='asis'}
cat(sprintf("# %s\n\nSection text here.\n\n", 1:10), sep = "")
```
# GOTO
Scroll Here
```{r, results='asis'}
cat(sprintf("# %s\n\nSection text here.\n\n", 11:20), sep = "")
```
I am using the summarytools package in Rmarkdown and knitting into an HTML. The tables look fine, but whenever I print the HTML document, the formatting of the tables (ctable in particular) is off. See picture below
As you can see, there are those borders within each cell. I believe this has to do with RMD using the default bootstrap.css file, and upon exploration of that file, I found some "#media print" lines. Does anyone have a quick solution to fixing this issue, or would I have to change the underlying bootstrap.css file?
Thanks.
I believe this has to do with RMD using the default bootstrap.css
file...
If this is the case, you may try canceling Bootstrap’s CSS with st_css(bootstrap = FALSE).
Also, you may find helpful to include results = "asis" to knitr chunk options.
Finally, check out Dominic's "Recommendations for Using summarytools With Rmarkdown" and section about ctable(). Acording to Dominic 'rendering method is preferred' with method = 'render':
---
title: "Title"
author: "Author"
date: "16/06/2020"
output:
html_document:
toc: TRUE
toc_float: TRUE
---
```{r setup, include = FALSE}
library(knitr)
library(summarytools)
knitr::opts_chunk$set(results = "asis")
```
```{r summarytools-css, echo = FALSE}
# with summarytools’ CSS we can cancel Bootstrap’s CSS (both are included by default)
# without it odd layout are expected, especially with dfSummary()
st_css(bootstrap = FALSE)
```
```{r summarytools-rmarkdown, echo = FALSE}
ctable(tobacco$gender, tobacco$smoker, style = 'rmarkdown')
```
```{r summarytools-html, echo = FALSE}
print(ctable(tobacco$gender, tobacco$smoker), method = 'render')
```
I'd like to output an accessible version of a presentation I'm making with R Markdown ioslides. At this point, I've been struggling to find much documentation on alt-text for dynamically generated images - not pointers to images - there's lots of information available online on that front.
Seems like the easiest thing to do might be to output my document as a word_document instead of a presentation, and ensure that figures have captions, using fig.cap argument in the chunk header.
However, I'd like the captions to be available only as alt-text - so that this document doesn't look strange to folks who aren't using screen reader tech (I'd like to make my alt-text nice and descriptive, but for folks who can see ok, this will seem odd, because the graph will do the talking instead).
I've included a reprex below. How can I still include the fig.cap as alt-text in the output word document, but not have it show up underneath the graph?
Also, if you are aware of any good resources on making RMarkdown docs accessible, I am all ears!!
Thanks for your help.
---
title: 'test doc'
author: "Nova"
date: "April 2020"
output:
word_document:
fig_height: 5
fig_width: 10
height: 500
widescreen: yes
width: 500
---
```{r setup and comments, include=FALSE}
knitr::opts_chunk$set(echo = FALSE,
message = F,
warning = F,
fig.height = 5,
fig.width = 10,
fig.cap = NA)
library(ggplot2)
```
## cars
```{r ggplot, include=T, fig.cap = "this is some alternative text about this figure"}
ggplot(cars)
```
I'd go back to some kind of HTML output, because it's simpler.
If you want ioslides output, you can use fig.cap="Some alt text" in the chunk option to set the alt text for the figure. Unfortunately, this also generates a visible caption, but you can suppress that. For one slide, just insert inline CSS:
<style>
.caption {
display:none;
}
</style>
somewhere on the slide before the figure. To do it for the whole presentation, put that text in a .css file and include it with YAML like
output:
ioslides_presentation:
css: style.css
It's probably also possible to change the template for this output style, but that looks like a lot more work.
I recently asked
Changing the font size of figure captions in RMarkdown HTML output
and I got a very nice answer which uses this CSS method. I wanted to try the same, but this time with Word output. If you don't want to read my former question, I summarize the issue here: I'd like to make the font size of all figure captions in my R Markdown document smaller. The final output is Word,this time, and I'm working in R Studio. To load the picture, I use the include_graphics function from knitr, because I've been told it's the best way (see here). My .Rmd file is:
---
title: "ppp"
author: "ppp"
date: "`r Sys.Date()`"
output:
word_document:
fig_caption: yes
html_document:
fig_caption: yes
---
<style>
p.caption {
font-size: 0.8em;
}
</style>
```{r setup, include=FALSE}
library(knitr)
opts_chunk$set(echo = FALSE)
```
```{r foo, fig.cap="$f_{p}$ as a function of $g$ for various values of $r=\\frac{\\rho_{w}}{\\rho_{a}}$"}
# All defaults
include_graphics("download.jpg")
```
This is regular text.
The corresponding output is:
Clearly, this CSS method doesn't work (I guess it's something related to HTML, so it doesn't render in Word). In Word I can manually change the font size for each caption, but I'd rather set some global R Markdown parameter. Is that possible?
Almost as easy as in the HTML case. The following applies to the workflow using LibreOffice. But in Word it should be almost the same:
Produce your docx output file.
Open it in LibreOffice (or Word, or Pages, ...)
In LibreOffice, right-click the caption and choose Edit Style (in Word you can open the styles pane with Ctrl+Shift+Alt+S)
In the menu that popped up you can modify the style for Image Captions
When you are done editing the style, click Apply and just save the file as a docx called template.docx
Finally, add a style reference in the YAML header of your Rmd document like
title: "ppp"
author: "ppp"
date: "July 4, 2017"
output:
word_document:
reference_docx: template.docx
fig_caption: yes
And the captions should be smaller now according to how you changed the style in your reference document.
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") })
---