Is there a way to have code syntax inside a block quote using RMarkdown (knitr, Knit to HTML)?
Example Rmd file:
---
title: "MyTitle"
author: "Me"
date: "Today"
output:
html_document:
fig_caption: true
toc: true
toc_float: true
---
# Introduction
> My block quote
saying things here
```
some code here, but within the block quote
and more of the same here
```
It turns out a simple two-space indent will do it:
> My block quote
saying things here
```
some code here, but within the block quote
and more of the same here
```
Here are two options for putting a code chunk inside a block quote. I prefer the second because I can still run the chunk as see its output in RStudio (and it's easier to copy from).
> Example 1:
>
> ```{r}
> 10 * 2
> ```
<blockquote>
Example 2:
```{r}
10 * 2
```
</blockquote>
Related
I'd like to have the section titles in the header not the body of the page. \fancyhead[C]...puts the section title in the header but how do you suppress the body printing of the section?
---
title: "Untitled"
classoption: landscape
output:
pdf_document:
number_sections: false
dev: pdf
keep_tex: false
toc: yes
header-includes:
- \usepackage{fancyhdr}
- \usepackage{etoolbox}
- \pagestyle{fancy}
- \fancyhead[L]{left}
- \fancyhead[R]{right}
- \fancyhead[C]{ \nouppercase{\leftmark} }
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
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:
```{r cars}
summary(cars)
```
\newpage
# Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE}
plot(pressure)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
\newpage
# page 3
You can also embed plots, for example:
```{r pressured, echo=FALSE}
plot(pressure)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
I try to get Highouts Output in my Powerpoint presentation, but the suggestion does not work .This feature is still pretty new and I was not able to find something valueable in the docu.
---
title: "Untitled"
output:
beamer_presentation: default
powerpoint_presentation: default
ioslides_presentation: default
always_allow_html: yes
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(highcharter)
```
### R Markdown
This is an R Markdown presentation. Markdown is a simple formatting
syntax for authoring HTML, PDF, and MS Word documents. For more
details on using R Markdown see <http://rmarkdown.rstudio.com>.
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.
### Slide with Bullets
- Bullet 1
- Bullet 2
- Bullet 3
### Slide with R Output
```{r cars, echo = TRUE}
highchart() %>%
hc_add_series(data = mtcars, type = "bar", hcaes(y = cyl))
```
### Slide with Plot
```{r pressure}
plot(pressure)
```
Produces:
Functions that produce HTML output found in document targeting pptx output.
Please change the output type of this document to HTML. Alternatively, you can allow
HTML output in non-HTML formats by adding this option to the YAML front-matter of
your rmarkdown file:
always_allow_html: yes
Note however that the HTML output will not be visible in non-HTML formats.
I added the always_allow_html: yes part to the top, but it still does not work. Can anyone help me?
I would like to write an R Markdown document which presents code examples of how to write an R Markdown document. For example, I want to show in the document how to render text as bold.
`**this is bold**` will render 'this is bold' with bold text, i.e. **this is bold**
That works fine, the ` render the text within as code. However, I can't figure out how to get a code chunk to display properly. e.g.
```{markdown, eval=FALSE}
```{r}
x = rnorm(1)
```
```
This doesn't work because markdown isn't a supported language. I can't enclose the r code block in ` because I need that symbol to mark the beginning of the code chunk and it only works inline.
I can do some hoop jumping by actually using R
```{r, echo="FALSE"}
o = "```{r}\nx=sample(1)\n```\n"
cat(o)
```
which renders as
## ```{r}
## x=sample(1)
## ```
But this is more complicated for me writing the document and the code it generates doesn't allow for simple copy/paste.
Is there a native way to render as code the markdown necessary to create the R code block?
I found the bookdown book on Rmarkdown which has examples of R code chunks being rendered via Rmarkdown. The book source is available on GitHub and the relevant chapter is located here.
The chunk below works as desired. I can't explain why the `r ''` is required at the beginning of the block, but it is.
````markdown
`r ''````{r}
x = sample(1)
```
````
If you don't put {r} after the three backticks, rmarkdown will just pass the block on to markdown and it almost works. For example, this
```
```{r}
x = rnorm(1)
```
```
displays as
It's not quite right; the braces around the r have been removed. (I think r-markdown did that, not markdown.) I don't know if there's an option to force them in, but they will appear if there's a non-letter ahead of the r. You can put in a space, or (if you can figure out how) a zero width space, which R will display using "\u200B".
You can use the experimental knitrhooks package, which adds the chunk option chunk_head to enable us to keep the header. The package is in development on GitHub here.
To install the package, use the command devtools::install_github("nathaneastwood/knitrhooks"). Once installed, you can use the chunk hook by loading the package and then calling the function chunk_head() in your header.
Here is an example:
---
title: "Untitled"
output: pdf_document
---
```{r, include = FALSE}
library(knitrhooks)
chunk_head()
```
```{r, chunk_head = TRUE, echo = TRUE}
x <- sample(1)
```
Unfortunately, this will not display syntax highlighting, but as discussed within this issue, this is a limitation within how knitr processes the file.
So.
I want to insert some image files into an Rmarkdown document, auto-generate labels and be able to reference those images from elsewhere in the text. I'm using bookdown, so I start off with
---
output:
html_document:
toc: true
number_sections: true
fig_caption: true
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(bookdown)
```
According to the bookdown manual if I have the following code chunk:
```{r knnPlot, echo=FALSE, fig.cap="Knn Plot"}
knitr::include_graphics("knn-cs3-gs2.png")
```
then I should have a label fig:knnPlot automatically generated, because using fig.cap apparently puts R in a figure environment and automatically prepend "fig" to the label. It then tells me I should be able to reference the figure using \#ref(label), or rather, in this case, \#ref(fig:knnPlot)
When I do this however, the text "\#ref(fig:knnPlot)" is output, rather than an actual cross reference. There's no figure label, no numbering. How is this meant to work?
I can't get the hard coding method suggested here to work. Nor can I get the only other option I can find to work, it tells me to install pandoc-crossreference, which leads me down an absurd rabbit hole of installing haskell of all things along with endless dependencies and obscure pointless error messages which lead to spectacularly unhelpful developer forums filled with 6 pages of error logs.
You are not creating a bookdown document. Use bookdown::html_document2 instead:
---
title: "Bookdown"
output:
bookdown::html_document2:
fig_caption: yes
number_sections: yes
toc: yes
---
```{r Doge, echo=FALSE, fig.cap="Mighty Doge"}
knitr::include_graphics("unnamed.png")
```
Check out this picture: \#ref(fig:Doge)
In an R Markdown (.Rmd) file, how do you comment out unused text? I'm not referring to the text in the R code chunk, but the general texts, like % in LaTex for example.
I think you should be able to use regular html comments:
<!-- regular html comment -->
Does this work for you?
Extra yaml blocks can be used anywhere inside the document, and commented out with #
---
title: "Untitled"
output: html_document
---
No comment.
---
# here's a comment
# ```{r}
# x = pi
# ```
---
Note however that this does not prevent knitr from evaluating inline r code.
After drag the lines you want to make comment, press SHIFT+CMD+C (macOS), SHIFT+CTRL+C (Windows). This is the shortcut of R Markdown editor (R Studio) to comment out.
You can always turn off code by putting it within an if(F){} statement.