Matias Andina
Matias Andina

Reputation: 4220

Writing help information for user defined functions in R

I frequently use user defined functions in my code. RStudio supports the automatic completion of code using the Tab key. I find this amazing because I always can read quickly what is supposed to go in the (...) of functions/calls.

However, my user defined functions just show the parameters, no additional info and obviously, no help page. This isn't so much pain for me but I would like to share code I think it would be useful to have some information at hand besides the #coments in every line.

Nowadays, when I share, my lines usually look like this

myfun <- function(x1,x2,x3,...){

# This is a function for this and that

# x1 is a factor, x2 is an integer ...
# This line of code is useful for transformation of x2 by x1
  some code here
# Now we do this other thing
  more code
# This is where the magic happens
  return (magic)
}

I think this line by line comment is great but I'd like to improve it and make some things handy just like every other function.

Upvotes: 2

Views: 440

Answers (1)

IRTFM
IRTFM

Reputation: 263311

Not really an answer, but if you are interested in exploring this further, you should start at the rcompgen-help page (although that's not a function name) and also examine the code of:

rc.settings

Also, executing this allows you to see what the .CompletionEnv has in it for currently loaded packages:

names(rc.status())
#-----
 [1] "attached_packages" "comps"             "linebuffer"        "start"            
 [5] "options"           "help_topics"       "isFirstArg"        "fileName"         
 [9] "end"               "token"             "fguess"            "settings"  

And if you just look at:

rc.status()$help_topics

... you see the character items that the tab-completion mechanism uses for matching. On my machine at the moment there are 8881 items in that vector.

Upvotes: 1

Related Questions