从帮助中获取 R 函数的文档作为字符串

get the documentation of an R function from the help as a string

我想获取 R 中名称为 data 的所有函数的所有参数的文档文本。我需要怎么做?

所以如果我有一个功能,例如MASS::truehist,我想将 R 文档中参数 data 旁边的文本作为字符串获取。那就是 "numeric vector of data for histogram. Missing values (NAs) are allowed and omitted." 我该怎么做? 下面向我展示了一个名为数据的参数。但是如何在 R 中检索 (不仅仅是在帮助环境中)该文档的文本?

formals(MASS::truehist)

您可以将帮助文件提取为文本:

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

获得文件后,您可以轻松找到参数部分,搜索 "data:" 并检索以下文本。