Search code examples
rknitrr-markdownrnotebook

Rnotebook not showing code output for data frames


My code chunk output in Rnotebook is not appearing (as if not being run) when I try to view data frame results. I have to pass it through the pander() function to see the output print out. Is this something to do with knitr? I mention this because I set the options at the beginning to the following:

```{r setup, include = FALSE}
knitr::opts_chunk$set(echo = TRUE, eval = TRUE)
```

I have tried setting the options directly in the chunk but get the same unwanted result. Is there a setting I am not configuring correctly? I have to also mention that this is a behaviour that has been somehow inconsistent. That is, I may stop working on it and some time later the code output comes up somehow.

Here's an sample of the work code I am trying to run to copy paste into Rnotebook.

Setting the notebook workspace options

```{r setup, include = FALSE}
knitr::opts_chunk$set(echo = TRUE, eval = TRUE)
```

Loading the corresponding libraries and packages

```{r}
library(easypackages)
libraries("dplyr",
          "ggplot2",
          "caret",
          "tidyverse",
          "tidytext",
          "ROCR",
          "pander",
          "knitr",
          "broom")
```

Here's some sample data:

```{r}
library(readr)
attibm <- read_csv("https://raw.githubusercontent.com/vincentarelbundock/Rdatasets/master/csv/datasets/mtcars.csv", 
    col_types = cols(Attrition = col_character()))
```

Seeing the structure. (This output is shown as expected)

```{r}
glimpse(attibm)
```

Output expected

Preview the first ten rows (this is the output that doesn't show. Nothing happens)

```{r}
head(attibm)
```

This output doesn't show either. (Nothing happens)

```{r}
attibm %>% 
  summarise_if(is.integer, mean)
```

When I pass the pander function THEN it is shown.

```{r}
attibm %>% 
  summarise_if(is.integer, mean) %>% 
  pander()
```

Output shown using pander 1

This one is shown too

```{r}
pander(head(attibm))
```

Output shown using pander 2

I have checked the question posted: Output of numbers in R notebook, but I wasn't able to see the connection with this case.

I hope this is clear enough and that you can reproduce the code shown here. Any help on this issue will be highly appreciated.


Solution

  • The newest version of markdown is no longer compatible with pandocv2. You can check your version of pandoc using

    library(rmarkdown); pandoc_version()
    

    If it's pandoc version you need the development version of markdown that you can download there

    library(devtools); install_github("rstudio/rmarkdown")
    

    To narrow down the issue of whether this is a problem with the newest version of pandoc, try checking wether the .md produced is correct by adding

     ---
     output:  
      html_notebook 
        keep_md: true
     ---