Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7399131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:01:06+00:00 2026-05-29T04:01:06+00:00

Are there any R users aware of an "open file"-type function in R? Preferably

  • 0

Are there any R users aware of an "open file"-type function in R?
Preferably it’d have a text interface, e.g.:

> file.choose("/path/to/start/at")
path/to/start/at:
[1] [D] a_directory
[2] [D] another_directory
[3] [F] apicture.tif
[4] [F] atextfile.txt
...
[..] Go up a directory
Enter selection: 

And I’d be able to browse through until I select the file(s) I wanted.

I am aware of the current file.choose, but (on Linux anyway) that just says "enter file name:" and takes whatever you type in, but doesn’t give you the ability to browse. (Perhaps on Windows it shows an "open file" dialog?).

I’m amenable to an open file dialog but would prefer to stay away from loading a GUI package like RGtk2/tcltk/etc just for this.

I could also write the above text browser myself but I figured I’d ask to see if anyone knew of such a function before I try to reinvent the wheel (and get it wrong many, many, times before it works!)

cheers.

Update

The answer is "no" to the text-based interface. But based on @TylerRinker’s solution and comments by @Iterator, I wrote my own function to do it (and it was much easier than I thought thanks to them!):

Edit – modified default to multiple=F as usually people expect to select one file.

#' Text-based interactive file selection.
#'@param root the root directory to explore
#'             (default current working directory)
#'@param multiple boolean specifying whether to allow 
#'                 multiple files to be selected
#'@return character vector of selected files.
#'@examples 
#'fileList <- my.file.browse()
my.file.browse <- function (root=getwd(), multiple=F) {
    # .. and list.files(root)
    x <- c( dirname(normalizePath(root)), list.files(root,full.names=T) )
    isdir <- file.info(x)$isdir
    obj <- sort(isdir,index.return=T,decreasing=T)
    isdir <- obj$x
    x <- x[obj$ix]
    lbls <- sprintf('%s%s',basename(x),ifelse(isdir,'/',''))
    lbls[1] <- sprintf('../ (%s)', basename(x[1]))

    files <- c()
    sel = -1
    while ( TRUE ) {
        sel <- menu(lbls,title=sprintf('Select file(s) (0 to quit) in folder %s:',root))
        if (sel == 0 )
            break
        if (isdir[sel]) {
            # directory, browse further
            files <- c(files, my.file.browse( x[sel], multiple ))
            break
        } else {
            # file, add to list
            files <- c(files,x[sel])
            if ( !multiple )
                break
            # remove selected file from choices
            lbls <- lbls[-sel]
            x <- x[-sel]
            isdir <- isdir[-sel]
        }
    }
    return(files)
}

It might barf with symlinks and the ‘..’ since I use normalizePath, .. but oh well.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T04:01:07+00:00Added an answer on May 29, 2026 at 4:01 am

    I have kind of what you want made that I keep in my .Rprofile. It has a menu interface as it’s default for looking through the working directory. If you want it extended to start with he root directory and work out with menus from there you’d have to do a lot of modifying of the function.

    The function finds only .txt .R and .Rnw files in the menu.

    Open <- function(method = menu) {
        wd<-getwd()
        on.exit(setwd(wd))
    
        x <- dir()
        x2 <- subset(x, substring(x, nchar(x) - 1, nchar(x)) == ".R" | 
            substring(x, nchar(x) - 3, nchar(x)) %in%c(".txt", ".Rnw"))
    
        if (is.numeric(method)) {      
            x4 <- x2[method]
            x5 <- as.character(x4)
            file.edit(x5)
        } else { 
            switch(method, 
                menu = { x3 <- menu(x2)
                         x4 <- x2[x3]
                         x5 <- as.character(x4)
                         file.edit(x5)
                        }, 
                look = file.edit(file.choose()))
        }
    }
    
    ##########
    #Examples
    #########
    Open()
    Open("L")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Are there any DHTMLX users out there? We have an app that is being
I want to allow users to either have there username field empty at any
Is there any real difference to screen reader users (or any users really) whether
Is there any way to restrict users with administrative privileges from managing specific Windows
Is there any reasonable method to allow users of a webapp to download large
Is there any way to enforce a template in Bugzilla to guide users fill
Hey guys, quick question for any experts out there. I am allowing users to
Is there any Win32/MFC API to get the CSIDL_LOCAL_APPDATA for any user that I
Apart from Sql server profiler ,is there any third party user friendly tool available
Is there any way to provide user log-in without the need for a DB.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.