24

インタラクティブな環境内から、Rパッケージのソース(またはパッケージ内のメソッド)を表示する簡単な方法はありますか?

4

4 に答える 4

19

関数/メソッドの名前を括弧なしで入力するだけです。

R> base::rev.default 
function (x) 
if (length(x)) x[length(x):1L] else x
<environment: namespace:base>

R-ヘルプデスク-2006年10月のRNewsVolume6/4のソースへのアクセス参照してください。

于 2009-11-24T09:07:44.763 に答える
15

ソースコードを見つける方法は、関数の種類によって異なります。この関連する質問に対する私の答えを参照してください。

rcsが指摘したように、パッケージを指定する場合は、を使用できます::

> lattice::xyplot
function (x, data, ...) 
UseMethod("xyplot")
<environment: namespace:lattice>

パッケージのすべての関数がエクスポートされるわけではありません(つまり、公開されます)。これらについては、を使用する必要があります:::

> lattice::xyplot.formula
Error: 'xyplot.formula' is not an exported object from 'namespace:lattice'

> lattice:::xyplot.formula
function (x, data = NULL, allow.multiple = is.null(groups) || 
    outer, outer = !is.null(groups), auto.key = FALSE, aspect = "fill", 
    panel = lattice.getOption("panel.xyplot"), prepanel = NULL, 
    scales = list(), strip = TRUE, groups = NULL, xlab, xlim, 
    ylab, ylim, drop.unused.levels = lattice.getOption("drop.unused.levels"), 
    ..., lattice.options = NULL, default.scales = list(), subscripts = !is.null(groups), 
    subset = TRUE) 
{
    formula <- x
    dots <- list(...)
# etc.
于 2009-11-24T16:44:11.770 に答える
9

見たいメソッドを見つけるには、次のように記述します。methods(funcOfInterest)

時々それはに十分ではありませんprint(funcOfInterest.class)。それなら試してみてくださいprint(getAnywhere(funcOfInterest.class))

于 2009-11-24T15:45:19.317 に答える
2

https://cloud.r-project.org/src/contribからパッケージソースをダウンロードし、お気に入りのエディターで開きます。関数定義を見つけます(grepそのために使用できます)。時々あなたは同様に役に立つ紹介を見つけることができます。

于 2018-10-17T22:36:37.883 に答える