Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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))
}
like image 519
Jonathan Charlton Avatar asked Apr 11 '13 18:04

Jonathan Charlton


People also ask

How do I save a DataFrame in R?

R dataset files One of the simplest ways to save your data is by saving it into an RData file with the function save( ). R saves your data to the working folder on your computer disk in a binary file.

Does read csv create a data frame?

read. csv() function reads a file in table format and creates a data frame from it, with cases corresponding to lines and variables to fields in the file.


3 Answers

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")
like image 65
kith Avatar answered Oct 16 '22 12:10

kith


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

like image 33
Shalini Baranwal Avatar answered Oct 16 '22 14:10

Shalini Baranwal


write.csv([enter name of dataframe here],file = file.choose(new = T))

After running above script this window will open :

enter image description here

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.

like image 8
Ayush Nigam Avatar answered Oct 16 '22 13:10

Ayush Nigam