How to save a data frame as CSV to a user selected location using tcltk

Jonathan Charlton picture Jonathan Charlton · Apr 11, 2013 · Viewed 142.2k times · Source

I have a data frame called, Fail.

I would like to save Fail as a CSV in a location that the user selects. Below is some example code that I found, but I don't know how to incorporate Fail into it.

require(tcltk)
fileName <- tclvalue(tkgetSaveFile())
if (!nchar(fileName)) {
    tkmessageBox(message = "No file was selected!")
} else {
    tkmessageBox(message = paste("The file selected was", fileName))
}

Answer

kith picture kith · Apr 11, 2013

Take a look at the write.csv or the write.table functions. You just have to supply the file name the user selects to the file parameter, and the dataframe to the x parameter:

write.csv(x=df, file="myFileName")