How to open working directory directly from R console?

If you actually want a file browser you could create a function to open the directory. This is done differently based on the operating system you're using but this should cover most bases

opendir <- function(dir = getwd()){
    if (.Platform['OS.type'] == "windows"){
        shell.exec(dir)
    } else {
        system(paste(Sys.getenv("R_BROWSER"), dir))
    }
}

If you don't need it to be cross platform you can reduce it down to just the code for your OS. But if you just want to view the files in a given directory then using dir should be good enough.


You can use dir() or list.files() to display the files in the current working directory or file.choose() to browse the directory and choose a file. All three default to the current working directory.

Tags:

R