r - file.choose() 自定义对话窗口 [英] r - file.choose() customizing dialogue window

查看:12
本文介绍了r - file.choose() 自定义对话窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让file.choose()运行后弹出的对话窗口显示自定义标题,类似于X <- menu(files, graphics=TRUE, title="选择文件 X")?

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())

目前我只是使用我的(人类)记忆来知道为第一个窗口、第二个窗口和第三个窗口选择哪些文件,但我希望窗口显示哪个对象 X YZ 当前窗口的文件将被导入.我可以将窗口移到一边以查看控制台正在执行哪一行代码,但这似乎很不雅.

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.

我试过 X <- read.csv(file.choose(new=c("Choose X"))) 例如,但似乎没有任何作用.

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

推荐答案

替代方案:

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

看到该功能也可以用于在一次调用中选择多个文件.为此,在选择多个文件时按住 CTRL 键:

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.

这篇关于r - file.choose() 自定义对话窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆