Python Code
python_code.Rd
Arguments
- code
(
character
)
Code to mutate the dataset. Must contain thedataset$dataname
.- script
(
character
)
file that contains python Code that can be read usingreticulate::py_run_script
.
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()
}