The following Test.Rmd will produce an interactive learning widget for r using knitr (see the link).
---
title: "Example Document"
author: "Your name here"
output:
html_document:
self_contained: false
---
```{r, include = FALSE}
tutorial::go_interactive()
```
By default, `tutorial` will convert all R chunks.
```{r}
a <- 2
b <- 3
a + b
```
Edited
Wondering how to an get an interactive learning widget for r using quarto. Need help for YAML of .qmd, my attempt is
---
title: "Test"
author: "MYaseen208"
format:
html:
self_contained: false
---
```{r}
#| echo: false
#| include: false
tutorial::go_interactive()
```
```{r}
#| echo: false
1 + 1
```
You can add options to executable code like this
```{r}
#| echo: false
2 * 2
```
The `echo: false` option disables the printing of code (only output is displayed).
However, it throws the following error:
ERROR: Validation of YAML front matter failed.
ERROR: (line 5, columns 3--7) Field "html" has empty value but it must instead be an object
4: format:
5: html:
~
6: ---
ERROR: Render failed due to invalid YAML.
Another attempt which render but don't produce the required output:
---
title: "Test1"
author: "MYaseen208"
format:
html:
output-file: "Test1.html"
self-contained: false
---
To fix the error, you should use self-contained instead of self_contained in quarto like this:
---
title: "Test"
author: "MYaseen208"
format:
html:
self-contained: false
---
```{r}
#| echo: false
#| include: false
tutorial::go_interactive()
```
```{r}
#| echo: false
1 + 1
```
You can add options to executable code like this
```{r}
#| echo: false
2 * 2
```
The `echo: false` option disables the printing of code (only output is displayed).
Output:
I don't think the package is currently supported on Quarto, since the latest release of the package was in 2016. You might contact them about this.
Related
I would like to add a bibtex reference to the notes for a gt table in Quarto, but using #citationkey does not seem to work. Does anyone know how to do it?
Here's a reproducible example:
---
title: "Untitled"
format: pdf
bibliography: refs.bib
---
```{r}
#| include: false
library(dplyr)
library(gt)
```
Here I can cite #dirac
But below I get only the literal "#dirac". If I do not include the quotation marks, the code does not compile.
```{r}
#| include: true
#| echo: false
head(mtcars) %>%
gt() %>%
tab_source_note("#dirac")
```
# References {-}
And the reference in refs.bib:
#book{dirac,
title={The Principles of Quantum Mechanics},
author={Paul Adrien Maurice Dirac},
isbn={9780198520115},
series={International series of monographs on physics},
year={1981},
publisher={Clarendon Press},
keywords = {physics}
}
Following this post you could read your bib file via bibtex::read.bib. Afterwards you could add your citation to the gt table via cite like so:
---
title: "Untitled"
format: pdf
bibliography: refs.bib
---
```{r}
#| include: false
library(dplyr)
library(gt)
library(bibtex)
```
```{r}
biblio <- bibtex::read.bib("refs.bib")
```
Here I can cite #dirac
But below I get only the literal "#dirac". If I do not include the quotation marks, the code does not compile.
```{r}
#| include: true
#| echo: false
head(mtcars) %>%
gt() %>%
tab_source_note(cite("dirac", biblio, textual = TRUE))
```
I have a .qmd / .rmd file that wants to show the output of block of code. The code block has a lot of lines at the beginning that I'd like to hide, in the example below I'd like the output to be the third line of code str(month) and output the result of str(month). I've attempted to edit the code block parameters, but it's giving me an error:
---
format:
html: default
---
```{r}
#| echo: c(3)
month <- "July"
str(month)
```
Error:
7: #| echo: c(3)
~~~
8: month <- "July"
x The value c(3) is string.
i The error happened in location echo.
rmarkdown support files suggest something like this might be possible
This does not work because you are using YAML syntax for chunk options as recommended with Quarto but #| echo: c(3) is not valid YAML. #| echo: 3 is.
You can use !expr within YAML field to parse R code if necessary. #| echo: !expr c(3) would work. It is explained here: https://quarto.org/docs/computations/r.html#chunk-options
However, know that knitr supports other way to specify chunk options:
Usual header where option needs to be valid R code
```{r, echo = c(3)}
#| echo: c(3)
month <- "July"
str(month)
```
And a multiline version of it, useful when having long option like fig.cap
```{r}
#| rmdworkflow,
#| echo = FALSE,
#| fig.cap = "A diagram illustrating how an R Markdown document
#| is converted to the final output document.",
#| out.width = "100%"
knitr::include_graphics("images/workflow.png", dpi = NA)
```
See the announced in blog post for more about this new syntax: https://yihui.org/en/2022/01/knitr-news/
This question has also been asked in Github - so more detailed answer there: https://github.com/quarto-dev/quarto-cli/issues/863
I don't know if I understood the question correctly. But you can choose to display only the code you want based on the index of the line inside specific chunk. Insert the number of index line you want to show inside the c() {r, echo = c()}
Your specific case
---
format:
html: default
---
```{r, echo = c(2)}
month <- "July"
str(month) # line 2
```
Other Example:
---
format:
html: default
---
```{r, echo = c(5,8)}
# Hide
month <- "July"
## Show code and output
str(month) # Line 5
## Show code and output
1+1 # Line 8
## Show just output
2+2
```
So I have a document where I'm trying to knit, but I get an error where it says that
Error: object 'r' not found
Execution halted
Here is my full code:
---
title: "Test"
author: "Test Test"
date: "05.15.2022"
output:
html_document:
toc: yes
toc_float: yes
editor_options:
markdown:
wrap: sentence
---
# Header
##chunks
```{r}
summary(cars)
```
```{r}
knitr::opts_chunk$set(message = FALSE,warning = FALSE, error = FALSE)
```
```{r}
sapply(cars,class)
```
Any help? I am really new to R.
When I add the following lines to add table of content to a shiny document:
toc: true
toc_float: true
The document fails to run. It runs fine without them. I get the following error:
Error Scanner error: mapping values are not allowed in this context at line 5, column 8 (line 5 is toc: true)
How can I resolve this issue?
The code I ran:
---
title: "Untitled"
runtime: shiny
output:
html_document
toc: true
toc_float: true
---
### section 1
```{r, echo=FALSE}
sliderInput("slider", "Number of observations:", 1, 100, 50)
renderText({paste0(rep('blah', 100), collapse = '\n')})
```
### section 2
```{r, echo=FALSE}
renderPlot({hist(rnorm(500)[seq_len(input$slider)])})
```
You're just missing a : from html_document. It should be html_document:
---
title: "Untitled"
runtime: shiny
output:
html_document:
toc: true
toc_float: true
---
When using bookdown (single document), if I set both section_numbering = 'yes' and fig_caption = 'yes', the figures are numbered X.2 (where X is the section number). If section_number = 'no', the figures are numbered sequentially (Fig 1, 2 ...), but sections numbers are lost.
Is there a way to get figures numbered sequentially without losing the section numbers? In the example below, I would like to have both the sections figures numbered as 1 and 2.
Thank you.
---
output:
bookdown::html_document2:
fig_caption: yes
number_sections: yes
---
# header 1
Reference example: \#ref(fig:plotcars):
```{r plotcars, fig.cap = "A car plot"}
plot(cars)
```
# header 2
Reference example: \#ref(fig:plotcars2):
```{r plotcars2, fig.cap = "A car plot"}
plot(cars)
```
I just added a new argument global_numbering to the dev version of bookdown. You can test the dev version via
remotes::install_github('rstudio/bookdown')
Example:
---
output:
bookdown::html_document2:
fig_caption: true
number_sections: true
global_numbering: true
---
# header 1
Reference example: \#ref(fig:plotcars):
```{r plotcars, fig.cap = "A car plot"}
plot(cars)
```
# header 2
Reference example: \#ref(fig:plotcars2):
```{r plotcars2, fig.cap = "A car plot"}
plot(cars)
```