Rnotebook not showing code output for data frames

生来就可爱ヽ(ⅴ<●) 提交于 2021-01-28 03:16:29

问题


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.


回答1:


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
 ---



回答2:


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



来源:https://stackoverflow.com/questions/47854646/rnotebook-not-showing-code-output-for-data-frames

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!