Table won't be displayed with head() in R Notebook

372 Views Asked by At

Code entered into R Notedbook:

Code:

---
title: "test"
output: html_notebook
---
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_knit$set(root.dir=WORKING.DIRECTORY)
summary(cars)
head(cars)

Output: Output produced by code above

2

There are 2 best solutions below

0
On

Make sure you actually run the code chunks you want to see displayed and save the file:


I've also set root.dir to the result of getwd(). This doesn't change the result as far as displaying the tables, but here is the whole file for reference:

---
title: "test"
output: html_notebook
editor_options: 
  chunk_output_type: inline
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_knit$set(root.dir=getwd())
``` 
```{r}
summary(cars)
head(cars)
```
0
On

Try using getwd() instead of WORKING.DIRECTORY.

``` r{r setup, include=FALSE}

knitr::opts_chunk$set(echo = TRUE)
knitr::opts_knit$set(root.dir=getwd())

```

Generate new code chunk:

The keyboard shortcut to do this is Ctrl + Alt + I (OS X: Cmd + Option + I)

```{r}

summary(cars)
head(cars)

```

Output:

#>      speed           dist       
#>  Min.   : 4.0   Min.   :  2.00  
#>  1st Qu.:12.0   1st Qu.: 26.00  
#>  Median :15.0   Median : 36.00  
#>  Mean   :15.4   Mean   : 42.98  
#>  3rd Qu.:19.0   3rd Qu.: 56.00  
#>  Max.   :25.0   Max.   :120.00


#>   speed dist
#> 1     4    2
#> 2     4   10
#> 3     7    4
#> 4     7   22
#> 5     8   16
#> 6     9   10

Created on 2020-07-25 by the reprex package (v0.3.0)