agentsclimarketplace

R flextable

Skill arthurgailes/r-package-skills/skills/r-flextable

Use when code loads or uses flextable (library(flextable), flextable::), creating formatted tables for Word (.docx), PowerPoint (.pptx), HTML, or PDF in R, or needing merged cells and conditional formattingFrom its SKILL.md

Install
npx -y skills add arthurgailes/r-package-skills --skill r-flextable

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

2 things to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
  • 23 stars23 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

3.3 KB, as published. Nobody here has run it

R flextable

Overview

flextable creates publication-quality tables that render consistently across Word, PowerPoint, HTML, and PDF.

Core principle: Separate data from display. Build from a data.frame, then layer formatting declaratively using selectors.

References

Read references/API.md before writing code.

  • references/API.md - Complete function reference
  • references/overview.md - Core concepts and workflow
  • references/formatting.md - Styling and appearance
  • references/layout.md - Structure and merging
  • references/selectors.md - Targeting cells for formatting
  • references/output.md - Rendering to different formats

When to Use

Use flextable when:

  • Output to Word/PowerPoint required
  • Need cell merging, conditional formatting, mini charts
  • Cross-references and auto-numbered captions
  • Same table across multiple formats

Consider alternatives:

  • HTML-only: gt or reactable
  • LaTeX-heavy: kableExtra
  • Interactive dashboards: DT

Quick Reference

TaskFunction
Create tableflextable(df)
Format numberscolformat_double(), colformat_int()
Bold/italic/colorbold(), italic(), color()
Background colorbg()
Merge cellsmerge_v(), merge_h(), merge_at()
Add headeradd_header_row()
Auto-sizeautofit()
Apply themetheme_vanilla(), theme_zebra()
Save to Wordsave_as_docx()
Save to PowerPointsave_as_pptx()

Core Pattern

library(flextable)

# Create -> format -> output
ft <- flextable(head(mtcars, 5)) |>
  colformat_double(digits = 1) |>
  # Conditional formatting with formula selectors
  color(i = ~ mpg > 20, j = "mpg", color = "darkgreen") |>
  bold(i = ~ mpg > 20, j = "mpg") |>
  # Spanning header
  add_header_row(
    values = c("Performance", "Engine", "Transmission"),
    colwidths = c(2, 4, 5)
  ) |>
  theme_vanilla() |>
  autofit()

save_as_docx(ft, path = "table.docx")

Selectors (Key Concept)

Target cells for formatting:

# Row selector (formula)
bold(ft, i = ~ cyl == 6)

# Column selector
bg(ft, j = ~ mpg + hp, bg = "lightgray")

# Part selector
bold(ft, part = "header")

See references/selectors.md for details on multi-content cells, mini charts, output-specific notes.

Common Mistakes

MistakeFix
Theme doesn't format new headerApply theme AFTER add_header_row()
autofit() overflows marginsUse set_table_properties(layout = "autofit")
height() has no effectSet hrule(rule = "exact") first
Formula selectors fail in headerUse integer indices for header rows
Images missing in WordUse officedown::rdocx_document()
PDF ignores paddingUse ft.tabcolsep chunk option
add_header_row values wrongOne value per span; colwidths sum to ncol

Advanced

See references/ for:

  • API.md: Complete function reference (240+ functions)
  • selectors.md: Multi-content cells, mini charts, output-specific notes
  • formatting.md: All formatting functions and options
  • layout.md: Merging, sizing, headers/footers
  • output.md: Rendering to all formats

Keep looking

Skills are one crate of 613,297. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.