rep的文档是否告诉我们这是一个内部泛型函数? [英] Does the documentation for rep tell us that it is an internal generic function?

查看:69
本文介绍了rep的文档是否告诉我们这是一个内部泛型函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为它位于列表中内部通用函数,我知道 rep 是内部通用函数.仅通过阅读 the代表文件?我找到了以下两个相关的部分:

Because it is on the list of Internal Generic Functions, I know that rep is an internal generic function. Could this fact have been derived by only reading the documentation for rep? I have located the following two relevant-looking sections:

rep复制x中的值.这是一个泛型函数,此处介绍(内部)默认方法.

rep replicates the values in x. It is a generic function, and the (internal) default method is described here.

对于内部默认方法,这些可以包括:

For the internal default method these can include:

这两个方法是否都明确告诉读者 rep 是内部泛型函数?

Do either of these specifically tell the reader that rep is an internal generic function?

要完全清楚,我要问的是这些摘录中使用的术语.我不是R术语的专家,所以我要问的是它们所使用的词所隐含的含义.例如,如果R文档说函数是通用的",则返回"0".并具有内部默认方法",是否表示该函数因此是内部通用函数?

To be totally clear, I'm asking about the terminology that is used in these extracts. I'm not an expert on R's terminology, so what I'm asking is about what is implied by the words that they've used. For example, if the R documentation says that a function "is generic" and has an "internal default method", does that mean that the function is therefore an internal generic function?

指向某种R术语表或R手册之一中的相关部分的链接,将是一个很好的答案的非常有力的组成部分.一个简单的是或否可能就不够.

A link to some sort of glossary of R terms, or the relevant section in one of the R manuals, would be a very strong component of a good answer. A simple yes or no will probably not suffice.

推荐答案

首先,我认为您将从以下资源( 15.7通用函数OO

Firstly, I think you would benefit from the following resource (15.7 Generic-Function OO, https://homerhanumat.github.io/r-notes/generic-function-oo.html).

其次,一些定义(摘录自 https://homerhanumat.github.io/r-notes/glossary-12.html https://colinfay.me/r-internals/internal-vs-primitive.html ):

Secondly, some definitions (extracted from https://homerhanumat.github.io/r-notes/glossary-12.html and https://colinfay.me/r-internals/internal-vs-primitive.html):

泛型函数:一种基于输入的类将输入对象分派到许多方法函数之一的函数".

Generic function: "A function that dispatches an input object to one of a number of method-functions, based on the class of the input".

Generic-Function OO :一种面向对象的程序设计,其中的任务由通用功能执行.用于执行特定任务的方法由输入对象"的类确定.

Generic-Function OO: "A type of object-oriented programming in which tasks are performed by generic functions. The method used to perform a particular task is determined by the class of the input object".

原始函数和内部函数:可以在称为 primitives 的情况下直接调用构建时编译为R的C代码,也可以通过 .Internal 接口,它与 .External 接口非常相似,但语法."除外.

Primitive and Internal functions: "C code compiled into R at build time can be called directly in what are termed primitives or via the .Internal interface, which is very similar to the .External interface except in syntax".

因此,我们可以这样说:

Thus, we can say that:

内部泛型函数:泛型的原始和内部函数(例如,根据输入的类将输入对象分派到许多方法函数之一的函数).

Internal Generic function: Primitive and internal functions that are generic (e.g. function that dispatches an input object to one of a number of method-functions, based on the class of the input).

现在,回答您的问题:

a)文档清晰吗?

这是通用函数,并且在此描述(内部)默认方法".它明确指出 rep 是一个泛型函数.(内部)"一眼就知道这是一个内部/原始函数.围绕内部括号的需求是什么?我其实不知道.如果声明,则肯定会更清楚:" rep 属于内部通用函数的类别(请参见 InternalMethods ).默认方法的细节在这里描述".但是,对于 rep.int rep_len 来说,它会更清晰一些(内部,它们是通用的").编写好的文档总是很难!

"It is a generic function, and the (internal) default method is described here". It clearly states that rep is a generic function. The "(internal)" sort of glimpses that it is a internal/primitive function. What is the need for the parenthesis around internal? I actually do not know. It would certainly be clearer if it stated: "rep falls under the category of internal generic functions (see InternalMethods). Details on the default methods are described here". However, for rep.int and rep_len it is a bit clearer ("Internally, they are generic"). Writing good documentation is always hard!

b)如何凭经验找出函数是否为内部通用

依靠文档并不能总是保证成功.对于CRAN提供的多种R包,这确实是正确的.但是,该主题不仅是随机的R程序包,而且是低级的R编程语言.在阅读 rep 的源代码后,我们可以确认rep是原始函数:

Relying on documentation does not always guarantee success. This is certainly true for the huge diversity of R-packages offered at CRAN. But, this topic is not just a random R-package but low level R-programming language. Reading rep's source code you, we can confirm that rep is a primitive function:

> rep
function (x, ...)  .Primitive("rep")

然后运行以下命令,我们可以确认 rep 是通用函数:

And by running the following, we can confirm that rep is a generic function:

> methods(rep)
[1] rep.bibentry*       rep.Date            rep.factor          rep.numeric_version rep.POSIXct        
[6] rep.POSIXlt         rep.roman*

因此, rep 必须是内部通用函数.只是为了提供一个否定的控件(非通用函数的方法输出),请参见以下内容:

Therefore, rep must be an internal generic function. Just to provide a negative control (the output of methods for a function that is not generic), see below:

> methods(diag)
no methods found

c)R-CRAN资源

最后,CRAN在这里汇编R编程语言(cran.r-project.org/doc/manuals/r-release/R-lang.html)的定义方面做得很好.关于"5面向对象编程"部分有更多的信息.但是上面提供的资源更具教学意义.CRAN提供了一些您可能会感兴趣的手册(cran.r-project.org/manuals.html).

Finally, CRAN did do a great job compiling the definition of the R-programming language here (cran.r-project.org/doc/manuals/r-release/R-lang.html); There is much more information on section "5 Object-oriented programming". But resources provided above are a bit more didactical. CRAN offers several manuals which may be of your interest (cran.r-project.org/manuals.html).

这篇关于rep的文档是否告诉我们这是一个内部泛型函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆