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

Feature Request: wrong output calling xportr_order with grouped data #270

Open
ynsec37 opened this issue May 16, 2024 · 1 comment
Open
Labels
enhancement New feature or request programming

Comments

@ynsec37
Copy link

ynsec37 commented May 16, 2024

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

@ynsec37 ynsec37 added enhancement New feature or request programming labels May 16, 2024
@bms63
Copy link
Collaborator

bms63 commented May 16, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request programming
Projects
None yet
Development

No branches or pull requests

2 participants