1

I'd like to get the text of the documentation of all the arguments of all functions in R which have as name data. How would I need to do this?

So if I have a function e.g. MASS::truehist, I would like to get the text next to argument data in the documentation in R as a string. So that would be "numeric vector of data for histogram. Missing values (NAs) are allowed and omitted." How do I do that? The following shows me that there is an argument called data. But how to retrieve in R (not just in the help environment) the text of that documentation?

formals(MASS::truehist)
  • @hrbrmstr. Thanks for the link. Indeed duplicate! –  Nov 30 '18 at 14:32
  • 1
    . that one is kind of hard to search for (or get search results to bubble it up) but I do quite a bit of research CRAN itself (CRAN mirror at home) and that link is in more than a few scripts of mine to as a reference to give credit where due ;-) – hrbrmstr Nov 30 '18 at 14:34

1 Answers1

3

You can extract help file as text:

helptext <- help(truehist, package=MASS)
tools:::Rd2txt(utils:::.getHelpFile(as.character(helptext)))

After you get the file you can easily find the arguments part, search for "data:" and retrieve the following text.

Aaro Viertiö
  • 219
  • 1
  • 5
  • Thanks for the code. Works equally fine. Wasn't aware that a solutions was already given at https://stackoverflow.com/questions/7495685/how-to-access-the-help-documentation-rd-source-files-in-r –  Nov 30 '18 at 14:34