atorus-research / Tplyr

Home Page:https://atorus-research.github.io/Tplyr/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use more than two variables for nested counts

feigs opened this issue · comments

Currently only two variables are allowed for nested count layers. Do you plan to allow for more variables (three would be good enough for me, but maybe other users have more complex use-cases).

See example below (using Tplyr V1.1.0)

Thanks!

library(dplyr)
library(Tplyr)

ds <- tibble::tribble(~SubjId,~Group1, ~Group2,~Group3,~Trtvar,
"001", "Region 1","Country1", "Site 0", "Placebo",
"003", "Region 1","Country1", "Site 0", "Placebo",
"004", "Region 1","Country1", "Site 1", "Placebo",
"009", "Region 1","Country1", "Site 0", "HighDose",
"011", "Region 1","Country1", "Site 1", "HighDose",
"022", "Region 2","Country3", "Site 6", "HighDose",
"024", "Region 2","Country3", "Site 6", "HighDose",
"028", "Region 2","Country3", "Site 6", "Placebo",
"027", "Region 2","Country4", "Site 9", "HighDose",
"023", "Region 2","Country4", "Site 9", "Placebo")

t<-tplyr_table(ds,Trtvar)

this works

t1 <- t %>%
add_layer(group_count(vars(Group1,Group2))%>%
set_nest_count(TRUE)%>%
set_indentation("----")
)

out1 <- t1%>%
build()

this does not work

t2 <- t %>%
add_layer(group_count(vars(Group1,Group2,Group3))%>%
set_nest_count(TRUE)%>%
set_indentation("----")
)

out2 <- t2%>%
build()

Hi @feigs.

This is definitely something we've discussed, and is unfortunately a hefty update right now. But we have interest in supporting this in the future, so I've tagged as an enhancement. I'd like to see this eventually able to take n variables, because a proper framework for 3 variables would should be repeatable for 4, 5, etc.

While it doesn't produce exactly what you're looking for, in some cases you might be able to get what you need by using a by variable. This won't have the outer group totaling though.

Closing because I'll defer this to something addressed in tplyr2