Sign up to take part
Registered users can ask their own questions, contribute to discussions, and be part of the Community!
Registered users can ask their own questions, contribute to discussions, and be part of the Community!
I want to write a R dataframe in csv format in a non-local managed folder. I am not getting how to do this. I tried the method mentioned in Dataiku documentation but it is not giving desired results.
From Documenttaion:
# data must be a connection providing the data to upload dkuManagedFolderUploadPath("folder_name", "path_in_folder", data)
It says that data should be a connection. I tried with below code but it is creating a binary file and csv.
save(df, file= "sample.csv")
connection <- file("sample.csv", "rb")
dkuManagedFolderUploadPath("folderid", "sample.csv", connection)
close(connection)
Please help.
Hi @lucifer20,
To save a dataframe to a CSV file you can use write.csv(). Below is an example code:
library(dataiku)
โ
# Read the dataset as a dataframe
input_df <- dkuReadDataset("input")
โ
# Export the dataframe to a temporary local CSV file
tmp_csv_path <- tempfile()
write.csv(input_df, tmp_csv_path)
โ
# Open the CSV file for reading (as a R "connection")
tmp_csv_file_connection <- file(tmp_csv_path, "rb")
โ
# Push the result to the managed folder
dkuManagedFolderUploadPath("folderid", "mydataset.csv", tmp_csv_file_connection)
โ
# Close the connection
close(tmp_csv_file_connection)
โ
# Delete the temporary file
unlink(tmp_csv_path)