【问题标题】:RMarkdown plot doesn't show in final knit outputRMarkdown 图未显示在最终针织输出中
【发布时间】:2021-07-02 02:02:35
【问题描述】:

我正在使用 RMarkdown 并使用 gt 包创建报告。在我编写文档之前,图形输出显示了 2 个部分:“R Console”和“shiny.tag.list”。虽然“shiny.tag.list”有表格,但 R 控制台是我编织文档后出现的内容,“min 没有非缺失参数;将 Infno 非缺失参数返回给 max;返回 -Inf”。我如何让它显示表格?有没有办法解决 R 控制台 cmets,使其不会出现?

附言。针织输出在 Microsoft Word 中。

gt_tbl <- 
    df_tbl %>% 
    gt(rowname_col="date")

# removes date so you can add a line alignment for that column
  
gt_tbl <- 
    gt_tbl %>% 
    tab_stubhead(label="date")
# adds the line alignment + new label for column you just took out name for  

 gt_tbl <- 
   gt_tbl %>% 
   tab_header(
     title=md("**Weekly Screener Report**"),
     subtitle= {current_range}) %>% 
   tab_style(
     style=list(
       cell_fill(color="light blue"),
       cell_text(weight="bold")
     ),
     locations = cells_body(
       columns=vars(week_total)
     )
   )
# md("**text**") bolds "text"
 # tab_style() adds color where you want it, can be done to rows as well
 # tab_header is for title and subtitle
 
  
# Create 2 row groups w/ 'tab_row_group()' function
 # Group the rows in opposite order you want to see it in
gt_tbl <- 
  gt_tbl %>% 
    tab_row_group(
      group="current",
      rows= 5:8  
  ) %>% 
  
    tab_row_group(
      group="former",
      rows= 1:4
  )

# view table
gt_tbl

before_knit_rconsole

before_knit_plot

after_knit_output

【问题讨论】:

  • 一个可重复的例子可以帮助你更好地理解你的问题

标签: r r-markdown


【解决方案1】:

我可以重现错误。

但首先,您在输出中看到的是警告。您可以通过如下设置块的标头来摆脱这些:

{r, warning=FALSE}

一个可重现的例子:

---                                                                                         
title: "test"                                                                               
output: word_document                                                                       
---                                                                                         
                                                                                            
```{r setup, include=FALSE}                                                                 
knitr::opts_chunk$set(echo = TRUE)                                                          
library(gt)                                                                                 
```                                                                                         
                                                                                            
                                                                                            
```{r, warning=FALSE}                                                                       
gt_tbl <-                                                                                   
  gt::gtcars                                                                                
                                                                                            
gt_tbl %>% gt(rowname_col = "mfr")                                                          
```    

当我运行此代码时,我没有在 .docx 中打印出表格。如果我更改为pdf_document,表格就会出现。

快速搜索表明不支持 word 输出 (https://www.danieldsjoberg.com/gtsummary/articles/rmarkdown.html)。但我可能错了。

【讨论】:

  • 非常感谢 MKR,这有助于了解 gt() 绘图不适用于 word。我还看到您添加了 Rmarkdown 标头来禁止警告,我肯定会使用它。有没有办法将 AND {r pressure, echo=FALSE} 用于绘图输出?
  • 是的,您基本上可以添加尽可能多的可用选项:{r, echo=FALSE, warning=FALSE} 等。
猜你喜欢
  • 1970-01-01
  • 2020-11-24
  • 2017-01-05
  • 2020-04-26
  • 1970-01-01
  • 1970-01-01
  • 2017-03-19
  • 1970-01-01
  • 2013-11-23
相关资源
最近更新 更多