如何访问 R 中的帮助/文档 .rd 源文件?
在 R 中,一个非常巧妙的功能是函数的源代码可以作为工作区中的对象进行访问。
因此,如果我想知道 grep()
的源代码,我可以简单地在控制台中输入 grep
并读取代码。
同样,我可以通过在控制台中输入 ?grep
来阅读 grep
的文档。
问题:如何获取函数文档的源代码?换句话说,我在哪里可以找到 .rd 文件?
我发现研究编写良好的代码的源代码是学习习惯用法的绝佳方法。现在我想研究如何为一些非常具体的案例编写文档。我无法在 R 安装中找到任何基本 R 函数的文档文件。也许我一直在寻找错误的地方。
In R, one very neat feature is that the source code of functions is accessible as objects in the workspace.
Thus, if I wanted to know the source code of, for example, grep()
I can simply type grep
into the console and read the code.
Similarly, I can read the documentation for grep
by typing ?grep
into the console.
Question: How can I get the source code for the documentation of a function? In other words, where do I find the .rd files?
I find studying the source of well-written code an excellent way of learning the idioms. Now I want to study how to write documentation for some very specific cases. I have not been able to find the documentation files for any of the base R functions in my R installation. Perhaps I have been looking in the wrong place.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来你可以从已安装的 R 中提取 Rd 源。我正在使用 R-devel (2011-09-05 r56942)。
获取基础包的 Rd 数据库。
在 Rd DB 的名称中搜索“grep.Rd”,例如:
仅获取 grep 的 Rd 对象。
有一些工具可用于从 Rd 对象获取组件,因此您可以将搜索细化为关键字或名称,请参阅 ?Rd_db 中的示例并尝试此操作。
It seems you can extract the Rd sources from an installed R. I'm using R-devel (2011-09-05 r56942).
Get the database of Rd for the base package.
Search for "grep.Rd" in the names of the Rd DB, for example:
Get just the Rd object for grep.
There are tools for getting the components from the Rd objects, so you can refine searching to keywords or name, see examples in ?Rd_db and try this.