I am using this pseudo code to generate dynamic title on an flexdashboard in R
title_Var <- paste("Numurkah", format(max(Data$`Cutt Off daily`), "%d %b %Y"))
which works fine in the R console : Numurkah 09 Oct 2018
but when I use it inside the RMD file, (this code is inserted after I defined my variable in r)
---
title: \`r title_Var`\
---
it render in the HTML file as
09 Oct 2018
so YAML get my variable correctly, but it show only the date not the first text " Numurkah"
thanks for the reply, I found the correct answer
---
title: `r title_Var`
---
I think there are some restrictions on which YAML lines R code can execute from (see for example Inline R code in YAML for rmarkdown doesn't run). You can create the title with system parameters, it seems, but not with variables that are identified later in the markdown doc. For example this works:
---
title: '`r paste("Numurkah", format(Sys.Date(), "%d %b %Y"))`'
date: '`r format(Sys.time(), "%d %B %Y")`'
output: html_document
---
Related
I would like to include external markdown file covering inline code as well. Once I hit the Knit on RStudio, it does show only code text rather than the actual value of sys.time. If I place the content of about.md into the main.Rmd, there is no issue. The point should be related with includeMarkdown but it does not take any parameter except than path. Any suggestions ?
Thanks in advance
main.Rmd
---
title: "test"
author: "test"
output:
flexdashboard::flex_dashboard:
orientation: rows
social: menu
vertical_layout: fill
---
```{r}
htmltools::includeMarkdown('about.md')
```
about.md
Today is `r format(Sys.time(), "%d %B %A %Y")`
Current Output
Today is r format(Sys.time(), "%d %B %A %Y")
htmltools::includeMarkdown() only includes plain Markdown, not R Markdown. Your about.md is actually R Markdown---it contains R code to be evaluated.
To include an R Markdown document in another one, you can use the chunk option child:
```{r, child='about.Rmd'}
```
I suggest you rename about.md to about.Rmd.
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 am using rmarkdown and knitr
I have two questions:
Q1: I am not sure why the figure caption does not appear when I build my rmarkdown document.
Here is an example. I get the figure there but with not the figure caption!
---
title: "Untitled"
author: "XXXX"
date: "9 September 2016"
output: pdf_document
---
## R Markdown
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
![figure1 caption](my photo.png)
Q2: I am developing an R-package using RStudio. I am able to create an html_vignette using the code below. However, I am not sure why I am not able to create a PDF vignette when I change the output to output: rmarkdown::pdf_vignette? The latter gives an error:
Error: 'pdf_vignette' is not an exported object from 'namespace:rmarkdown'
Execution halted
---
title: "TITLE XXX"
author: "AMT"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{package-intro}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
I am new to this area, so if somebody can explain that would be great.
Using knitr in RStudio, I have an rmarkdown file:
---
title: "PDF knit error"
output: pdf_document
date: "`r format(Sys.time(), '%d %B, %Y')`"
---
#Content
In RStudio, there is a nice little dropdown option where I can change the output format:
However, when I use this to change between output formats, the YAML header is changed in an undesirable way (it is also changed appropriately, as the output value changes). That is, the date field, which has an R snippet to dynamically assign the value to date, gets munged-up because the double quotes are changed to single quotes, and the single quotes are changed to a pair of single quotes.
For example, when I use this button to change the out put format to HTML, the markdown file is altered to:
---
title: "PDF knit error"
output: html_document
date: '`r format(Sys.time(), ''%d %B, %Y'')`'
---
#Content
The date changes compared:
"`r format(Sys.time(), '%d %B, %Y')`" # before another output option selected
'`r format(Sys.time(), ''%d %B, %Y'')`' # after another output option selected
This change causes the Knit to fail:
processing file: yaml-header-test.Rmd
Quitting from lines 2-7 (yaml-header-test.Rmd)
Error in base::parse(text = code, keep.source = FALSE) :
<text>:1:29: unexpected input
1: format(Sys.time(), ''%d %B, %Y'')
^
Calls: <Anonymous> ... inline_exec -> withVisible -> eval -> parse_only -> <Anonymous>
Execution halted
Is there away to prevent the switching of formats via the dropdown menu from causing edits to the date field? And, pre-emptively, yes, I recognize I can accomplish the change in format by editing the output field directly, but my question is about consequences of the GUI button.
System details:
Ubuntu 16.04
pandoc 1.17.2
R 3.3.1
RStudio 0.99.489
I am using RMarkdown to write some university work
I have created a table using the code below and need to export it to Microsoft Word
Can anyone tell me how to add a label describing the data in the table or do I have to do this in MS Word afterwards
---
title: "Data"
author: "foo"
date: "2 July 2016"
output:
word_document:
bibliography: bibliography.bib
---
kable(table(Rawdata$Var1, Rawdata$Var2))
Use the caption argument in kable.
If you want more options for formatting tables in Word output, I would recommend downloading the Gmisc package and using the Gmisc::docx_document format. Just keep in mind that it will save the file as an HTML file that can be opened as a Word Document and preserve the formatting.
For example:
---
title: "Data"
author: "foo"
date: "2 July 2016"
output: Gmisc::docx_document
---
```{r}
knitr::kable(head(mtcars[, 1:3]),
caption = "This is the table caption")
```