atorus-research / Tplyr

https://atorus-research.github.io/Tplyr/
Other
95 stars 16 forks source link

Metadata vignette update #112

Closed byu-coug55 closed 1 year ago

byu-coug55 commented 1 year ago

Overview

Very small error I saw in a vignette.

Prerequisites

None.

Description

Metadata vignette

You start off by showing the following code:

t <- tplyr_table(adsl, TRT01P, where = SAFFL == "Y") %>% 
  add_layer(
    group_count(RACE)
  ) %>% 
  add_layer(
    group_desc(AGE, where = EFFFL == "Y")
  )

dat <- t %>% build(metadata=TRUE)

But then in your next code block you have:

get_meta_subset(t, 'c2_1', 'var1_Placebo') %>% 
  kable()

I believe the first argument in get_meta_subset() should be dat not t.

mstackhouse commented 1 year ago

Thanks, @byu-coug55. In this example, get_meta_subset() needs the built Tplyr table and not the output dataframe. There are 2 S3 dispatch methods for get_meta_subset() and get_meta_result():

https://atorus-research.github.io/Tplyr/reference/get_meta_subset.html

In this example, by providing the tplyr_table object t, we're able to query the metadata inside the tplyr_table object. When working with a dataframe (in this example dat), x would need to be a metadata dataframe, and then you'd need to provide dat as the target parameter:

get_meta_subset(get_metadata(t), 'c2_1', 'var1_Placebo', target=dat).

byu-coug55 commented 1 year ago

Gotcha! Thank you for helping me understand this better.