Enable file autocompletion in my functions

autocomplete

#1

Hi all,

I've been wondering if there is a way to enable file autocompletion in functions that we write?

For example, I sometimes specify a temp directory at the start of my script using a function, and later use it with load/save/etc., like this:

    tmpdir <- function(x) {
      paste0('/some/path/to/a/temp/dir/', x)
    }

    save(tmpdir('some_data.rda'))

and later when I do load(tmpdir('<TAB> I would like to see some_data.rda be suggested by autocomplete, much like it would be if I manually typed the full path to my temp directory. Any ideas?

Not sure if this is RStudio specific, might be.

Thanks!
Brian


#2

This has nothing to do with your question, but why don't you use the tempfile and tempdir functions?


#3

This is for cases when I can't use just any temporary directory. We have different file systems that are optimized for different needs of size, speed, and security. I may be abusing the notion of the term "temp" here, these are more like unfinished work in progress data pieces.


#4

If you are hoping to use this sort of feature inside RStudio, then yes I think this is an RStudio-specific question (and it might be a good idea to move this post to the #rstudio-ide category). Are you imagining this as a feature request, or something you want to implement yourself (such as an RStudio AddIn)? I’m not sure there’s enough exposed by rstudioapi right now to do exactly what you describe, but it might be possible to make an add-in that still helped automate this process.

That said, the path completion system will complete any file name within the current Project even if it’s in a sub-directory, so if your not-really-temp temp folders are within an RStudio Project structure, that might help?