Submit your use case or success story to the 2023 edition of the Dataiku Frontrunner Awards ENTER YOUR SUBMISSION

Writing a R Dataframe into CSV in non-local Managedfolder in Dataiku

Level 1
Writing a R Dataframe into CSV in non-local Managedfolder in Dataiku

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)



Please help.

0 Kudos
1 Reply

Hi @lucifer20,

To save a dataframe to a CSV file you can use write.csv(). Below is an example code:


# 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
# Delete the temporary file


0 Kudos