1

According to the description, apa_table takes arguments from knitr::kable. But when I want to use a functionality from kableExtra (in my example, format entries in the second column as bold), I get an error message.

library(tidyverse)
library(papaja)
library(kableExtra)
#> 
#> Attaching package: 'kableExtra'
#> The following object is masked from 'package:dplyr':
#> 
#>     group_rows

holiday_schedule <- tibble(
  day1 = c("surfing", "siesta", "cocktails"),
  day2 = c("beach", "walk", "restaurant")
)

apa_table(holiday_schedule,
          format = "latex") %>%
  column_spec(2, bold = TRUE)
#> Error in if (!kable_format %in% c("html", "latex")) {: argument is of length zero

Created on 2021-09-23 by the reprex package (v2.0.0)

It is like setting the format (in format = "latex") was not taken into account. How can I go about this?

raphael_ldl
  • 113
  • 8

1 Answers1

3

The output object from apa_table() does not have the "format" attribute set, which is why column_spec() from the kableExtra package cannot recognize the output. A workaround is to manually set the attribute. For your simple example, this would look like:

apa_table(holiday_schedule,
          format = "latex") %>%
          `attr<-`("format", "latex") %>%
  column_spec(2, bold = TRUE)

However, note that apa_table() can produce more-complex output that deviates from what knitr::kable() produces; I assume that kableExtra will eventually break sooner or later.

Marius Barth
  • 596
  • 2
  • 9