C8H10N4O2
C8H10N4O2

Reputation: 19005

Rstudio is changing my default R Notebook output

I start with a new R Notebook in RStudio:

---
title: "R Notebook"
output: html_notebook
---

This is an [R Markdown](http://rmarkdown.rstudio.com) Notebook. Etc Etc Etc.

Then I modify it to do what I want -- for example, I'm trying to use microbenchmark().

---
title: "R Notebook"
output: html_notebook
---

Let's compare the sort methods on a set of shuffled integers.

```{r}
library(microbenchmark)
n <- 100000L
microbenchmark(
  sort(sample.int(n),method='radix'),
  sort(sample.int(n),method='quick'),
  sort(sample.int(n),method='shell')
)
```

Submitting this microbenchmark() to the console gives sensible output, like:

Unit: milliseconds
                                  expr       min        lq      mean    median        uq       max neval cld
 sort(sample.int(n), method = "radix")  4.685707  4.914925  6.559412  5.619257  7.539383  16.66746   100 a  
 sort(sample.int(n), method = "quick")  8.169732  8.534512 10.490920  9.333782 11.008653  21.44854   100  b 
 sort(sample.int(n), method = "shell") 10.766820 11.144858 15.479061 12.408976 14.519405 133.87898   100   c

However, when I try to knit it (click the drop-down from "Preview" to "Knit to HTML", it automatically changes my header to:

---
title: "R Notebook"
output:
  html_document:
    df_print: paged
---

Which really messes up the output -- now it looks like this:

enter image description here

If I go back and change the header back to output: html_notebook and click the "Knit" button again, now it looks right:

enter image description here

Is there a way to prevent RStudio from messing up my first knit?

I'm on RStudio Version 1.1.419 for Windows.

Upvotes: 2

Views: 707

Answers (1)

user2554330
user2554330

Reputation: 44808

There are two changes happening. First, your html_notebook format is being changed to html_document:. Second, the df_print option is being added.

Basically the first of these is what Knit to HTML is asking for. html_document and html_notebook are different formats, and you're asking to change formats.

Once you're in html_document format, you probably want df_print: default instead of df_print: paged. Or you can just leave out the option.

As far as I can see, there's no way to ask for this, other than changing the source of RStudio (around line 118 in this file: https://github.com/rstudio/rstudio/blob/8af730409bb6d651cc8f6816d136bea91441e7a4/src/gwt/src/org/rstudio/studio/client/rmarkdown/model/RmdTemplateData.java).
That's not very practical for most people.

Of course, after you've got the html_document output format chosen, you can change the option (or just delete it).

Upvotes: 2

Related Questions