noamross / redoc

[NOTE: Project in suspended animation for now] Reversible Reproducible Documents
https://noamross.github.io/redoc
Other
514 stars 44 forks source link

Flextables output doesn't appear without chunk option echo = TRUE #60

Open thealk opened 4 years ago

thealk commented 4 years ago

flextable() output appears to only show up in resulting .docx outputs if the chunk option is set to echo = TRUE. This is problematic for any sort of writing projects where the code needs to be hidden (e.g., scientific manuscripts). The same code renders acceptably using word_document. The flextable package is extremely useful for use with .docx outputs/collaborators and plays nice with the captioner package for cross-referencing in lieu of using bookdown::word_document2, so would be wonderful if supported (it may be supported already and I am just missing something).

Rmarkdown code

---
title: "Testing flextable behavior in redoc"
output:
  redoc::redoc: default
  word_document: default
---

`​``{r setup​} library(flextable) ```

## Test

The following table won't show up in redoc:

```{r echoF, echo=FALSE} flextable(head(cars)) ```

But the next table will:

```{r echoT, echo=TRUE} flextable(tail(cars)) ```

Output

rendered_redoc.docx rendered_word_document.docx

Please take a moment and consider if the issue is actually in **knitr**, **rmarkdown**, **officer** or **pandoc**. Thanks! -->
Session Info ```r R version 3.6.0 (2019-04-26) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 16.04.6 LTS Matrix products: default BLAS: /usr/lib/atlas-base/atlas/libblas.so.3.0 LAPACK: /usr/lib/atlas-base/atlas/liblapack.so.3.0 locale: [1] LC_CTYPE=C.UTF-8 LC_NUMERIC=C [3] LC_TIME=C.UTF-8 LC_COLLATE=C.UTF-8 [5] LC_MONETARY=C.UTF-8 LC_MESSAGES=C.UTF-8 [7] LC_PAPER=C.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets [6] methods base loaded via a namespace (and not attached): [1] zip_2.0.4 Rcpp_1.0.3 compiler_3.6.0 [4] base64enc_0.1-3 prettyunits_1.0.2 redoc_0.1.0.9000 [7] remotes_2.1.0 tools_3.6.0 uuid_0.1-2 [10] testthat_2.3.1 digest_0.6.23 pkgbuild_1.0.6 [13] pkgload_1.0.2 jsonlite_1.6 evaluate_0.14 [16] memoise_1.1.0 rlang_0.4.2 whoami_1.3.0 [19] cli_2.0.0 rstudioapi_0.10 diffobj_0.2.3 [22] curl_4.3 yaml_2.2.0 xfun_0.11 [25] httr_1.4.1 officer_0.3.6 withr_2.1.2 [28] knitr_1.26 xml2_1.2.2 desc_1.2.0 [31] fs_1.3.1 devtools_2.2.1 rprojroot_1.3-2 [34] glue_1.3.1 R6_2.4.1 processx_3.4.1 [37] fansi_0.4.0 rmarkdown_2.0 sessioninfo_1.1.1 [40] callr_3.4.0 magrittr_1.5 backports_1.1.5 [43] ps_1.3.0 ellipsis_0.3.0 htmltools_0.4.0 [46] usethis_1.5.1 assertthat_0.2.1 mime_0.8 [49] stringi_1.4.3 crayon_1.3.4 ``` Pandoc version (get with rmarkdown::pandoc_version): 2.3.1 RStudio version (if applicable): Test on RStudio Cloud and on RStudio V 1.2.1335
fcecinati commented 3 years ago

Same problem, following

albert-ying commented 2 years ago

I get it work by using inline code to print the table

library(magrittr)
library(flextable)

tab_1_curr <- structure(list(myRegion = c("a", "b", "c", "BRITISH COLUMBIA"
 ), Current_Perc_1 = c(85.9, 90.8, 89.7, 88.4), Current_Perc_2 = c(88, 
 91, 89, 89.3), curr_change_1_to_2 = c(2.09999999999999, 0.200000000000003, 
 -0.700000000000003, 0.9)), .Names = c("myRegion", "Current_Perc_1", 
 "Current_Perc_2", "curr_change_1_to_2"), row.names = c(NA, 4L
 ), class = "data.frame")

rt = regulartable(tab_1_curr) %>% 
  bold(i = ~ myRegion %in% "BRITISH COLUMBIA") %>% 
  theme_zebra() %>% 
  autofit()

`r rt`