I have been trying to add a flextable created via rtable::FlexPivot into a word document using officer.
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)
This returns an error message saying
Error in UseMethod("docx_str") : no applicable method for 'docx_str' applied to an object of class "FlexTable"
Any idea what might be causing this? I am using pandoc 2.1.3. pandoc_version() returns '2.1.3'.
rtable
is designed to work with ReporteRs
not with officer
. Note that package ReporteRs will be removed from CRAN the 16th of July 2018 (due to incompatibility with java >=9), package officer
is replacing ReporteRs
and package flextable
is replacing ReporteRs::FlexTable
objects.