-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Description
Hello, I discovered that the function order_cols accepts and processes negative order values in the metacore, which should be rejected as they are not valid order values. I’m not sure how significant the impact of this behavior might be, so I am first creating this issue for your information.
reprex
library(metacore)
#> Attaching package `metacore`
#>
#> As of metacore 0.3.0 the `keep` variable in the `ds_vars` table has been renamed to `mandatory`. Please see release documentation for details.
library(metatools)
library(dplyr)
load(metacore::metacore_example("pilot_ADaM.rda"))
data <- haven::read_xpt(metatools_example("adsl.xpt"))
# Modify ds_vars to have negative order(-10) for BMIBLGR1, which was originally 36th in the order
modified_ds_vars <- metacore$ds_vars %>%
mutate(order = if_else(dataset == "ADSL" & variable == "BMIBLGR1", -10, order))
# Reconstruct metacore object with modified ds_vars
spec <- suppressWarnings(
metacore::metacore(
metacore$ds_spec,
modified_ds_vars,
metacore$var_spec,
metacore$value_spec,
metacore$derivations,
metacore$codelist
)
) %>%
select_dataset("ADSL", verbose = "silent")
# Now the column BMIBLGR1 comes first, because it has the lowest(-10) order value in the spec.
# However, this is not the intended behavior as -10 is a negative number and hence not a valid order value.
order_cols(data, spec)
#> # A tibble: 254 × 51
#> BMIBLGR1 STUDYID USUBJID SUBJID SITEID SITEGR1 ARM TRT01P TRT01PN TRT01A
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <dbl> <chr>
#> 1 25-<30 CDISCPILO… 01-701… 1015 701 701 Plac… Place… 0 Place…
#> 2 >=30 CDISCPILO… 01-701… 1023 701 701 Plac… Place… 0 Place…
#> 3 >=30 CDISCPILO… 01-701… 1028 701 701 Xano… Xanom… 81 Xanom…
#> 4 25-<30 CDISCPILO… 01-701… 1033 701 701 Xano… Xanom… 54 Xanom…
#> 5 25-<30 CDISCPILO… 01-701… 1034 701 701 Xano… Xanom… 81 Xanom…
#> 6 >=30 CDISCPILO… 01-701… 1047 701 701 Plac… Place… 0 Place…
#> 7 25-<30 CDISCPILO… 01-701… 1097 701 701 Xano… Xanom… 54 Xanom…
#> 8 <25 CDISCPILO… 01-701… 1111 701 701 Xano… Xanom… 54 Xanom…
#> 9 <25 CDISCPILO… 01-701… 1115 701 701 Xano… Xanom… 54 Xanom…
#> 10 <25 CDISCPILO… 01-701… 1118 701 701 Plac… Place… 0 Place…
#> # ℹ 244 more rows
#> # ℹ 41 more variables: TRT01AN <dbl>, TRTSDT <date>, TRTEDT <date>,
#> # TRTDURD <dbl>, AVGDD <dbl>, CUMDOSE <dbl>, AGE <dbl>, AGEGR1 <chr>,
#> # AGEGR1N <dbl>, AGEGR2 <chr>, AGEGR2N <dbl>, AGEU <chr>, RACE <chr>,
#> # RACEN <dbl>, SEX <chr>, ETHNIC <chr>, SAFFL <chr>, ITTFL <chr>,
#> # EFFFL <chr>, COMP8FL <chr>, COMP16FL <chr>, COMP24FL <chr>, DISCONFL <chr>,
#> # DSRAEFL <chr>, DTHFL <chr>, BMIBL <dbl>, HEIGHTBL <dbl>, WEIGHTBL <dbl>, …Created on 2026-02-02 with reprex v2.1.1
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels