How to inherit autocomplete for arguments when using ellipsis (...)

64 Views Asked by At

I have a function foo with some documentation, using roxygen2.

#' @param a description a
#' @param b description b
foo <- function(a, b, c){
        cat(a, b, c)
    }

I have written a wrapper, foo_wrapper, whose help file inherit all parameters, but a, from foo. They show as expected in the help file.

#' @inheritDotParams foo -a
foo_wrapper <- function(a, ...){
    foo(a = "a", ...)
}

The autocomplete only show the arguments a and ... from foo_wrapper. How can I get it to suggest the parameters from foo instead, i.e. the same parameters that are in the help file from foo_wrapper? Found this issue which seem related, but not the same problem.

1

There are 1 best solutions below

1
user2554330 On

I think the best way to do that is to copy the parameter names, i.e. define foo_wrapper as

foo_wrapper <- function(a, b, c){
  foo(a = "a", b = b, c = c)
}

The autocomplete is usually based on the function definition, and @inheritDotParams has no effect on the function definition, it only affects the Rd documentation file that is produced.

If you are really determined to do it, you could use the methods described in ?rcompgen. For example, running

utils:::.addFunctionInfo(foo_wrapper = c("a", "b", "c"))

will cause the base R GUIs to offer all three arguments as completions. It appears that the RStudio completion code doesn't pay any attention to this. I don't know if there's a way to do it if you're using RStudio.