3

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.

Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
ogorodriguez
  • 103
  • 3
  • 9
  • I have also found this thread https://stackoverflow.com/questions/47839559/running-code-chunks-in-r-knitr-package, but in my case I don't recieve error messages so I have no Traceback error log to provide. – ogorodriguez Dec 17 '17 at 12:10
  • Hi, I've tested your code with markdown + development version of rmarkdown + pandocv2 (I had to update rmarkdown from the development github page as it is no longer compatible with pandoc v2). Anyway it produces all results fine. Try saving the intermediate md file and see what's going on. By the way you posted easypackage in your example, thanks I didn't know that ! – Cedric Dec 17 '17 at 14:18
  • Thanks @Cedric, for this pointer. I have reinstalled rmarkdown following the instance install.packages("rmarkdown") since I could not find where to get the development version. I have also downloaded the newest version of pandoc from [here](https://github.com/jgm/pandoc/releases/tag/2.0.5) Yet nothing has changed. Can you tell me where you got the versions you mentioned and how you went about installing them (using devtools?). It is nice to know you also find the easypackages package handy. – ogorodriguez Dec 17 '17 at 17:46
  • I've found that the newest versions of pandoc don't play well with [rmarkdown]((https://yihui.name/en/2017/11/pandoc-2/). You can install the dev version by `devtools::install_github('rstudio/rmarkdown')`. – dshkol Dec 17 '17 at 20:15
  • To install the development version `library(devtools) install_github("rstudio/rmarkdown")`. I'm not saying that you should do this, only if you have the latest version of pandoc which you can get by `require(rmarkdown) ;pandoc_version()`. If you have version 2, which I downloaded on my computer then you need the development version of rmarkdown. @dshkol your message came as I was typing so we say the same ! – Cedric Dec 17 '17 at 20:16
  • The issue with pandocv2 is described [here](https://github.com/rstudio/rmarkdown/issues/1185) – Cedric Dec 17 '17 at 20:22
  • @ogorodriguez did you look at your intermediary file output by adding one line to the yaml header ? When knitting, the output tells you where the md is : `output: html_notebook keep_md: yes` this will narrow down the issue, as to whether this is a problem with pandoc (in which case your md will be fine) or before. – Cedric Dec 17 '17 at 20:24
  • https://stackoverflow.com/questions/24292909/new-r-studio-version-0-98-932-deletes-md-file-how-to-prevent – Cedric Dec 17 '17 at 20:31
  • Thanks @yihuixie for the edit! – ogorodriguez Dec 18 '17 at 11:02
  • Having checked on my side I can tell it has resolved the issue @Cedric please make this an answer so I can mark it as the answer. Thanks a lot to all for your help. – ogorodriguez Jan 20 '18 at 07:20

2 Answers2

3

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
 ---
Cedric
  • 2,412
  • 17
  • 31
  • Hi @Cedric, this indeed helped but also the indication you gave about the yaml header. Could you please update the answer to include this? Thanks again. – ogorodriguez Jan 21 '18 at 19:49
1

I had a similar problem which data.frame and DT:data.table wouldn't show any output.
this post helped me. I found that the cause of problem was my mis-typing in .rmd file name including a non-ASCII character! as soon as i removed it the problem resolved. Hope this helps others too

asalimih
  • 298
  • 2
  • 8