我一直在尝试将通过 rtable::FlexPivot 创建的弹性表添加到使用officer 的word 文档中。
library(magrittr)
library(rtable)
library(officer)
library(flextable)
data = mtcars
data = group_by(data, vs, am, gear, carb)
data = summarise(data, avg = mean( mpg ), min = min( mpg ))
data$avg_col = ifelse( data$avg < 17, "red", "black" )
data$min_col = ifelse( data$min < 20, "gray", "purple" )
data$avg = sprintf( "%.3f", data$avg)
data$min = sprintf( "%.2f", data$min)
ft = FlexPivot( dataset = data, space = FALSE, columns.transpose = TRUE,
id = c("gear", "carb"), transpose = c("vs", "am"),
columns = c("avg", "min"),
color = c("avg"="avg_col", "min" = "min_col") )
my_doc <- read_docx() %>%
body_add_par(value='Some text etc etc') %>%
body_add_flextable(value=ft)
这会返回一条错误消息说
UseMethod(“docx_str”)中的错误:没有适用于“docx_str”的方法应用于“FlexTable”类的对象
知道可能是什么原因造成的吗?我正在使用 pandoc 2.1.3。pandoc_version() 返回“2.1.3”。