简体   繁体   中英

r - file.choose() customizing dialogue window

Is there a way for the dialogue window that pops up after file.choose() is run to display a custom title, similar to X <- menu(files, graphics=TRUE, title="Choose file X") ?

Right now my code requires several files be loaded.

X <- read.csv(file.choose())
Y <- read.csv(file.choose())
Z <- read.csv(file.choose())

At the moment I'm just using my (human) memory to know which files to choose for the first window, the second window, and the third window, but I'd like the window to show which object X Y or Z the current window's file will be imported to. I can move the window aside to see which line of code the console is up to, but that seems pretty inelegant.

I've tried X <- read.csv(file.choose(new=c("Choose X"))) for example but that doesn't seem to do anything.

An alternative:

library(tcltk)
X <- read.csv(tk_choose.files(caption = "Choose X"))

See that the function can also be used to select multiple files in one call. For that, hold CTRL when selecting more than one file:

XYZ.list <- lapply(tk_choose.files(caption = "Choose X, Y, and Z"), read.csv)

but the selection order is not preserved so you might want to keep three separate calls if that works better for you.

On Windows, you can use choose.files , which allows for custom title and also default file name ( default ), file type filtering ( filters ) and multifile selection ( multi ):

choose.files(default = "", caption = "Select files",
             multi = TRUE, filters = Filters,
             index = nrow(Filters))

check the help ?choose.files ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM