About the hyperlink in RMARKDOWN - r

In rmarkdown, we can create a catalog using 'toc: yes',using the hyperlink, i can link to subtitle.
Now, i want to link subtitle to catalog ? (in the final html, i with to click subtitle,then back to top of the file)
---
title:'my markdown file'
output:
html_document:
toc: yes
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## subtitle 1 :R Markdown
```{r cars}
summary(cars)
```
## subtitle 2:Including Plots
```{r pressure, echo=FALSE}
plot(pressure)
```

You may enclose subheader in an HTML tag <a>.
---
title: 'my markdown file'
output:
html_document:
toc: yes
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## subtitle 1 :R Markdown
```{r cars}
summary(cars)
as.matrix(rnorm(100))
```
## subtitle 2:Including Plots
```{r pressure, echo=FALSE}
plot(pressure)
```

Related

RMarkdown is not referencing tables

Somehow my RMarkdown document is not crossreferencing tables or figures. Here is a stripped down version of my document.
---
title: "Test"
author: "Me"
date: "01/04/2022"
output: bookdown::pdf_document2
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
var1<-sample(LETTERS)
tab1<-table(var1)
My table is in Table \#ref{tab:tab1}
library(knitr)
kable(tab1, caption="my table")
AS we see in Figure \#ref{fig:plot1}
plot(seq(1,10,1))
You should call your tab1 in the code chunk like this {r tab1}. And use () instead of {} for your #ref. In that case it reference to your figures and tables. You can use the following code:
---
title: "Test"
author: "Me"
date: "01/04/2022"
output: bookdown::pdf_document2
---
My table is in Table \#ref(tab:tab1)
```{r tab1, echo =FALSE}
var1<-sample(LETTERS)
tab1<-table(var1)
library(knitr)
kable(tab1, caption="my table")
```
\newpage
AS we see in Figure \#ref(fig:plot1)
```{r plot1, fig.cap ="plot", echo=FALSE}
par(mar = c(4, 4, .2, .1))
plot(seq(1,10,1))
```
Output:
As you can see on the image, when you click on 1 in will go to your table.

Cross references between slides and its content

In an R markdown presentation with output format beamer (to generate a LaTex/PDF file), is it possible to create cross-references between slides, i.e. pages of the final PDF?
This would be very helpful to quickly jump between slides, e.g. to navigate to an appendix at the end of the presentation.
I tried to use bookdown commands as proposed in this SO post, but without success.
MWE:
---
title: "Cross references between slides"
output:
# beamer_presentation: default
bookdown::pdf_book:
base_format: rmarkdown::beamer_presentation
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## Bullets with references
- Bullet 1: \ref{tab:my-table}
- Bullet 2: \ref{fig:my-plot}
- Bullet 3: \ref{appendix}
## Bullets with references (bookdown)
- Bullet 1: \#ref(tab:my-table)
- Bullet 2: \#ref(fig:my-plot)
- Bullet 3: \#ref(appendix)
## table
```{r my-table, cars, echo = TRUE}
library(kableExtra)
kable(summary(cars))
```
## plot
```{r my-plot, pressure}
plot(pressure)
```
## appendix
my appendix
For linking to the appendix, you can use
- Bullet 3: \hyperlinkappendixstart{appendix}
If you examine the tex code produced by your MWE you will see that your table and figure are both included without caption or figure/table environment, but you can reference the slide they are on
- Bullet 1: \hyperlink{table}{table}
- Bullet 2: \hyperlink{plot}{plot}
MWE:
---
title: "Cross references between slides"
output:
beamer_presentation:
theme: "default"
keep_tex: true
includes:
in_header: preamble.tex
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## Bullets with references
- Bullet 1: \hyperlink{table}{table}
- Bullet 2: \hyperlink{plot}{plot}
- Bullet 3: \hyperlinkappendixstart{appendix}
## table
```{r my-table, cars, echo = TRUE}
library(kableExtra)
kable(summary(cars))
```
## plot
```{r my-plot, pressure}
plot(pressure)
```
## appendix
\appendix
my appendix
Approach 2
or you could use the caption package to add captions to your tables and plots
---
title: "Cross references between slides"
output:
beamer_presentation:
theme: "default"
keep_tex: true
includes:
in_header: preamble.tex
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## Bullets with references
- Bullet 1: \ref{foo}
- Bullet 2: \ref{bar}
- Bullet 3: \hyperlinkappendixstart{appendix}
## table
```{r my-table, cars, echo = TRUE}
library(kableExtra)
kable(summary(cars))
```
\captionof{table}{foo}
\label{foo}
## plot
```{r my-plot, pressure}
plot(pressure)
```
\captionof{figure}{bar}
\label{bar}
## appendix
\appendix
my appendix
using this as preamble.tex:
\setbeamertemplate{caption}[numbered]
\usepackage{caption}

How to Create Full Width Figures When Using the "twocolumn" "classoption" for Knitr to PDF?

How can one create a full width figure when using the twocolumn class option in knitr / R / RMarkdown / LaTex?
Based on the Knitr documentation, I've tried two approaches. Nothing short of editing the .tex file has worked for me so far.
This:
---
output: pdf_document
classoption: twocolumn
header-includes:
- \usepackage{lipsum}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
\lipsum[1-2]
```{r fig.env = "figure*", fig.cap = "Test"}
plot(runif(10))
```
\lipsum[3-5]
```{r fig.fullwidth = T}
plot(runif(10))
```
Results in this:
Yihui has fixed this in the development version of knitr. Yihui's response:
The option fig.env = 'figure*' should be respected now (in the dev version of knitr). But the plot will float to a new page. I guess that is a LaTeX issue orthogonal to knitr. Thanks!
Don't forget that you must include a caption for this to work.
---
output: pdf_document
classoption: twocolumn
header-includes:
- \usepackage{lipsum}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
\lipsum[1-3]
```{r fig.env = "figure*"}
plot(runif(10))
```
\lipsum[2]
```{r fig.env = "figure*", fig.cap = ""}
plot(runif(10))
```
\lipsum[2]

hiding entire pages in an r markdown document

I have the r markdown document below. I would like to hide page 2 if parameter "P" is not equal to A.
So the result would be if parameter P != A then only 3 pages are produced.
Is this possible somehow?
---
title: "Untitled"
output:
pdf_document:
toc: yes
params:
P: A
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
\newpage
## PAGE2
this is text for page 2
this is text for page 2
```{r cars}
summary(cars)
```
\newpage
## PAGE3
this is text for page 3
```{r pressure, echo=FALSE}
plot(pressure)
```
\newpage
## PAGE4
this is text for page 4
You could comment the section out based on P value. Here is a bit of a hackish way to do it: surround the section with \iffalse/\fi. Note that the R code inside the section still needs to be valid for this to work (it will be compiled by knitr, but ignored by latex).
```{r, echo=FALSE, results='asis'}
if(params$P != "A")
cat("\\iffalse")
```
## PAGE2
this is text for page 2
this is text for page 2
```{r cars}
summary(cars)
```
\newpage
```{r, echo=FALSE, results='asis'}
if(params$P != "A")
cat("\\fi")
```

Show code in flexdashboard

I'm trying to produce a flexdashboard with R and want to show code in my presentation, but this seems not to work.
Here a little example:
---
title: "Test"
output:
flexdashboard::flex_dashboard
---
```{r setup, include=FALSE}
library(flexdashboard)
```
### Code
```{r, eval=FALSE, include=TRUE}
plot(iris$Sepal.Length, iris$Sepal.Width)
```
### Output
```{r, fig.align='center', echo = FALSE}
plot(iris$Sepal.Length, iris$Sepal.Width)
```
Even other chuck options like fig.show = 'hide' will not work.
Is it possible to show code in a R-chuck in flexdashboard?
The code highlights would be a benefit instead of a plain text.
If you want both the code and plot to show set the chunk options to: echo = true
If you just want code set it to: echo=TRUE, eval=FALSE
---
title: "Test"
output:
flexdashboard::flex_dashboard
---
```{r setup, include=FALSE}
library(flexdashboard)
```
### Code
```{r, echo=TRUE, eval=FALSE}
plot(iris$Sepal.Length, iris$Sepal.Width)
```
### Code and Plot
```{r, echo=TRUE}
plot(iris$Sepal.Length, iris$Sepal.Width)
```
### Plot
```{r, fig.align='center', echo = FALSE}
plot(iris$Sepal.Length, iris$Sepal.Width)
```
It won't show as a panel in your presentation, but to add a </> Source Code button to your dashboard, include source_code: embed in your YAML.
---
title: "Example"
output:
flexdashboard::flex_dashboard:
source_code: embed
---

Resources