Feature Request: wrong output calling ` xportr_order` with grouped data
Opened this issue · 1 comments
ynsec37 commented
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)
Adding missing grouping variables:
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
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
bms63 commented
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?