How to let user choose output file name in writecsv

萝らか妹 提交于 2021-01-27 13:24:39

问题


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.


回答1:


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)



回答2:


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")))
    


来源:https://stackoverflow.com/questions/19335892/how-to-let-user-choose-output-file-name-in-writecsv

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!