Code TealDatasetConnector
code_dataset_connector.Rd
Usage
code_dataset_connector(
dataname,
code,
keys = character(0),
label = character(0),
mutate_code = character(0),
mutate_script = character(0),
metadata = NULL,
...
)
code_cdisc_dataset_connector(
dataname,
code,
keys = get_cdisc_keys(dataname),
parent = if (identical(dataname, "ADSL")) character(0L) else "ADSL",
label = character(0),
mutate_code = character(0),
metadata = NULL,
...
)
Arguments
- dataname
(
character
)
A given name for the dataset it may not contain spaces- code
(
character
)
String containing the code to produce the object. The code must end in a call to the object.- keys
optional, (
character
)
vector of dataset primary keys column names- label
(
character
)
Label to describe the dataset.- mutate_code
(
character
)
String containing the code used to mutate the object after it is produced.- mutate_script
(
character
)
Alternatively tomutate_code
- location of the file containing modification code. Can't be used simultaneously withmutate_script
.- metadata
(named
list
,NULL
orCallableFunction
)
Field containing either the metadata about the dataset (each element of the list should be atomic and length one) or aCallableFuntion
to pull the metadata from a connection. This should return alist
or an object which can be converted to a list withas.list
.- ...
Additional arguments applied to pull function. In case when this object code depends on the
raw_data
from the otherTealDataset
,TealDatasetConnector
object(s) or other constant value, this/these object(s) should be included. Please note thatvars
are included to this object as localvars
and they cannot be modified within another dataset.- parent
(
character
, optional) parent dataset name
Details
Create a TealDatasetConnector
from a string of code.
Create a CDISCTealDatasetConnector
from a string of code with keys
assigned automatically by dataname
.
Examples
x <- code_dataset_connector(
dataname = "ADSL",
keys = get_cdisc_keys("ADSL"),
code = "ADSL <- teal.data::example_cdisc_data(\"ADSL\"); ADSL"
)
x$get_code()
#> [1] "ADSL <- teal.data::example_cdisc_data(\"ADSL\")\nADSL <- ADSL"
mutate_dataset(x, code = "ADSL$new_variable <- 1")
x$get_code()
#> [1] "ADSL <- teal.data::example_cdisc_data(\"ADSL\")\nADSL <- ADSL\nADSL$new_variable <- 1"
file_example <- tempfile(fileext = ".R")
writeLines(
text = c(
"seed <- 1; ADSL <- radsl(cached = TRUE, seed = seed)\nADSL"
),
con = file_example
)
y <- code_dataset_connector(
dataname = "ADSL",
keys = get_cdisc_keys("ADSL"),
code = paste0(readLines(file_example), collapse = "\n")
)