在 R 中查找您需要的内容:在 R 和所有 (3,500+) CRAN 包中集中搜索

发布于 2024-08-13 00:16:04 字数 1006 浏览 2 评论 0原文

通常在 R 中,有十几个函数分散在许多包中——所有这些函数都有相同的目的,但当然在准确性、性能、文档、理论严谨性等方面有所不同。

您如何从 R 内部甚至从您尚未安装的 CRAN 软件包中找到这些内容?

例如:通用的 plot 函数。使用基础包外部的函数设置辅助刻度要容易得多:

minor.tick(nx=n, ny=n, tick.ratio=n)

当然plot位于R核心中,但minor.tick不是,它实际上在Hmisc中。

当然,这不会出现在 plot 的文档中,您也不应该期望它出现。

另一个例子:plot的数据输入参数可以由函数hexbin返回的对象提供,同样,该函数来自外部库> R 核心。

显然,最好的方法是通过编程方式从各个库中收集这些函数参数并将它们放入单个命名空间中?

*编辑:(尝试更清楚地重述上面的示例:)R 核心中提供的 plot 参数,例如,设置轴刻度频率是 xaxp/yaxp;然而,我们也可以通过基础包之外的函数设置 a/t/f,就像 Hmisc 包中的minor.tick 函数一样——但仅仅通过查看绘图方法签名你不会知道这一点。 R 中有为此的元函数吗?*

到目前为止,当我遇到它们时,我一直在手动收集它们,每组都收集在一个 TextMate snippet (以及随之而来的库导入)。这并不是那么困难或耗时,但是当我发现这些附加参数/参数时,我只能更新我的代码片段。是否有规范的 R 方法可以做到这一点,或者至少有一种更简单的方法?

以防万一不清楚,我不是在谈论多个包提供针对相同统计数据或视图的函数的情况(例如,基础包中的“boxplot”;gplots 中的“boxplot.matrix”;以及“bplots”) ' 在 Rlab 中)。我所说的是两个或多个包中函数名称相同的情况。

Often in R, there are a dozen functions scattered across as many packages--all of which have the same purpose but of course differ in accuracy, performance, documentation, theoretical rigor, and so on.

How do you locate these--from within R and even from among the CRAN Packages which you have not installed?

So for instance: the generic plot function. Setting secondary ticks is much easier using a function outside of the base package:

minor.tick(nx=n, ny=n, tick.ratio=n)

Of course plot is in R core, but minor.tick is not, it's actually in Hmisc.

Of course, that doesn't show up in the documentation for plot, nor should you expect it to.

Another example: data-input arguments to plot can be supplied by an object returned from the function hexbin, again, this function is from a library outside of R core.

What would be great obviously is a programmatic way to gather these function arguments from the various libraries and put them in a single namespace?

*edit: (trying to re-state my example just above more clearly:) the arguments to plot supplied in R core, e.g., setting the axis tick frequency are xaxp/yaxp; however, one can also set a/t/f via a function outside of the base package, again, as in the minor.tick function from the Hmisc package--but you wouldn't know that just from looking at the plot method signature. Is there a meta function in R for this?*

So far, as i come across them, i've been manually gathering them, each set gathered in a single TextMate snippet (along with the attendant library imports). This isn't that difficult or time consuming, but i can only update my snippet as i find out about these additional arguments/parameters. Is there a canonical R way to do this, or at least an easier way?

Just in case that wasn't clear, i am not talking about the case where multiple packages provide functions directed to the same statistic or view (e.g., 'boxplot' in the base package; 'boxplot.matrix' in gplots; and 'bplots' in Rlab). What i am talking is the case in which the function name is the same across two or more packages.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

方觉久 2024-08-20 00:16:04

sos”包是一个很好的资源。它的主要接口是“findFn”命令,它接受一个字符串(您的搜索词)并扫描 Johnathan Baron 的站点搜索数据库中的“函数”条目,并返回包含搜索词的条目数据框(属于“findFn”类)。

该数据框的列是:CountMaxScoreTotalScorePackageFunction strong>、日期分数描述链接。单击任何条目行中的“链接”将立即拉出帮助页面。

举个例子:假设您想要查找所有 1800+ R 包中的所有卷积滤波器。

library(sos)
cf = findFn("convolve") 

此查询将查找术语“卷积”,换句话说,它不一定是函数名称。

键入“cf”会返回找到的所有匹配项的 HTML 表(本例中为 23 个)。该表是我上面提到的数据框的 HTML 呈现。特别方便的是,每一列(“Count”、“MaxScore”等)都可以通过单击列标题进行排序,因此您可以按“Score”、“Package Name”等查看结果。

(如顺便说一句:当运行这个确切的查询时,结果之一是名为“latticeExtra”的包中的函数“panel.tskernel”,我不知道这个包中有任何时间序列过滤器,我怀疑我是否会发现它。否则。

The "sos" package is an excellent resource. It's primary interface is the "findFn" command, which accepts a string (your search term) and scans the "function" entries in Johnathan Baron's site search database, and returns the entries that contain the search term in a data frame (of class "findFn").

The columns of this data frame are: Count, MaxScore, TotalScore, Package, Function, Date, Score, Description, and Link. Clicking on "Link" in any entry's row will immediately pull up the help page.

An example: suppose you wanted to find all convolution filters across all 1800+ R packages.

library(sos)
cf = findFn("convolve") 

This query will look the term "convolve", in other words, that doesn't have to be the function name.

Keying in "cf" returns an HTML table of all matches found (23 in this case). This table is an HTML rendering of the data frame i mentioned just above. What is particularly convenient is that each column ("Count", "MaxScore", etc.) is sortable by clicking on the column header, so you can view the results by "Score", by "Package Name", etc.

(As an aside: when running that exact query, one of the results was the function "panel.tskernel" in a package called "latticeExtra". I was not aware this package had any time series filters in it and i doubt i would have discovered it otherwise.

〃温暖了心ぐ 2024-08-20 00:16:04

你的问题不容易回答。不存在一种确定的函数。

formals 是为函数提供命名 参数及其在命名列表中的默认值的函数,但您始终可以通过 ...< /code> 参数和带有嵌入 hadArg 函数的隐藏命名参数。要获取这些列表,您必须使用 getAnywhere,然后扫描 hasArg 的表达式。我想不出一种自动的方法来自己做这件事。也就是说,如果函数隐藏参数没有记录。

Your question is not easy to answer. There is not one definitive function.

formals is the function that gives the named arguments to a function and their defaults in a named list, but you can always have variable arguments through the ... parameter and hidden named arguments with embedded hadArg function. To get a list of those you would have to use a getAnywhere and then scan the expression for the hasArg. I can't think of a automatic way of doing it yourself. That is if the functions hidden arguments are not documented.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文