Open ynsec37 opened 1 month ago
Dear developer,
when the input data is grouped, the xportr_order get wrong results as shown in below example.
xportr_order
adsl %>% group_by(USUBJID)
Adding missing grouping variables: USUBJID
USUBJID
grouped data frame
sometimes the user will forget to ungroup the final data frame, then calling the function xportr_order get wrong output.
if the function can check the input data frame is grouped or not, or ungroup the input data frame inside the function.
library(dplyr,warn.conflicts = FALSE) library(xportr) adsl <- data.frame( BRTHDT = c(1, 1, 2), STUDYID = c("mid987650", "mid987650", "mid987650"), TRT01A = c("Active", "Active", "Placebo"), USUBJID = c(1001, 1002, 1003) ) %>% group_by(USUBJID) metadata <- data.frame( dataset = c("adsl", "adsl", "adsl", "adsl"), variable = c("STUDYID", "USUBJID", "TRT01A", "BRTHDT"), order = 1:4 ) adsl <- xportr_order(adsl, metadata, domain = "adsl") #> Adding missing grouping variables: `USUBJID` #> New names: #> Warning in names(df_re_ord) != names(.df): longer object length is not a #> multiple of shorter object length #> #> ── 1 variables not in spec and moved to end ── #> #> ── 4 reordered in dataset ──
Created on 2024-05-16 with reprex v2.1.0
perhaps we should issue an error that the dataset is grouped and ask users to ungroup?
@atorus-research/xportr-development-team what do you think?
Feature Idea
Dear developer,
when the input data is grouped, the
xportr_order
get wrong results as shown in below example.adsl %>% group_by(USUBJID)
Relevant Input
grouped data frame
Relevant Output
sometimes the user will forget to ungroup the final data frame, then calling the function
xportr_order
get wrong output.if the function can check the input data frame is grouped or not, or ungroup the input data frame inside the function.
Reproducible Example/Pseudo Code
Created on 2024-05-16 with reprex v2.1.0