Tyler Rinker
Tyler Rinker

Reputation: 109844

Get loaded package's function X title programmatically

How can I get the title of a function from a loaded package programmatically? For example ?mean tells me Arithmetic Mean and ?sd's title is Standard Deviation. How could I use R to return "Arithmetic Mean" given the function name mean?

Upvotes: 5

Views: 78

Answers (1)

LyzandeR
LyzandeR

Reputation: 37879

You can do it using the following:

You will need the Rd_db function from the tools package to find the rd file of one of the functions (the mean in this case):

library(tools)
db <- Rd_db("base")

Then save in a variable the .Rd file of interest

therd <- db[grep("mean.Rd", names(db), value = TRUE)]

Finally just print the Title

> c(therd$mean.Rd[[1]][[1]])
[1] "Arithmetic Mean"

In the same way you can actually print other parts of the .Rd file like the description, value etc.

Upvotes: 4

Related Questions