pharmaverse / admiral

ADaM in R Asset Library
https://pharmaverse.github.io/admiral
Apache License 2.0
215 stars 60 forks source link

Documentation: Invalid value passed to argument `out_unit` in `derive_vars_duration()` under "Usage" section #2464

Closed gg106046 closed 1 month ago

gg106046 commented 1 month ago

Function Documentation

1

The value passed to out_unit argument in derive_vars_duration() function should be in lowercase instead of up case.

bundfussr commented 1 month ago

I think uppercase is fine. For the calculation the value is handled case-insensitive. However, the unit variable is set to the specified value (without changing the case). As far as I remember we are using "DAYS" as default value because it is the value defined in the CDISC codelist C71620.

gg106046 commented 1 month ago

I think for the calculation, the value of out_unit is case-sensitive as I get the following error:

image

But when out_unit is set to a lower-case unit, the unit variable comes up as an up-case unit (YEARS"/"DAYS") by default in the dataset.

bundfussr commented 1 month ago

Are you using an old version of admiral? We changed it in admiral 1.0.0.

I get

> derive_vars_duration(data,
+                      new_var = ADURN,
+                      new_var_unit = ADURU,
+                      start_date = ASTDT,
+                      end_date = AENDT,
+                      out_unit = "days"
+ )
# A tibble: 4 × 5
  USUBJID ASTDT      AENDT      ADURN ADURU
  <chr>   <date>     <date>     <dbl> <chr>
1 P01     2021-03-05 2021-03-02    -3 days 
2 P02     2019-09-18 2019-09-18     1 days 
3 P03     1985-01-01 NA            NA NA   
4 P04     NA         NA            NA NA   
> derive_vars_duration(data,
+                      new_var = ADURN,
+                      new_var_unit = ADURU,
+                      start_date = ASTDT,
+                      end_date = AENDT,
+                      out_unit = "DAYS"
+ )
# A tibble: 4 × 5
  USUBJID ASTDT      AENDT      ADURN ADURU
  <chr>   <date>     <date>     <dbl> <chr>
1 P01     2021-03-05 2021-03-02    -3 DAYS 
2 P02     2019-09-18 2019-09-18     1 DAYS 
3 P03     1985-01-01 NA            NA NA   
4 P04     NA         NA            NA NA   
gg106046 commented 1 month ago

Are you using an old version of admiral? We changed it in admiral 1.0.0.

I get

> derive_vars_duration(data,
+                      new_var = ADURN,
+                      new_var_unit = ADURU,
+                      start_date = ASTDT,
+                      end_date = AENDT,
+                      out_unit = "days"
+ )
# A tibble: 4 × 5
  USUBJID ASTDT      AENDT      ADURN ADURU
  <chr>   <date>     <date>     <dbl> <chr>
1 P01     2021-03-05 2021-03-02    -3 days 
2 P02     2019-09-18 2019-09-18     1 days 
3 P03     1985-01-01 NA            NA NA   
4 P04     NA         NA            NA NA   
> derive_vars_duration(data,
+                      new_var = ADURN,
+                      new_var_unit = ADURU,
+                      start_date = ASTDT,
+                      end_date = AENDT,
+                      out_unit = "DAYS"
+ )
# A tibble: 4 × 5
  USUBJID ASTDT      AENDT      ADURN ADURU
  <chr>   <date>     <date>     <dbl> <chr>
1 P01     2021-03-05 2021-03-02    -3 DAYS 
2 P02     2019-09-18 2019-09-18     1 DAYS 
3 P03     1985-01-01 NA            NA NA   
4 P04     NA         NA            NA NA   

Are you using an old version of admiral? We changed it in admiral 1.0.0.

I get

> derive_vars_duration(data,
+                      new_var = ADURN,
+                      new_var_unit = ADURU,
+                      start_date = ASTDT,
+                      end_date = AENDT,
+                      out_unit = "days"
+ )
# A tibble: 4 × 5
  USUBJID ASTDT      AENDT      ADURN ADURU
  <chr>   <date>     <date>     <dbl> <chr>
1 P01     2021-03-05 2021-03-02    -3 days 
2 P02     2019-09-18 2019-09-18     1 days 
3 P03     1985-01-01 NA            NA NA   
4 P04     NA         NA            NA NA   
> derive_vars_duration(data,
+                      new_var = ADURN,
+                      new_var_unit = ADURU,
+                      start_date = ASTDT,
+                      end_date = AENDT,
+                      out_unit = "DAYS"
+ )
# A tibble: 4 × 5
  USUBJID ASTDT      AENDT      ADURN ADURU
  <chr>   <date>     <date>     <dbl> <chr>
1 P01     2021-03-05 2021-03-02    -3 DAYS 
2 P02     2019-09-18 2019-09-18     1 DAYS 
3 P03     1985-01-01 NA            NA NA   
4 P04     NA         NA            NA NA   

Ah yes. I was using an older version. My bad! This issue can be closed then.