0
votes

I am using RStudio 1.0.44 and I when I run a code chunk in an RMarkdown document, the ouptut looks great but when knit to html or pdf it looks like plain old R console output.

Why the difference?

Example:

library(datasets)
library(dplyr)
data <- ToothGrowth

data %>%
   group_by(supp, dose) %>%
   summarise(n=(), mean=mean(len), sd=sd(len))

R Markdown:

```{r}
library(datasets)
library(dplyr)
data <- ToothGrowth

data %>%
  group_by(supp, dose) %>%
  summarise(n=n(), mean=mean(len), sd=sd(len))
```

In RStudio: RStudio chunk

In HTML and PDF: HTML and PDF output

1
Rmarkdown code would give a better idea.R.S.
Updated question, Thank you!Monduiz
works fine for me.. maybe check the settings (next to knittr menu in RStudio) and check that the setting for HTML is set to use default theme.R.S.
The source code for the generated html file will have all the css embedded as style tags at the top .R.S.
you can use knitr::kable() to format dataframesRichard Telford

1 Answers

0
votes

You are wanting "pretty" datatables printed in a similar manner that they are displayed inside an Rmd file. I do not know how to produce an exact replication of that output inside an HTML format.

I do know how to produce a similar output in an HTML document. You need the DT package which itself uses htmlwidgets as a dependency.

Once you've added the library to your document use the following call inside a chunk:

DT::datatable(data)

This will give you an interactive table in your HTML output.

This will not work in PDF documents because the libraries require the use of javascript. This is noted in Yihui Xie's documentation of bookdown. If you must use PDF you will need to fallback on a standard output.