davidgohel / flextable

table farming
https://ardata-fr.github.io/flextable-book/
565 stars 82 forks source link

Breakage with the latest version of knitr #621

Closed yihui closed 7 months ago

yihui commented 7 months ago

To reproduce, remotes::install_github('yihui/knitr') and run tests in flextable or do R CMD check:

  Running the tests in ‘tests/testthat.R’ failed.
  Complete output:
    > library(testthat)
    > library(flextable)
    > library(officer)
    >
    > test_check("flextable")
    [ FAIL 4 | WARN 1 | SKIP 4 | PASS 245 ]

    ══ Skipped tests (4) ═══════════════════════════════════════════════════════════
    • On CRAN (4): 'test-as_flextable.R:3:1', 'test-borders.R:3:1',
      'test-captions-rmd.R:195:3', 'test-md-captions.R:3:1'

    ══ Failed tests ════════════════════════════════════════════════════════════════
    ── Failure ('test-captions-rmd.R:72:3'): with html_document2 ───────────────────
    grepl(...) is not TRUE

    `actual`:   FALSE
    `expected`: TRUE
    ── Failure ('test-captions-rmd.R:73:3'): with html_document2 ───────────────────
    grepl("Table [0-9]+\\: azerty querty", xml_text(xml_parent(caption_id2))) is not TRUE

    `actual`:   FALSE
    `expected`: TRUE
    ── Failure ('test-captions-rmd.R:83:3'): with html_document2 ───────────────────
    inherits(id_chunk, "xml_missing") is not FALSE

    `actual`:   TRUE
    `expected`: FALSE
    ── Failure ('test-captions-rmd.R:86:3'): with html_document2 ───────────────────
    grepl("Table 2:", xml_text(caption)) is not TRUE

    `actual`:   FALSE
    `expected`: TRUE

    [ FAIL 4 | WARN 1 | SKIP 4 | PASS 245 ]
    Error: Test failures
    Execution halted

This is due to a change in knitr::raw_block(): https://github.com/yihui/knitr/commit/5435c52469af3781541ef0708bb9fcd7dced3d45#diff-60bef5af43a1bd541299ce9bceeb226afb23deaa5e637b145c85e05ffd552b0c

Previously, knitr::raw_block() always uses three backticks in the fences. Now it will look at its content first. If the content contains three backticks, it will use four in the fences. I didn't look closely into the flextable codebase, but I guess it might be easier for you to figure out a proper fix. The above tests were failing because they generated something like this:

````{=html}
HTML code
HTML code

which should have been

`````md
```{=html}
HTML code
HTML code


Thanks!
davidgohel commented 7 months ago

Hello

I believe that the problem does not appear in the dev version - work on the tests is in progress and seems to have eliminated this problem (by chance). I will double check to be sure and let you know soon.

When do you plan a submission? If I can submit before your submission, you could delete the workaround. On my side, I have to wait for the submission of a reverse dependency and then it can be done.

yihui commented 7 months ago

I plan to make a submission today. No hurry for you to release a new version. I can remove the hack on my side next time. Thank you!

yihui commented 7 months ago

I can confirm that the dev version of flextable works fine with knitr without the workaround.

github-actions[bot] commented 1 month ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.