0

I am looking for a way to autocomplete an argument of a function while typing (i.e. with tab).

For example, let say I have a function f with an argument name and I want to be able to autocomplete name from a list of possible names c("AAA","BBBBB","C") and as I am typing on the terminal

f(name="A

if I hit tab then it should autocomplete to

f(name="AAA"

and continue typing more arguments the function may need.

The solution so far is defining the list with select.list:

f<-function(name=select.list(c("AAA","BBBBB","C")),graphics=FALSE),other arguments...)

and let the user select the name from the list that is displayed immediately after calling the function, but I want to avoid doing this since the list may be quite large.

PS I found the function select.list after reading the question R Prompt User With Autocomplete

Community
  • 1
  • 1
Oliver Lopez
  • 220
  • 1
  • 8

1 Answers1

0

This kind of thing is best left to the editor of your choice.

However, R can perform partial matching on for named arguments using match.arg so you don't need to autocomplete anyway.

x <- function(x =c('aa','b')) return(match.arg(x))
x('a')
# [1] "aa"
x('b')
[1] "b"
x('c')
# Error in match.arg(x) : 'arg' should be one of “aa”, “b” 
mnel
  • 113,303
  • 27
  • 265
  • 254