2

I need a way to determine the description of an argument within R.

For example, if I'm using the function qplot() from the package ggplot2, I need to be able to extract a description of each argument in qplot(). From ggplot2's reference manual, it's easy to see that there are several arguments to consider. One of them is called "data", which is described as: "data frame to use (optional). If not specified, will create one, extracting vectors from the current environment."

Is there a way to get this information from within an R session, rather than by reading a reference manual? Maybe an R function similar to packageDescription(), but for a function's arguments?

Thanks!


edit: I found a variant on my question answered here:

How to access the help/documentation .rd source files in R?

Reading the .Rd files seems like the safest way to get the information I need. For anyone interested, the following code returns a list of arguments and their descriptions, where "package_name" can be any package you want:

db <- Rd_db("package_name")
lapply(db, tools:::.Rd_get_metadata, "arguments")

Thank you for your help, everyone.

Community
  • 1
  • 1
RedShift
  • 275
  • 1
  • 9
  • 3
    The `args()` function will list all the function arguments (e.g. `args(qplot)`. But I'm not sure if that's what you want. You can also access the help file for a function from the command line with ?function (e.g. `?qplot`). Finally, `formals()` will extract the function arguments as a list if you wish to use them programmatically (e.g. `formals(qplot)`). – matt_k Feb 08 '14 at 23:36
  • @matt_k I'm aware of the functions that exist for determining the names of arguments, but I'm looking for something that returns their descriptions. Right now, my best solution is to convert a package's reference manual from pdf format to txt and scan for the "Arguments" section. But that approach is somewhat error-prone. – RedShift Feb 09 '14 at 00:00
  • 1
    R's help pages are written in `.Rd` format. That is then displayed by the chosen browser. You need to read up on that format rather than trying to decompile a pdf version. Examine the output of `\`?\``. – IRTFM Feb 09 '14 at 00:51
  • 1
    Back to the question: why exactly do you need this? I shudder to think what would happen if you were to use , e.g., `par()` . I strongly recommend against doing what you're asking for. – Carl Witthoft Feb 09 '14 at 01:08

1 Answers1

0

From the R console in the Mac GUI R.app ... When I look at the text output from help'seq', help_type="text") (which goes to a temporary file) I see that the beginning of hte descriptions you want are demarcated by:

_A_r_g_u_m_e_n_t_s:   # Those underscores were ^H's before I pasted

And then the arguments appear in are name:description pairs:

     ...: arguments passed to or from methods.

from, to: the starting and (maximal) end values of the sequence.  Of
          length ‘1’ unless just ‘from’ is supplied as an unnamed
          argument.

      by: number: increment of the sequence.

length.out: desired length of the sequence.  A non-negative number,
          which for ‘seq’ and ‘seq.int’ will be rounded up if
          fractional.

along.with: take the length from the length of this argument.

When I use a Terminal session to get that same output it appears in the same window but as a Unix help page like:

Arguments:

     ...: arguments passed to or from methods.

from, to: the starting and (maximal) end values of the sequence.  Of
          length ‘1’ unless just ‘from’ is supplied as an unnamed
          argument.

      by: number: increment of the sequence.

length.out: desired length of the sequence.  A non-negative number,
          which for ‘seq’ and ‘seq.int’ will be rounded up if
          fractional.

along.with: take the length from the length of this argument.

I believe these are displayed by whatever system program is called by the value of options("pager"). In my case, that is the program "less".

IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • Is there any way to access these help files programmatically? For example, is it possible to save the descriptions as character objects? – RedShift Feb 09 '14 at 01:40