Auto-format tables for printing in MS-Word documents

docx_tab(
  x,
  lang = c("eng", "ger")[1],
  pvalform = "p.value",
  asft = TRUE,
  digits = "round_smart",
  ...
)

Arguments

x

Table to be formatted

lang

Language for column names.

pvalform

Names of columns are that formatted via BioMathR::format_p(). Can be set to NULL. The default is "p.value", but note that this function first unifies multiple column names such as "Pr(>F)" or "P(>|Chi|)" into "p.value".

asft

If TRUE, output is formatted as flextable

digits

Number of digits all numeric columns are rounded to. The default is actually "round_smart" which applies BioMathR::round_smart() to each numeric column individually.

...

Other arguments passed to BioMathR::round_smart()

Examples

library(BioMathR)

anova <- anova(lm(weight ~ group, data = PlantGrowth))
docx_tab(anova, lang = "ger")

Term

FG

SQ

MQ

F-Wert

p-Wert

group

2

3,8

1,9

4,8

0,016*

Residuals

27

10,5

0,4

docx_tab(anova, lang = "eng", asft = FALSE) #> # A tibble: 2 × 6 #> Term df SS MS `F value` `p value` #> <chr> <int> <dbl> <dbl> <dbl> <chr> #> 1 group 2 3.8 1.9 4.8 "0.016*" #> 2 Residuals 27 10.5 0.4 NA "" before <- data.frame( V1 = c(123456, 1234), V2 = c(-123, -0.12345), V3 = c(1.0012345, 0.1), V4 = c(1.1, 0.0012345), V5 = c(1.000000012345, 0), V6 = c(NA, -5.0018), V7 = c(NA_real_, NA_real_) ) docx_tab(before)

V1

V2

V3

V4

V5

V6

V7

123,456

-123.0

1.001

1.100

1

1,234

-0.1

0.100

0.001

0

-5.002

docx_tab(before, digits = 2)

V1

V2

V3

V4

V5

V6

V7

123,456

-123.00

1.0

1.1

1

1,234

-0.12

0.1

0.0

0

-5