global option in Rnotebook doesn't work

I am using Rnotebook a lot as a basis for my analysis.
Because my package is using default r plot,
I want to make a default option for all chunks as follows:

knitr::opts_chunk$set(global.par = TRUE)
par(pty="s")

However, this doesn't work in Rnotebook.
Do you have any ideas?

When you say Rnotebook, are you talking about a Rmd file with html_notebook as format ?
Or another format ?

It should be knitr::opts_knit$set as this options is a package option not a chunk option. see

This works

---
title: My Document
output: html_document
---

```{r}
knitr::opts_knit$set(global.par = TRUE)
```

```{r}
par()$pty
```

```{r}
par(pty="s")
```

```{r}
par()$pty
```

Thanks for your kind reply.

It works if I set html_document, however it doesn’t work when html_notebook.

Because there are little information of Rnotebook, I guess Rmarkdown option will be applied as well.

Please check this.

---
title: My Document
output: html_notebook
---

```{r}
knitr::opts_knit$set(global.par = TRUE)
```

```{r}
par()$pty
```

```{r}
par(pty="s")
```

```{r}
par()$pty
```

Notebook are a bit different. Best you can find as information are

They are completly tied to the IDE and compare to other format, the document is not really knitted.
The Notebook format allow you to run chunks in the IDE and preview the document at the same time. The notebook is not "Knit" but preview, that means a html document containing the text and the evaluated chunks (in a new notebook document with no evaluated chunk yet, if you preview you only have the code chunk without result)

However, I don't think currently a rendering of the document using knitr is happening. So the knitr option is not taken into account.

Try to run the document above chunk by chunk and you'll see the options is not taken into account. I believe this is not yet supported by rstudio.

This could be something to improve in the IDE.

Thank you very much for the useful information. As a user of Rnotebook, I hope this feature will be applied to Rstudio IDE next time.

You could open a feature request in RStudio repo if there is none yet.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.