开发者

File browser in R

开发者 https://www.devze.com 2023-03-10 14:00 出处:网络
I need to write a small R script for people who never used R before that imports a file and does some things with it. I would like to minimize user i开发者_运维知识库nput as much as possible, and sinc

I need to write a small R script for people who never used R before that imports a file and does some things with it. I would like to minimize user i开发者_运维知识库nput as much as possible, and since assigning the file-path is basically all the user input required I was wondering, is it possible to get a popup screen (basically your usual "open file" screen) allowing someone to select a file (import the name as string in R or something)?


The file.choose function performs this, eg:

fname <- file.choose()

source(file.choose())

You may also want to look at choose.files (for multiple files) and choose.dir (for just selecting a directory path).


The tcltk package gives you tk_choose.files.

If you want to go beyond file choosers then you can use the package to build user interfaces.


It's worth mentioning rChoiceDialogs::rchoose.files. I'm not completely sold yet, but they advertise it as being completely cross platform and fixing the annoying problem common to choose.files and tk_choose.files of popping up behind other windows. See their vignette here.

0

精彩评论

暂无评论...
验证码 换一张
取 消