In golfing, one tries to complete a puzzle in as few characters as possible, generally using the base language only. One trick for golfing in R is to use partial completion so that e.g. rle(...)$length
can be shortened to rle(...)$l
. How does one turn on function name completion in R, preferably in as few characters as possible?
How do I turn on function name completion?
561 Views Asked by Ari B. Friedman At
2
There are 2 best solutions below
0

Inspired by @Ian, here is a golf version of @Ian's answer. The concept is similar but use some R-ish hack (i.e., call tree manipulation)
`?`<-function(o)with(x<-as.list(substitute(o)),do.call(apropos(paste("^",deparse(x[[1]]),sep=""))[1],x[-1]))
try:
> ?me(1:5)
[1] 3
> a<-1;?as.ch(a)
[1] "1"
>
for golf, R
needs a shortcut of function
.
This overloads the help operator to provide the shortest object matching the regular expression provided. For example: