Skip to contents

[Experimental] Create a python code object directly from python code or a script containing python code.

Usage

python_code(code = character(0), script = character(0))

Arguments

code

(character)
Code to mutate the dataset. Must contain the dataset$dataname.

script

(character)
file that contains python Code that can be read using reticulate::py_run_script.

Value

(PythonCodeClass) object containing python code

Details

Used to mutate dataset connector objects with python code. See mutate_dataset or mutate_data for details.

Examples

if (FALSE) {
library(scda)
library(reticulate)
library(magrittr)

# mutate dataset object

ADSL <- synthetic_cdisc_data("latest")$adsl

x <- scda_cdisc_dataset_connector("ADSL", "adsl")

x %>% mutate_dataset(python_code("import pandas as pd
r.ADSL = pd.DataFrame({'x': [1]})"))

x$get_code()
x$pull()
x$get_raw_data()

# mutate data object

y <- 8
tc <- cdisc_data(
  scda_cdisc_dataset_connector("ADSL", "adsl"),
  scda_cdisc_dataset_connector("ADLB", "adlb")
)

tc %>% mutate_data(python_code("import pandas as pd
r.ADSL = pd.DataFrame({'STUDYID': [r.y], 'USUBJID': [r.y]})"), vars = list(y = y))


load_datasets(tc) # submit all
ds <- tc$get_dataset("ADSL")
ds$get_raw_data()
}