'How to handover R list object to R transform in Code Workbook
I estimate a polr model with R in foundry code workbook. After estimation I want to handover the model object to another R transform. Estimation works fine. Handover not.
Example:
global code
library(MASS)
transform code
model <- function(modeldata) {
df <- modeldata
model = polr(answer ~ eos_ratio,
data = df,
Hess = TRUE)
return(model)
}
Error message
Function should return a data frame or FoundryObject or NULL.
Thanks
Solution 1:[1]
When you return something from Code Workbooks in Foundry, it's expected for you to be returning a data frame, a FoundryObject or a raw file written to a dataset. For saving down models, users generally use Foundry Machine Learning (FoundryML) but it currently doesn't support R officially. Please contact support for the specifics and if you face issues since I realize there might be a lot of pain here.
My R is a bit rusty, but there are a couple of (hacky) alternatives:
From the documentation https://www.palantir.com/docs/foundry/code-workbook/transforms-unstructured/#unstructured-files-in-r , here is how you save down a .rds file:
write_rds_file <- function(r_dataframe) {
output <- new.output()
output_fs <- output$fileSystem()
saveRDS(r_dataframe, output_fs$get_path("my_RDS_file.rds", 'w'))
}
You can something similar with rda
: Reusing a Model Built in R
The other option is store the model parameters in a dataframe: How do I store lm object in a data frame in R
You can then recreate the model using those parameters.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | fmsf |