Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apa_num() options specified in apa_print() don't apply to the whole the output #525

Open
jakub-jedrusiak opened this issue Apr 22, 2022 · 1 comment

Comments

@jakub-jedrusiak
Copy link

jakub-jedrusiak commented Apr 22, 2022

Describe the bug
apa_num() options specified in apa_print(), like decimal.mark and gt1, don't apply to the whole the output, especially to the p-values.

To Reproduce

library(papaja)
model <- lm(Sepal.Length ~ Species, data = iris)
anova(model) |> apa_print(decimal.mark = ",", gt1 = TRUE)

Output

$estimate
$estimate$Species
[1] "$\\hat{\\eta}^2_G = 0,401$, 90\\% CI $[0,300, 0,485]$"


$statistic
$statistic$Species
[1] "$F(2, 147) = 49.16$, $p < .001$"


$full_result
$full_result$Species
[1] "$F(2, 147) = 49.16$, $p < .001$, $\\hat{\\eta}^2_G = 0,401$, 90\\% CI $[0,300, 0,485]$"


$table
A data.frame with 7 labelled columns:

     term estimate       conf.int statistic df df.residual p.value
1 Species    0,401 [0,300, 0,485]     49.16  2         147  < .001

Expected behavior
I want all leading zeros to be displayed and all decimal marks changed to a comma which isn't the case with e.g. p-values and F-ratios but works well in other parts of the output.

Additional context
Makes apa_print() nonadjustable for different languages' implementations of the APA style.

@crsh
Copy link
Owner

crsh commented Apr 25, 2022

Hi Jakub, thanks for raising the issue and providing an example. This is related to #506.

In some sense, this is beyond the scope of papaja and so there is currently no good way to adjust the type setting of all statistics. We support changes to the estimates because their typesetting depends on the outcome variable (e.g., leading zero, number of digits). That said, there is a mid- to long-term aim of abstracting the typesetting away and allowing users to specify their own reporting style. I should note, though, that there are several other big milestones with higher priority.

It is, however, straight forward to do what you need with a little bit of regex and knowledge of papaja internals:

adjust_reporting_style <- function(x) {
  stopifnot(inherits(x, "apa_results"))
  
  x$table |> 
    dplyr::mutate(
      statistic = gsub("\\.", ",", statistic)
      , p.value = gsub("\\.", "0,", p.value)
    ) |> 
    (\(x) {
      glue_apa_results(
        x
        , est_glue = papaja:::construct_glue(x, "estimate")
        , stat_glue = papaja:::construct_glue(x, "statistic")
      )
    })()
}


my_print <- function(...) {
  papaja::apa_print(...) |> 
    adjust_reporting_style()
}

anova(model) |> 
  my_print(decimal.mark = ",", gt1 = TRUE)

See the vignette extending_apa_print for some additional information (vignette("extending_apa_print", package = "papaja"), note that you need to set build_vignettes = TRUE when installing papaja).

This may also be of interest to @JeffreyRStevens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants