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

analyze_vars_in_cols is not working well with categorical data #1013

Closed
Melkiades opened this issue Jul 27, 2023 · 1 comment · Fixed by #1014
Closed

analyze_vars_in_cols is not working well with categorical data #1013

Melkiades opened this issue Jul 27, 2023 · 1 comment · Fixed by #1014
Assignees
Labels
bug Something isn't working sme

Comments

@Melkiades
Copy link
Contributor

Melkiades commented Jul 27, 2023

library(tern)
adpp <- tern_ex_adpp %>% h_pkparam_sort()

  lyt <- basic_table() %>%
    split_rows_by(var = "STRATA1", label_pos = "topleft") %>%
    split_rows_by(
      var = "SEX",
      label_pos = "topleft",
      child_label = "hidden"
    ) %>%
    # split_cols_by("STRATA1") %>%
    analyze_vars_in_cols(
      vars = "ARM",
      .stats = c("n", "count_fraction"),
      .labels = c("count_fraction" = "argh")
    )
# error before now is more informative
  testthat::expect_error(
    result <- build_table(lyt = lyt, df = adpp),
    "The analyzed column produced more than one category of results."
  )

  lyt <- basic_table() %>%
    split_rows_by(var = "STRATA1", label_pos = "topleft") %>%
    split_rows_by(
      var = "SEX",
      label_pos = "topleft",
      child_label = "hidden"
    ) %>%
    split_cols_by("ARM") %>%
    analyze_vars_in_cols(
      vars = "counter",
      .stats = c("count_fraction"),
      .labels = c("count_fraction" = " ")
    )
# error before -> unlist
  testthat::expect_snapshot(build_table(
    lyt = lyt,
    df = adpp %>% mutate(counter = factor("n"))
  ))
@Melkiades Melkiades added bug Something isn't working sme labels Jul 27, 2023
@Melkiades Melkiades self-assigned this Jul 27, 2023
@shajoezhu
Copy link
Contributor

hi @Melkiades , can you provide an example here please. thanks

Melkiades added a commit that referenced this issue Aug 4, 2023
FIxes #1013 but it may be not the best way. Last test show an
alternative way that is much simpler.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working sme
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants