cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

Using R, how do we write csv file to say dbfs:/tmp?

THIAM_HUATTAN
Valued Contributor

let us say I already have the data 'TotalData'

write.csv(TotalData,file='/tmp/TotalData.csv',row.names = FALSE)

I do not see any error from above

when I list files below:

%fs ls /tmp

I do not see any files written there. Why?

1 ACCEPTED SOLUTION

Accepted Solutions

Kaniz_Fatma
Community Manager
Community Manager

Hi @THIAM HUAT TAN​  We haven’t heard from you since the last response from @Cedric Law Hing Ping​ , and I was checking back to see if you have a resolution yet.

If you have any solution, please share it with the community as it can be helpful to others. Otherwise, we will respond with more details and try to help.

Also, Please don't forget to click on the "Select As Best" button whenever the information provided helps resolve your question.

View solution in original post

5 REPLIES 5

Cedric
Esteemed Contributor III
Esteemed Contributor III

Hi Thiam,

Thank you for reaching out to us. In this case it seems that you have written a file to the OS /tmp and tried to fetch the same folder in DBFS.

Written >> /tmp/TotalData.csv

Reading >> /dbfs/tmp/TotalData.csv

Please try to execute write.csv with the following path instead:

write.csv(TotalData,file='/dbfs/tmp/TotalData.csv',row.names = FALSE)

%fs ls /tmp

Then you will see the file in DBFS. If your intention was to write it to the OS /tmp, please do the following:

write.csv(TotalData,file='/tmp/TotalData.csv',row.names = FALSE)

%sh ls /tmp

%sh allows you to run shell code on the OS while %fs is used for DBFS file access.

Please read the following documentation for more information:

https://docs.databricks.com/notebooks/notebooks-use.html#:~:text=Notebooks%20also%20support%20a%20fe...

%r

write.csv(df,file='/tmp/df.csv',row.names = FALSE)

%fs ls /tmp

above does not show that the file df.csv exist

below will have error:

%r

write.csv(df,file='/dbfs/tmp/df.csv',row.names = FALSE)

Warning in file(file, ifelse(append, "a", "w")) :

cannot open file '/dbfs/tmp/df.csv': No such file or directory

Error in file(file, ifelse(append, "a", "w")) :

cannot open the connection

Some(<code style = 'font-size:10pt'> Error in file(file, ifelse(append, &quot;a&quot;, &quot;w&quot;)): cannot open the connection </code>)

Kaniz_Fatma
Community Manager
Community Manager

Hi @THIAM HUAT TAN​  We haven’t heard from you since the last response from @Cedric Law Hing Ping​ , and I was checking back to see if you have a resolution yet.

If you have any solution, please share it with the community as it can be helpful to others. Otherwise, we will respond with more details and try to help.

Also, Please don't forget to click on the "Select As Best" button whenever the information provided helps resolve your question.

please see above. thanks.

Hi @THIAM HUAT TAN​, Thank you for your reminder.

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group