How to save a data frame as CSV to a user selected location using tcltk
Solution 1
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")
Solution 2
You need not to use even the package "tcltk". You can simply do as shown below:
write.csv(x, file = "c:\\myname\\yourfile.csv", row.names = FALSE)
Give your path inspite of "c:\myname\yourfile.csv".
Solution 3
write.csv([enter name of dataframe here],file = file.choose(new = T))
After running above script this window will open :
Type the new file name with extension in the File name field and click Open, it'll ask you to create a new file to which you should select Yes and the file will be created and saved in the desired location.
Jonathan Charlton
Updated on July 08, 2022Comments
-
Jonathan Charlton almost 2 years
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 incorporateFail
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)) }
-
Slak over 9 yearsI didn't see it mentioned, so I thought it would be useful to mention the
row.names = F
parameter that will remove the rownames from taking up an output column