ialm ialm - 1 month ago 12
R Question

Is it possible to get RStudio to show function arguments and descriptions for custom functions?

The code completion in RStudio is great, and I really like how a popover appears to describe the arguments for the function inputs. For example, if one types

matrix(
and then presses "tab", a list of arguments for the
matrix()
function appears, along with a description of the input. Say,
nrow=
is selected, then the adjoining window describes the
nrow
input as "the desired number of rows.".

Can I get RStudio to do this for my custom functions? Would I have to create a package to achieve this effect?

Say I have a file full of custom functions,
myCustomFunctions.R
, and I store all my miscellaneous helper functions in there. I want to be able to add meta data for my functions so that this helper window also describes my function inputs.

Answer

To add to Hadley's answer in the comments, Rstudio is mining specific portions of the help files to generate the helper window. Specifically, tabbing before the parentheses brings up the "Usage" and "Description" sections and tabbing inside the parentheses or after a comma brings up the "Arguments" section. Therefore, not only does a package need to be made, but the help files must be generated to take advantage of this feature.