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(reticulate)
library(magrittr)
# mutate dataset object
random_data_connector <- function(dataname) {
fun_dataset_connector(
dataname = dataname,
fun = teal.data::example_cdisc_data,
fun_args = list(dataname = dataname),
)
}
x <- random_data_connector(dataname = "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(
random_data_connector(dataname = "ADSL"),
random_data_connector(dataname = "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()
}