Retrieve raw data
get_raw_data.Rd
Usage
get_raw_data(x, dataname = NULL)
# S3 method for TealDataset
get_raw_data(x, dataname = NULL)
# S3 method for TealDatasetConnector
get_raw_data(x, dataname = NULL)
# S3 method for TealDataAbstract
get_raw_data(x, dataname = NULL)
Arguments
- x
(
TealDataset
,TealDatasetConnector
,TealDataAbstract
)
object- dataname
(
character
)
Name of dataset to return raw data for.
Value
data.frame
with the raw data inserted into the R6 objects. In case of
TealDataAbstract
, list
of data.frame
can be returned
if user doesn't specify dataname
- (get_raw_data
from all datasets).
Examples
# TealDataset ---------
ADSL <- teal.data::example_cdisc_data("ADSL")
x <- dataset(dataname = "ADSL", x = ADSL)
get_raw_data(x)
#> # A tibble: 400 × 55
#> STUDYID USUBJID SUBJID SITEID AGE AGEU SEX RACE ETHNIC COUNTRY DTHFL
#> <chr> <chr> <chr> <chr> <int> <fct> <fct> <fct> <fct> <fct> <fct>
#> 1 AB12345 AB12345-C… id-128 CHN-3 32 YEARS M ASIAN HISPA… CHN Y
#> 2 AB12345 AB12345-C… id-262 CHN-15 35 YEARS M BLAC… NOT H… CHN N
#> 3 AB12345 AB12345-R… id-378 RUS-3 30 YEARS F ASIAN NOT H… RUS N
#> 4 AB12345 AB12345-C… id-220 CHN-11 26 YEARS F ASIAN NOT H… CHN N
#> 5 AB12345 AB12345-C… id-267 CHN-7 40 YEARS M ASIAN NOT H… CHN N
#> 6 AB12345 AB12345-C… id-201 CHN-15 49 YEARS M ASIAN NOT H… CHN Y
#> 7 AB12345 AB12345-U… id-45 USA-1 34 YEARS F ASIAN NOT H… USA N
#> 8 AB12345 AB12345-U… id-261 USA-1 32 YEARS F ASIAN NOT H… USA N
#> 9 AB12345 AB12345-N… id-173 NGA-11 24 YEARS F BLAC… NOT H… NGA N
#> 10 AB12345 AB12345-C… id-307 CHN-1 24 YEARS M ASIAN NOT H… CHN Y
#> # ℹ 390 more rows
#> # ℹ 44 more variables: INVID <chr>, INVNAM <chr>, ARM <fct>, ARMCD <fct>,
#> # ACTARM <fct>, ACTARMCD <fct>, TRT01P <fct>, TRT01A <fct>, TRT02P <fct>,
#> # TRT02A <fct>, REGION1 <fct>, STRATA1 <fct>, STRATA2 <fct>, BMRKR1 <dbl>,
#> # BMRKR2 <fct>, ITTFL <fct>, SAFFL <fct>, BMEASIFL <fct>, BEP01FL <fct>,
#> # AEWITHFL <fct>, RANDDT <date>, TRTSDTM <dttm>, TRTEDTM <dttm>,
#> # TRT01SDTM <dttm>, TRT01EDTM <dttm>, TRT02SDTM <dttm>, TRT02EDTM <dttm>, …
# TealDatasetConnector ---------
library(magrittr)
pull_fun_adsl <- callable_function(teal.data::example_cdisc_data) %>%
set_args(list(dataname = "ADSL"))
dc <- dataset_connector("ADSL", pull_fun_adsl)
load_dataset(dc)
get_raw_data(dc)
#> # A tibble: 400 × 55
#> STUDYID USUBJID SUBJID SITEID AGE AGEU SEX RACE ETHNIC COUNTRY DTHFL
#> <chr> <chr> <chr> <chr> <int> <fct> <fct> <fct> <fct> <fct> <fct>
#> 1 AB12345 AB12345-C… id-128 CHN-3 32 YEARS M ASIAN HISPA… CHN Y
#> 2 AB12345 AB12345-C… id-262 CHN-15 35 YEARS M BLAC… NOT H… CHN N
#> 3 AB12345 AB12345-R… id-378 RUS-3 30 YEARS F ASIAN NOT H… RUS N
#> 4 AB12345 AB12345-C… id-220 CHN-11 26 YEARS F ASIAN NOT H… CHN N
#> 5 AB12345 AB12345-C… id-267 CHN-7 40 YEARS M ASIAN NOT H… CHN N
#> 6 AB12345 AB12345-C… id-201 CHN-15 49 YEARS M ASIAN NOT H… CHN Y
#> 7 AB12345 AB12345-U… id-45 USA-1 34 YEARS F ASIAN NOT H… USA N
#> 8 AB12345 AB12345-U… id-261 USA-1 32 YEARS F ASIAN NOT H… USA N
#> 9 AB12345 AB12345-N… id-173 NGA-11 24 YEARS F BLAC… NOT H… NGA N
#> 10 AB12345 AB12345-C… id-307 CHN-1 24 YEARS M ASIAN NOT H… CHN Y
#> # ℹ 390 more rows
#> # ℹ 44 more variables: INVID <chr>, INVNAM <chr>, ARM <fct>, ARMCD <fct>,
#> # ACTARM <fct>, ACTARMCD <fct>, TRT01P <fct>, TRT01A <fct>, TRT02P <fct>,
#> # TRT02A <fct>, REGION1 <fct>, STRATA1 <fct>, STRATA2 <fct>, BMRKR1 <dbl>,
#> # BMRKR2 <fct>, ITTFL <fct>, SAFFL <fct>, BMEASIFL <fct>, BEP01FL <fct>,
#> # AEWITHFL <fct>, RANDDT <date>, TRTSDTM <dttm>, TRTEDTM <dttm>,
#> # TRT01SDTM <dttm>, TRT01EDTM <dttm>, TRT02SDTM <dttm>, TRT02EDTM <dttm>, …
# TealData ----------------
adsl <- cdisc_dataset(
dataname = "ADSL",
x = teal.data::example_cdisc_data("ADSL"),
code = "library(teal.data)\nADSL <- teal.data::example_cdisc_data(\"ADSL\")"
)
adtte <- cdisc_dataset(
dataname = "ADTTE",
x = teal.data::example_cdisc_data("ADTTE"),
code = "library(teal.data)\nADTTE <- teal.data::example_cdisc_data(\"ADTTE\")"
)
rd <- teal.data:::TealData$new(adsl, adtte)
get_raw_data(rd)
#> $ADSL
#> # A tibble: 400 × 55
#> STUDYID USUBJID SUBJID SITEID AGE AGEU SEX RACE ETHNIC COUNTRY DTHFL
#> <chr> <chr> <chr> <chr> <int> <fct> <fct> <fct> <fct> <fct> <fct>
#> 1 AB12345 AB12345-C… id-128 CHN-3 32 YEARS M ASIAN HISPA… CHN Y
#> 2 AB12345 AB12345-C… id-262 CHN-15 35 YEARS M BLAC… NOT H… CHN N
#> 3 AB12345 AB12345-R… id-378 RUS-3 30 YEARS F ASIAN NOT H… RUS N
#> 4 AB12345 AB12345-C… id-220 CHN-11 26 YEARS F ASIAN NOT H… CHN N
#> 5 AB12345 AB12345-C… id-267 CHN-7 40 YEARS M ASIAN NOT H… CHN N
#> 6 AB12345 AB12345-C… id-201 CHN-15 49 YEARS M ASIAN NOT H… CHN Y
#> 7 AB12345 AB12345-U… id-45 USA-1 34 YEARS F ASIAN NOT H… USA N
#> 8 AB12345 AB12345-U… id-261 USA-1 32 YEARS F ASIAN NOT H… USA N
#> 9 AB12345 AB12345-N… id-173 NGA-11 24 YEARS F BLAC… NOT H… NGA N
#> 10 AB12345 AB12345-C… id-307 CHN-1 24 YEARS M ASIAN NOT H… CHN Y
#> # ℹ 390 more rows
#> # ℹ 44 more variables: INVID <chr>, INVNAM <chr>, ARM <fct>, ARMCD <fct>,
#> # ACTARM <fct>, ACTARMCD <fct>, TRT01P <fct>, TRT01A <fct>, TRT02P <fct>,
#> # TRT02A <fct>, REGION1 <fct>, STRATA1 <fct>, STRATA2 <fct>, BMRKR1 <dbl>,
#> # BMRKR2 <fct>, ITTFL <fct>, SAFFL <fct>, BMEASIFL <fct>, BEP01FL <fct>,
#> # AEWITHFL <fct>, RANDDT <date>, TRTSDTM <dttm>, TRTEDTM <dttm>,
#> # TRT01SDTM <dttm>, TRT01EDTM <dttm>, TRT02SDTM <dttm>, TRT02EDTM <dttm>, …
#>
#> $ADTTE
#> # A tibble: 2,000 × 67
#> STUDYID USUBJID SUBJID SITEID AGE AGEU SEX RACE ETHNIC COUNTRY DTHFL
#> <chr> <chr> <chr> <chr> <int> <fct> <fct> <fct> <fct> <fct> <fct>
#> 1 AB12345 AB12345-B… id-105 BRA-1 38 YEARS M BLAC… HISPA… BRA N
#> 2 AB12345 AB12345-B… id-105 BRA-1 38 YEARS M BLAC… HISPA… BRA N
#> 3 AB12345 AB12345-B… id-105 BRA-1 38 YEARS M BLAC… HISPA… BRA N
#> 4 AB12345 AB12345-B… id-105 BRA-1 38 YEARS M BLAC… HISPA… BRA N
#> 5 AB12345 AB12345-B… id-105 BRA-1 38 YEARS M BLAC… HISPA… BRA N
#> 6 AB12345 AB12345-B… id-134 BRA-1 47 YEARS M WHITE NOT H… BRA Y
#> 7 AB12345 AB12345-B… id-134 BRA-1 47 YEARS M WHITE NOT H… BRA Y
#> 8 AB12345 AB12345-B… id-134 BRA-1 47 YEARS M WHITE NOT H… BRA Y
#> 9 AB12345 AB12345-B… id-134 BRA-1 47 YEARS M WHITE NOT H… BRA Y
#> 10 AB12345 AB12345-B… id-134 BRA-1 47 YEARS M WHITE NOT H… BRA Y
#> # ℹ 1,990 more rows
#> # ℹ 56 more variables: INVID <chr>, INVNAM <chr>, ARM <fct>, ARMCD <fct>,
#> # ACTARM <fct>, ACTARMCD <fct>, TRT01P <fct>, TRT01A <fct>, TRT02P <fct>,
#> # TRT02A <fct>, REGION1 <fct>, STRATA1 <fct>, STRATA2 <fct>, BMRKR1 <dbl>,
#> # BMRKR2 <fct>, ITTFL <fct>, SAFFL <fct>, BMEASIFL <fct>, BEP01FL <fct>,
#> # AEWITHFL <fct>, RANDDT <date>, TRTSDTM <dttm>, TRTEDTM <dttm>,
#> # TRT01SDTM <dttm>, TRT01EDTM <dttm>, TRT02SDTM <dttm>, TRT02EDTM <dttm>, …
#>
# TealDataConnector --------
library(magrittr)
slice_cdisc_data <- function(dataname, n) {
head(example_cdisc_data(dataname), n)
}
random_data_connector <- function(dataname) {
fun_dataset_connector(
dataname = dataname,
fun = slice_cdisc_data,
fun_args = list(dataname = dataname),
)
}
open_fun <- callable_function(library)
open_fun$set_args(list(package = "teal.data"))
con <- data_connection(open_fun = open_fun)
con$set_open_server(
function(id, connection) {
moduleServer(
id = id,
module = function(input, output, session) {
connection$open(try = TRUE)
return(invisible(connection))
}
)
}
)
rdc <- relational_data_connector(
connection = con,
connectors = list(random_data_connector("ADSL"), random_data_connector("ADLB"))
)
rdc$set_ui(
function(id, connection, connectors) {
ns <- NS(id)
tagList(
connection$get_open_ui(ns("open_connection")),
numericInput(inputId = ns("n"), label = "Choose number of records", min = 0, value = 1),
do.call(
what = "tagList",
args = lapply(
connectors,
function(connector) {
div(
connector$get_ui(
id = ns(connector$get_dataname())
),
br()
)
}
)
)
)
}
)
rdc$set_server(
function(id, connection, connectors) {
moduleServer(
id = id,
module = function(input, output, session) {
# opens connection
connection$get_open_server()(id = "open_connection", connection = connection)
if (connection$is_opened()) {
for (connector in connectors) {
set_args(connector, args = list(n = input$n))
# pull each dataset
connector$get_server()(id = connector$get_dataname())
if (connector$is_failed()) {
break
}
}
}
}
)
}
)
if (FALSE) {
load_datasets(rdc)
get_raw_data(rdc)
}
# TealData (with connectors) --------
drc <- cdisc_data(rdc)
if (FALSE) {
get_raw_data(drc)
}