using RStudio I have noticed that, when calling a function, I can hit tab and a popup will appear with the possible parameters that can be chosen, e.g. if I type round(
and hit tab, x=
and digits=
will appear as possible choices. This also happens with the custom functions I write. The difference is that built-in functions popups also have comments and explanations regarding the individual parameters. Is it possible to recreate such a behavior with custom functions as well?
-
3put them in a package and write documentation for them in the package. – hrbrmstr Sep 30 '17 at 22:32
1 Answers
I see what you mean. If you write a customised function
foo = function(x,y) { ... }
Then you go foo(
and hit tab, the code completion pop-up menu will give you the options x =
and y =
. However, when you type an existing R function such as round(
, not only does tab give you the options, but there's an explanation beneath each variable, telling you its role in the function:
The only way I could think of doing this for your own functions is to package your functions in your own customised package, and to make sure the "help" documentations includes your functions' parameters. This is getting beyond the realm of a stackoverflow question, but I'll point you to a couple of blogs where I learned the basics of R packages.
The Not So Standard Deviation blog explains how to write a simple package with help documentation, which is precisely what you need to see your customised functions appear with explanations inside RStudio's autocomplete. In a nutshell, you'll need to install roxygen2
, devtools
and, with each customised function, you'll need to thoroughly comment the function like this :
(disclaimer: the goofy cat example is the blogger's, not mine)
Here's a more detailed tutorial on creating R packages, and here's another blog on getting organised with R packages. Good luck!

- 4,890
- 10
- 33
- 56
-
1Well, that was more complicated than expected... and very interesting! Sounds like it's time to step up my game! Your answer was very clear and complete, thank you :) – Max_IT Sep 30 '17 at 22:54
-
1If your list of customised functions is getting to be so long that you need code completion to help remind you what the variables do, then it's well worth the effort to start building your own packages. It's a bit of a learning curve at the start, but worth it – lebelinoz Sep 30 '17 at 22:56