Skip to contents

[Stable]

[Stable]

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 to mutate_code - location of the file containing modification code. Can't be used simultaneously with mutate_script.

metadata

(named list, NULL or CallableFunction)
Field containing either the metadata about the dataset (each element of the list should be atomic and length one) or a CallableFuntion to pull the metadata from a connection. This should return a list or an object which can be converted to a list with as.list.

...

Additional arguments applied to pull function. In case when this object code depends on the raw_data from the other TealDataset, TealDatasetConnector object(s) or other constant value, this/these object(s) should be included. Please note that vars are included to this object as local vars 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

library(scda)
x <- code_dataset_connector(
  dataname = "ADSL",
  keys = get_cdisc_keys("ADSL"),
  code = "ADSL <- synthetic_cdisc_data(\"latest\")$adsl; ADSL"
)

x$get_code()
#> [1] "ADSL <- synthetic_cdisc_data(\"latest\")$adsl\nADSL <- ADSL"

mutate_dataset(x, code = "ADSL$new_variable <- 1")
x$get_code()
#> [1] "ADSL <- synthetic_cdisc_data(\"latest\")$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")
)