本文介绍了如何访问R中的帮助/文档.rd源文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在R中,一个非常整洁的功能是可以在工作区中的对象访问函数的源代码。

In R, one very neat feature is that the source code of functions is accessible as objects in the workspace.

因此,如果我想知道源代码例如, grep()我可以直接在控制台中输入 grep 并阅读代码。

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.

同样,我可以通过键入?grep grep 的文档>进入控制台。

Similarly, I can read the documentation for grep by typing ?grep into the console.

问题:如何获取函数文档的源代码?换句话说,我在哪里可以找到.rd文件?

我发现学习写好代码的源代码是学习习语的好方法。现在我想研究如何为一些非常具体的案例编写文档。我无法在R安装中找到任何基本R功能的文档文件。也许我一直在错误的地方。

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.

推荐答案

似乎你可以从安装的R中提取Rd源。 m使用R-devel(2011-09-05 r56942)。

It seems you can extract the Rd sources from an installed R. I'm using R-devel (2011-09-05 r56942).

获取基础包的Rd数据库。

Get the database of Rd for the base package.

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

在Rd DB的名称中搜索grep.Rd,例如:

Search for "grep.Rd" in the names of the Rd DB, for example:

grep("grep.Rd", names(db), value = TRUE)
[1] "d:/murdoch/recent/R64/src/library/base/man/agrep.Rd"
[2] "d:/murdoch/recent/R64/src/library/base/man/grep.Rd"

只需要grep的Rd对象。

Get just the Rd object for grep.

db[grep("/grep.Rd", names(db))]
$`d:/murdoch/recent/R64/src/library/base/man/grep.Rd`
\title{Pattern Matching and Replacement}
\name{grep}
\alias{grep}
\alias{grepl}
\alias{sub}
\alias{gsub}
\alias{regexpr}
\alias{gregexpr}
\alias{regexec}
\keyword{character}
\keyword{utilities}
\description{
\code{grep}, \code{grepl}, \code{regexpr} and \code{gregexpr} search
for matches to argument \code{pattern} within each element of a
character vector: they differ in the format of and amount of detail in
the results.

\code{sub} and \code{gsub} perform replacement of the first and all
matches respectively.
}\usage{
...
...

有从Rd对象获取组件的工具,因此您可以将关键字或名称的搜索精简,请参阅?Rd_db中的示例,然后尝试这样做。

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.

lapply(db, tools:::.Rd_get_metadata, "name")

这篇关于如何访问R中的帮助/文档.rd源文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 03:16