I created a vignette for a package with following header:
---
title: "My package vignette"
output: rmarkdown::html_document
vignette: >
%\VignetteIndexEntry{MyPackage}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
However, vignette format doesn't allow full functionalities allowed by html_document.
I would like to automatically change the YAML header in order to have the ability to knit the vignette in full html_document format (with options like toc_float: true)
I'm trying to read the .Rmd file with ReadLines and replace the header using gsub, but I'm struggling with escape characters / regex:
content <- readLines('vignettes/MyPackage.Rmd',encoding = 'UTF-8')
vignette_header <- "output: rmarkdown::html_document
vignette: >
%\\VignetteIndexEntry{MyPackage}
%\\VignetteEngine{knitr::rmarkdown}
%\\VignetteEncoding{UTF-8}"
normal_header <-
'output:
html_document:
toc_float: true'
gsub(vignette_header,normal_header,content )
Error in gsub(vignette_header, normal_header, content) :
regular expression 'output: rmarkdown::html_document
vignette: >
%\VignetteIndexEntry{ALPSYSparams}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}' incorrect, because of 'Invalid contents of {}'
Thanks for your suggestions, alternative methods to modify a file header with escape characters welcome.
Instead of modifying header, as a workaround I made two Rmarkdown files with different headers, and used child chunck option to insert the same Markdown body:
Vignette :
---
title: "My package vignette"
output: rmarkdown::html_document
vignette: >
%\VignetteIndexEntry{MyPackage}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r child=here::here('data/MyPackageVignetteBody.Rmd')}
```
Fully featured Markdown :
---
title: "My package fully featured Markdown"
output:
html_document:
toc: true
toc_float: true
---
```{r child=here::here('data/MyPackageVignetteBody.Rmd')}
```
Related
I wrote my own titlepage and it is loaded via an include in the R-markdown file. However, this conflicts with the pandoc title. I am trying to find settings in the R markdown yaml header such that pandoc does not insert the following code snipped into the tex-file.
% Create subtitle command for use in maketitle
\newcommand{\subtitle}[1]{
\posttitle{
\begin{center}\large#1\end{center}
}
}
\setlength{\droptitle}{-2em}
\title{}
\pretitle{\vspace{\droptitle}}
\posttitle{}
\author{}
\preauthor{}\postauthor{}
\date{}
\predate{}\postdate{}
There is no clear indication in the pandoc documents or the r markdown guidelines how to disable the title generation. Any help would be appreciated.
Update: In particular, I am looking for solutions that allow me to keep creating my title page with the \maketitle command. That is why I focussed on this particular code snipped that I want to get rid of.
I also use my own title page with rmarkdown documents for latex/pdf outputs. To remove the title, you can add the following command in a text file called with in_header :
\AtBeginDocument{\let\maketitle\relax}
A reproductible example with the header.tex file built directly within the Rmd document:
---
title: "RMarkdown No title Test"
author: "StatnMap"
date: "July 30, 2017"
output:
pdf_document:
includes:
in_header: header.tex
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r rm_title_page, echo=FALSE}
head <- cat('
\\AtBeginDocument{\\let\\maketitle\\relax}
', file = "header.tex")
```
# Title 1
**Some text**
# Title 2
**Some text**
Using compact-title: false in the YAML works.
---
title: "This title is not compact"
author: "Test"
date: "2019 May 10"
output: pdf_document
compact-title: false
---
I had the same problem today. Here's what I did. (Maybe I'll update the solution when I come up with something better.)
The solution is dumb but useful. I can't set an arbitrary space between the lines now, because I used \newline.
---
title: "\\huge My Smart Title"
author: "\\newline \\Large My Smart Author"
date: "\\newline \\Large 2018-12-25"
output:
pdf_document:
includes:
in_header: preamble.tex
latex_engine: xelatex
---
Below are the outputs before and after the solution.
BEFORE:
AFTER:
Note:
You may be confused about the different sizes of the "author" and the "date" in the two pictures above, if you don't know that the fontsize of the "author" and the "date" is \large instead of \Large by default.
END
I defined keywords in the .Rmd file, but they are not visible in the output PDF.
Current Output
Expected results
Current .Rmd
First lines of .Rmd file looks as follows:
---
title: "No keywords within the output file"
abstract: "This is sample text for abstract. Generally speaking, I would like to show keywords list below an abstract (as in case of the linked example)"
keywords: "keywordA, keywordB"
author: "Mateusz Kędzior"
output:
bookdown::pdf_document2:
keep_tex: true
number_sections: yes
toc: false
base_format: rticles::elsevier_article
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Elsevier article
This is an R Markdown document.
I'm trying to prepare an Elsevier article.
I wonder if base_format is actually doing any work in your example (the output looks the same with and without base_format). Since base_format is an argument to pdf_book, consider changing your YAML header to
---
title: "No keywords within the output file"
author:
- name: "Mateusz Kędzior"
abstract: "This is sample text for abstract. Generally speaking, I would like to show keywords list below an abstract (as in case of the linked example)"
keywords: "keywordA, keywordB"
output:
bookdown::pdf_book:
keep_tex: true
number_sections: yes
toc: false
base_format: rticles::elsevier_article
---
which gives you the following output:
Alternatively, add keywords to the abstract:
abstract: "This is sample text for abstract. Generally speaking, I would like
to show keywords list below an abstract (as in case of the linked example) \\par
\\textbf{Keywords:} a, b"
to get
I know making .Rmd produce .html file or .md file should use the following codes
---
title: "report"
output: html_document
---
or
---
title: "report"
output: md_document
---
But how to produce the two at the same time? I try the following, but it is not working
---
title: "report"
output: html_document, md_document
---
Another issue is that, how can I make the name of the .html file (or .md file) produced different from the .Rmd file? For example, I have sample.Rmd, but I want the .md file to be named as sample_1.md.
You can use keep_md: yes to keep the md file while still getting other output. So the YAML will be something like
---
title: "report"
author: "me"
date: '2016-04-25'
output:
html_document:
keep_md: yes
---
You can customise the knit button, so that you can simultaneously render one Rmd file to multiple outputs.
Press knit button once, and then get two outputs (.html/.md) from the example below.
```
knit: (function(input, ...) {
rmarkdown::render(
input,
output_format = "all"
)
title: "report"
output:
html_doclument:
number_sections: true
toc: true
md_document:
variant: "markdown"
number_sections: false
toc: false
```
The following header is from a R Markdown document which I have compiled as a PDF. It results in code snippets being cropped. Commenting out the PDF output block and uncommenting the HTML block results in well-formatted HTML output.
Is there a parameter I can change to fix this? Or do I need to format my code snippets differently?
---
title: "fmodbc Package"
author: "Bobby Rohrkemper, Software Developer at Schweiz Tourismus"
date: "`r Sys.Date()`"
# output:
# rmarkdown::html_vignette:
# toc: TRUE
output:
pdf_document:
toc: TRUE
vignette: >
%\VignetteIndexEntry{Vignette Title}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
Or should I perhaps try a different theme? I would be interested in the Tufte Handout theme, but thought it makes more sense to fix the standard output first.
http://rmarkdown.rstudio.com/tufte_handout_format.html
PDF output is cropped:
HTML output looks good:
Code snippet:
This produces the results above. I am not modifying it in the PDF and HTML versions.
```{r}
# names(dat)
# "__Backups" "__Budget" "__Comments" "__Documents" "__globals" "__KPI" "__Marketing Activities" "__MarketManager" "__Segmentation" "__sts_Account" "__sts_Budget" "__sts_Mandate" "__sts_ProfitCenter" "__UserLog" "__VL_PlanningStatus"
```
Use the chunk option tidy = TRUE.
tidy: (FALSE; logical) whether R code should be tidied up using the function tidy_source() in the formatR package; if it failed to tidy up, original R code will not be changed; tidy=TRUE is like keep.source=FALSE in Sweave, but it also tries not to discard R comments (N.B. this option does not work in certain cases; see http://yihui.name/formatR for more information)
---
title: "fmodbc Package"
author: "Bobby Rohrkemper, Software Developer at Schweiz Tourismus"
date: "`r Sys.Date()`"
# output:
# rmarkdown::html_vignette:
# toc: TRUE
output:
pdf_document:
toc: TRUE
vignette: >
%\VignetteIndexEntry{Vignette Title}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r}
library(knitr)
opts_chunk$set(tidy = TRUE)
```
```{r}
# names(dat)
# "__Backups" "__Budget" "__Comments" "__Documents" "__globals" "__KPI" "__Marketing Activities" "__MarketManager" "__Segmentation" "__sts_Account" "__sts_Budget" "__sts_Mandate" "__sts_ProfitCenter" "__UserLog" "__VL_PlanningStatus"
```
I am trying to convert a .Rmd file to .md (output: md_document), but the title does not show up on the rendered file.
The title does show up when I try to render the same file as an .html file (output: html_document).
Title shows up on rendered document:
---
title: "Test"
output: html_document
---
```{r}
head(cars)
```
Title does not show up on rendered document:
---
title: "Test"
output: md_document
---
```{r}
head(cars)
```
rmarkdown::render(my_file)
Any ideas why?
I am using RStudio 0.98.1091 and R 3.1.2 on a Mac 10.9.5.
The code in between -- gets interpreted, as my references are rendered with the following piece of code:
---
title: "Test"
output: md_document
bibliography: ~/mybib.bib
---
This is a test where I cite [#post1, #post2]
The interesting thing is that when I ask for both the html and md files to be generated, the title shows up on the .md file:
---
title: "Test"
output:
html_document:
keep_md: yes
---
Shouldn't the output of keep_md: yes be the same as output: md_document?
Markdown does not have such a concept as "title". HTML has the <title> tag (and Pandoc also puts the title in <h1> for the HTML output from Markdown so you can see it from the HTML body), and LaTeX has the \title{} command. It is not unexpected to me that the YAML metadata (including the title info) is not reflected in the Markdown output.