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.