First, thank you for your continuous efforts in developing this package; it's excellent!
I've recently encountered a potential bug with the flextable_to_rmd function in version 0.9.6. It appears that local Rmarkdown chunk options are ignored by this function, leading to potential issues. This wasn't a problem before 0.9.6.
See a minimal reproducible example below where that issue causes the table not to be displayed because the local eval option is ignored.
---
output: html_document
---
```{r}
library(flextable)
ft <- flextable(head(iris))
Section 1 - It works
# Set global `eval` to `TRUE`
knitr::opts_chunk$set(eval = TRUE)
# This works as expected
flextable_to_rmd(ft)
Section 2 - It does not work
# Set global `eval` to `FALSE`
knitr::opts_chunk$set(eval = FALSE)
message("Current eval: ", knitr::opts_current$get("eval")) # TRUE
message("Global eval: ", knitr::opts_chunk$get("eval")) # FALSE
# This won't print anything although the `eval` is set to `TRUE` in this chunk
flextable_to_rmd(ft)
I suspect the issue stems from how `flextable_to_rmd` handles chunk options, possibly around lines 100-105 in the source code, where it might not properly account for local settings over global defaults. Ideally, it would respect the local chunk options setting even when the global option is set differently. Currently, the `echo` option is hardcoded to `FALSE`, which seems appropriate; however, other relevant options should also be considered and passed accordingly.
```r
writeLines(
c("```{r echo=FALSE}",
"x", "```", ""),
tmp_file,
useBytes = TRUE)
I believe it would be beneficial if the chunk containing the flextable object could inherit the local chunk options in which it is executed. Perhaps, extracting these options from the current chunk with knitr::opts_chunk$get(...)or an equivalent method might resolve the issue. While it may not be necessary to pass all chunk options to the child chunk, the eval option at least should be considered.
I am including my sessionInfo() output as advised, to provide details on my R environment and package versions.
I have checked both open and closed issues and updated to the latest package version to ensure this issue is not already addressed.
Thank you for looking into this, and I appreciate any guidance or corrections if my understanding is incorrect.
Hi!
First, thank you for your continuous efforts in developing this package; it's excellent!
I've recently encountered a potential bug with the
flextable_to_rmd function
in version0.9.6
. It appears that local Rmarkdown chunk options are ignored by this function, leading to potential issues. This wasn't a problem before0.9.6
.See a minimal reproducible example below where that issue causes the table not to be displayed because the local
eval
option is ignored.Section 1 - It works
Section 2 - It does not work
I believe it would be beneficial if the chunk containing the flextable object could inherit the local chunk options in which it is executed. Perhaps, extracting these options from the current chunk with
knitr::opts_chunk$get(...)
or an equivalent method might resolve the issue. While it may not be necessary to pass all chunk options to the child chunk, the eval option at least should be considered.I am including my
sessionInfo()
output as advised, to provide details on my R environment and package versions.I have checked both open and closed issues and updated to the latest package version to ensure this issue is not already addressed.
Thank you for looking into this, and I appreciate any guidance or corrections if my understanding is incorrect.