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

gt_merge_stack() and NA #132

Open
andrew-griffen opened this issue Jul 8, 2024 · 0 comments
Open

gt_merge_stack() and NA #132

andrew-griffen opened this issue Jul 8, 2024 · 0 comments
Assignees

Comments

@andrew-griffen
Copy link

Description

I have a data.frame with NA, which I replace with "" using gt::sub_missing(). But when I then pass to gt_merge_stack(), it unexpectedly prints an NA character in the table for col2.

Reproducible example

data.frame(a = 1, b = 2, c = NA, d = NA) |>
gt() |>
sub_missing(missing_text="") |>
gt_merge_stack(a,b) |>
gt_merge_stack(c,d)

Expected result

I wasn't expecting column c in the gt object to have anything since I had applied sub_missing() but instead it has an NA character for col2 (=d). I think the problem lies in gt_index() which returns NA to data_in even if sub_missing() has been applied. cols_merge() doesn't have this behavior. For example, if instead I used cols_merge(columns = c(c,d), pattern = "{1}
{2}") it gives what I was expecting (except gt_merge_stack has much better spacing). I made a local gt_merge_stack2() and added data_in <- ifelse(is.na(data_in),"",data_in) after data_in is first defined and it gives the expected behavior for this MWE but I'm not sure whether that conflicts with other functions in the package.

Session info

R version 4.4.1 (2024-06-14)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 22.04.4 LTS

Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so; LAPACK version 3.10.0

locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

time zone: Asia/Tokyo
tzcode source: system (glibc)

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] gtExtras_0.5.0 gt_0.10.1

loaded via a namespace (and not attached):
[1] vctrs_0.6.5 knitr_1.47 cli_3.6.2 xfun_0.44
[5] rlang_1.1.4 rematch2_2.1.2 generics_0.1.3 glue_1.7.0
[9] colorspace_2.1-0 htmltools_0.5.8.1 sass_0.4.9 scales_1.3.0
[13] fansi_1.0.6 grid_4.4.1 munsell_0.5.1 tibble_3.2.1
[17] fontawesome_0.5.2 fastmap_1.2.0 lifecycle_1.0.4 compiler_4.4.1
[21] dplyr_1.1.4 pkgconfig_2.0.3 rstudioapi_0.16.0 farver_2.1.2
[25] digest_0.6.35 paletteer_1.6.0 R6_2.5.1 tidyselect_1.2.1
[29] utf8_1.2.4 pillar_1.9.0 magrittr_2.0.3 withr_3.0.0
[33] tools_4.4.1 gtable_0.3.5 xml2_1.3.6 ggplot2_3.5.1

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

No branches or pull requests

2 participants