Napmi
Napmi

Reputation: 541

How to let user choose output file name in writecsv

Any idea how to let the user choose the filename to save using this function ?

write.csv(tweets, file = "newfile.csv",
          row.names = TRUE, sep = ',', 
          col.names = TRUE)

Something like how we use the save as function and then a browser option appears.

Upvotes: 3

Views: 4167

Answers (2)

MDK
MDK

Reputation: 300

Alternatively, you can use choose.files() to get a little more of the typical Windows "Save as" behavior:

  1. Allow the user to define a filename which doesn't exist yet
  2. Add a caption to the dialogue box
  3. Default to .csv file type without the user having to type it

    write.csv(tweets, file=choose.files(caption="Save As...", 
              filters = c("Comma Delimited Files (.csv)","*.csv")))
    

Upvotes: 3

gung - Reinstate Monica
gung - Reinstate Monica

Reputation: 11893

Try ?file.choose. That should bring up the window that lets you navigate to the folder you want, and enter the file name you want to save under. That is:

write.csv(tweets, file=file.choose(), row.names=TRUE, sep=',', 
          col.names=TRUE)

Upvotes: 4

Related Questions