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

why the order of columns changed after setting ref_groups #707

Closed
clarkliming opened this issue Aug 9, 2023 · 5 comments
Closed

why the order of columns changed after setting ref_groups #707

clarkliming opened this issue Aug 9, 2023 · 5 comments

Comments

@clarkliming
Copy link
Contributor

clarkliming commented Aug 9, 2023

in the following example, the ref_group is always put in the left-most column.

basic_table() %>%
  split_cols_by("Species", ref_group = "virginica") %>%
  analyze("Sepal.Length") %>%
  build_table(iris)

This means that if we want to have consistent output, we have to put placebo arm in the left. This should be re-considered to provide the flexibility

@gmbecker
Copy link
Collaborator

This is intentional (ie "its a feature"). The reasoning is that I didn't (and don't) think having a reference/control group appear in the middle of the list of facets doesn't make sense from a table-reading perspective.

In light of this, rtables always places the reference group first amongst its direct siblings. It could have been last, or even configurable between first and last, but that did not seem worth the complexity at the time.

Note, though, that like virtually all aspects of faceting, you can (should be able to) forcibly override this with a custom split function. In this case you'd use the postprocessing portion of make_split_fun to reorder the facets once they are created.

@shajoezhu
Copy link
Collaborator

Hi @gmbecker , I was wondering if there is an example for " postprocessing portion of make_split_fun to reorder the facets once they are created." maybe we could have a vignette for this too?

@gmbecker
Copy link
Collaborator

gmbecker commented Aug 14, 2023

@shajoezhu the example in ?make_split_fun does this (along with a couple other things, but they are fully separable by design because that's the whole point)

@Melkiades
Copy link
Contributor

Hi @gmbecker , I was wondering if there is an example for " postprocessing portion of make_split_fun to reorder the facets once they are created." maybe we could have a vignette for this too?

reorder_facets <- function(splret, spl, fulldf, ...) {
    # browser() if you enter here the order of splret seems already correct
    ord <- order(names(splret$values))
    make_split_result(splret$values[ord],
                      splret$datasplit[ord],
                      splret$labels[ord])
}

basic_table() %>%
    split_cols_by("Species", ref_group = "virginica", split_fun = make_split_fun(post = list(reorder_facets))) %>%
    analyze("Sepal.Length") %>%
    build_table(iris)

and I get the following:

       setosa   versicolor   virginica
——————————————————————————————————————
Mean    5.01       5.94        6.59   
Warning messages:
1: In .fixupvals(ret) :
  Got a partinfo list with values that are already SplitValue objects and non-null extras element. This shouldn't happen
2: In .fixupvals(ret) :
  Got a partinfo list with values that are already SplitValue objects and non-null extras element. This shouldn't happen

The warning is duplicated for the duplicated split. I do not know why the order of the split in the split function seems identical to this second output before sorting and I do not know why the warning fires up

@gmbecker
Copy link
Collaborator

@shajoezhu I believe this issue can be closed as wontfix afterthe above pull request is merged in to get rid of the superfluous warning.

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

4 participants