Question Details

No question body available.

Tags

r r-package

Answers (12)

April 14, 2026 Score: 2 Rep: 47,351 Quality: Low Completeness: 10%

It's easy to see the fraction of help pages with examples, but you would also need to determine how many functions are documented in each one. The usage section should let you do that.

And there may be functions that aren't documented at all, either because they aren't exported or because they are methods that don't require documentation (or because the package author forgot).

April 14, 2026 Score: 1 Rep: 273,907 Quality: Medium Completeness: 60%

There can be multiple functions per Rd file and there can also be Rd files that do not correspond to functions so we will assume that what is wanted is the fraction of Rd files with examples.

1) Assuming that the current working directory is the directory with the DESCRIPTION file get the Rd files, Files, and then parse and extract the examples from each Rd file giving a list, exs. Finally calculate the fraction of exs components with examples.

library(tools) Files
April 14, 2026 Score: 1 Rep: 12,127 Quality: Low Completeness: 30%

Can you please elaborate on the last part? Not too sure how restrictive the filtering should be. R Core's {tools} ships a lot of helpful functions for such task.

April 14, 2026 Score: 1 Rep: 19,953 Quality: Low Completeness: 10%

Your question should include that you want information from the package associated help page, specifically the embedded examples. As it is right now one might think you mean packages total used libraries, includes etc.

April 14, 2026 Score: 1 Rep: 273,907 Quality: Low Completeness: 0%

As explained in the answer there is not necessarily a one-to-one correspondence between functions and Rd files so it makes more sense to do it by Rd file.

April 14, 2026 Score: 0 Rep: 78,441 Quality: Low Completeness: 10%

By trial and error? Copy the source code of the function you want to a new R session, run it, then use it. If it gives an error that it cannot find another function, copy that function's source, run it and iterate. This doesn't sound very scientific but will probably be faster than an alternative way.

April 14, 2026 Score: 0 Rep: 1,797 Quality: Low Completeness: 10%

What do you mean with "last part" specifically? "Without installing"? I don't want to install, because I would like to do this for thousands of packages, which will be a tax on runtime that I would like to prevent.

April 14, 2026 Score: 0 Rep: 1,797 Quality: Low Completeness: 0%

Assume looking at the function's help page. Does it contain an examples section or not? I need this for all functions within a package of interest.

April 14, 2026 Score: 0 Rep: 12,127 Quality: Low Completeness: 30%

This might be straigtforward, untar and search man/*.Rd files for @examples. tools::parse_Rd() might be helpful.

April 14, 2026 Score: 0 Rep: 12,127 Quality: Low Completeness: 40%

For this, one can scan the NAMESPACE-file, e.g. readLines(), grepv() for pattern="export", then a simple sub()-call (sub('^export\\((.)\\)$', '\\1', x=_)) with partial matching to combine with those functions having examples tags in .Rd-files.

April 14, 2026 Score: 0 Rep: 1,797 Quality: Low Completeness: 0%

I've reformulated a bit. Is it clearer now?

April 14, 2026 Score: 0 Rep: 47,351 Quality: Low Completeness: 40%

S3 methods use a different style of exporting, e.g. S3method(someclass, print). That might be documented in a help page with alias print.someclass, but it can be skipped entirely, as can methods for any of the other object systems in R (S4, R5, R7, etc).