add_forest() flextable overflows the page in docx output
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 76/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- r
- Domain
- data-visualization
Research direction
Start in the flextable branch of add_forest() and reproduce the reported .docx output using the example in the issue. Check that the table reflows within the page, the forest plots remain 2.5in x 0.4in, and all images are packaged correctly.
Written by the indexing model from the issue text.
Description
Description
add_forest(table_engine = "flextable") produces a flextable that is wider than the page and uses a fixed table layout, so when the table is saved to .docx Word renders the exact column widths and the table spills off the right edge. The forest plots become unreadable.
The images themselves are sized correctly (the ggplot column is 2.5in x 0.4in). The problem is the overall table width combined with the fixed layout.
Reproduction
library(crane)
library(gtsummary)
set.seed(1)
ft <- trial |>
tbl_roche_subgroups(
rsp = "response", by = "trt", subgroups = c("grade", "stage"),
~ glm(response ~ trt, data = .x) |>
tbl_regression(show_single_row = trt, exponentiate = TRUE)
) |>
add_forest(pvalue = starts_with("p.value"), table_engine = "flextable")
# saved to docx the table is ~11.8in wide on a 6.5in usable page
Measured on the rendered .docx:
| Measure | Value |
|---|---|
| Table width | 11.79 in |
| Usable page width (Letter, 1in margins) | 6.5 in |
| Overflow | +5.29 in (181% of the page) |
| Table layout | fixed |
as_flex_table() already returns a fixed layout, and add_forest() keeps it fixed while widening the table, so Word cannot reflow it.
Proposed fix
Set layout = "autofit" at the end of the flextable branch of add_forest() so Word reflows the table to the page width. Verified: with autofit the table reflows, the plots stay at 2.5in x 0.4in, and all images package correctly.
Related
Related to #150 (fixed vs autofit layout for flextable). This issue is the concrete forest-plot symptom of that discussion.
- Dominant language
- R
- Stars
- 15
- Forks
- 7
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 3
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from insightsengineering/crane
-
Difficulty 1/5 1-3 hours Newbie friendliness 78/100
insightsengineering/crane#316 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
insightsengineering/crane#309 ·
-
Inexplicit error message when `by` variable and `include` variable is same in `tbl_roche_summary()` Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
insightsengineering/crane#290 · 4 comments ·
-
Difficulty 1/5 Under an hour Newbie friendliness 62/100
insightsengineering/crane#247 · 1 comment ·
-
[Release]: 0.4.0 Openrelease
insightsengineering/crane#319 · 1 assignee ·
All issues in insightsengineering/crane
Similar issues
-
documentation pkg infrastructure
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
epiverse-trace/epiparameter#511 ·
-
function:write_dwc
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
r-lib/pkgdepends#485 · 3 comments ·
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
beginners blocker
Difficulty 2/5 1-3 hours Newbie friendliness 78/100