Exporting a DataFrame as XML After Processing

If you want to export a DataFrame as XML after processing, you can do so by registering a script.

Create a script from the sidebar.

Specify the following in the script:

write_xml_to_downloads <- function(df, name,
downloads_path = "/Users/takatoshiroto/Downloads/",
encoding = "UTF-8") {
# Create full path for XML file
file_path <- file.path(downloads_path, str_c(name, ".xml"))
# Save dataframe as XML file
# Use xml2 package
library(xml2)
# Create root element
root <- xml_new_root("data")
# Add each row as XML element
for (i in 1:nrow(df)) {
row_node <- xml_add_child(root, "row")
for (col_name in names(df)) {
xml_add_child(row_node, col_name, as.character(df[i, col_name]))
}
}
# Save as XML file
write_xml(root, file_path, encoding = encoding)
return(df)
}

Select Custom R Command from the DataFrame and specify as follows to export as an XML file:

write_xml_to_downloads("File_Name")