OS-independent way to select directory interactively in R

后端 未结 5 931
Happy的楠姐
Happy的楠姐 2021-02-12 10:54

I would like users to be able to select a directory interactively in R. The solution needs to work on different platforms (at least on Linux, Windows and Mac machines that have

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-12 11:36

    Suggestion for adaption of choose_directory() as mentioned in my comment (06.09.2018 RFelber):

    choose_directory <- function(ini_dir = getwd(),
                                 method = select_directory_method(), 
                                 title = 'Select data directory') {
      switch(method,
              'choose.dir' = choose.dir(default = ini_dir, caption = title),
              'RStudioAPI' = selectDirectory(path = ini_dir, caption = title),
              'tcltk' = tk_choose.dir(default = ini_dir, caption = title),
              'rChoiceDialogs' = rchoose.dir(default = ini_dir, caption = title),
              'gWidgets2RGtk2' = gfile(type = 'selectdir', text = title, initial.dir = ini_dir),
              readline('Please enter directory path: ')
      )
    }
    

提交回复
热议问题