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

Pad p-values with space at beginning so decimal aligns #36

Open
szimmer opened this issue Mar 21, 2024 · 0 comments
Open

Pad p-values with space at beginning so decimal aligns #36

szimmer opened this issue Mar 21, 2024 · 0 comments
Labels
feature a feature request or enhancement

Comments

@szimmer
Copy link

szimmer commented Mar 21, 2024

When using the function pretty_p_value(), I'd like the resulting character to be aligned at the decimal point for nicer usage when printing tibbles or using gt() or kable() to print tables. Example of what I'd like this to look like (not implementation) is displayed in ps_f_alt below:

# remotes::install_github("r-lib/prettyunits")

library(prettyunits)
library(tibble)

ps <- c(1, 0, NA, 0.01, 0.0000001)
ps_format <- pretty_p_value(ps, minval = .05)
ps_format_2 <- stringr::str_pad(ps_format, 5)

pdf <- data.frame(ps=ps, ps_f=ps_format, ps_f_alt=ps_format_2)
ptib <- as_tibble(pdf)

pdf
#>      ps  ps_f ps_f_alt
#> 1 1e+00  1.00     1.00
#> 2 0e+00 <0.05    <0.05
#> 3    NA  <NA>     <NA>
#> 4 1e-02 <0.05    <0.05
#> 5 1e-07 <0.05    <0.05
ptib
#> # A tibble: 5 × 3
#>           ps ps_f  ps_f_alt
#>        <dbl> <chr> <chr>   
#> 1  1         1.00  " 1.00" 
#> 2  0         <0.05 "<0.05" 
#> 3 NA         <NA>   <NA>   
#> 4  0.01      <0.05 "<0.05" 
#> 5  0.0000001 <0.05 "<0.05"

Created on 2024-03-20 with reprex v2.0.2

@gaborcsardi gaborcsardi added the feature a feature request or enhancement label Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants