Maiasaura
Maiasaura

Reputation: 32986

Save a file interactively?

Using tk_choose.files or file.choose I am able to select a file interactively. Is there an analogous function wherein I can allow a user to interactively decide where to save the output of a write.table?

Upvotes: 5

Views: 2629

Answers (4)

MS Berends
MS Berends

Reputation: 5219

Old question, but after a long search I found that the tcltk2 package now exists as an improvement of tcltk:

library(tcltk2)
filename <- tclvalue(tkgetSaveFile())
if (!nchar(filename)) {
  tkmessageBox(message = "No file was selected!")
} else {
  tkmessageBox(message = paste("The file selected was", filename))
}

Upvotes: 2

jverzani
jverzani

Reputation: 5700

Try

val <- tkgetSaveFile(initialfile="", title="Save a file...")
f <- tclvalue(val)
if(f != "") ...

Upvotes: 2

user441706
user441706

Reputation: 1370

@Chase - this works in OS X (Eclipse and StatET). At least, I tried writing a data.frame (df) as a CSV file:

write.csv(x = df, file = file.choose())

Upvotes: 0

Chase
Chase

Reputation: 69201

On Windows 7 and working through the RGUI, I can specify something like:

write.table(x = iris, file = file.choose())

which pops open a Windows Explorer dialogue. I can then navigate to any existing file, create a new file by right clicking, or simply by typing the name of a new file where it will ask to create a new file.

I guess this may not be platform independent...can others with the appropriate OS's verify?

Upvotes: 6

Related Questions