r-s3

Using sd as a generic function in R

你说的曾经没有我的故事 提交于 2019-11-29 13:34:17
If I a have a class called foo , then it is straightforward to overload the summary function summary.foo = function(x, ...) print("bar") However this technique does not work with the sd function, that is > bar = createFooClass() > sd.foo = function(x, ...) print("Hi") > sd(bar) error: is.atomic(x) is not TRUE What is the correct way of overloading this function? You can hijack any non-generic function, make it (S3) generic and set the original version to be the default version. For example: ## make an S3 generic for sd sd <- function(x, ...) UseMethod("sd") ## take the usual definition of sd,

S3 method consistency warning when building R package with Roxygen

你。 提交于 2019-11-29 04:55:41
问题 I have created a roxygen file for a function that uses S3 an class. I roxygenize and then build and check and get a warning: * checking S3 generic/method consistency ... WARNING common: function(word.list, ...) common.list: function(word.list, overlap, equal.or) See section 'Generic functions and methods' of the 'Writing R Extensions' manual. So I spent time studying: http://cran.r-project.org/doc/manuals/R-exts.html#Generic-functions-and-methods & https://github.com/hadley/devtools/wiki/S3

Using sd as a generic function in R

天大地大妈咪最大 提交于 2019-11-28 07:28:53
问题 If I a have a class called foo , then it is straightforward to overload the summary function summary.foo = function(x, ...) print("bar") However this technique does not work with the sd function, that is > bar = createFooClass() > sd.foo = function(x, ...) print("Hi") > sd(bar) error: is.atomic(x) is not TRUE What is the correct way of overloading this function? 回答1: You can hijack any non-generic function, make it (S3) generic and set the original version to be the default version. For

What does “S3 methods” mean in R?

巧了我就是萌 提交于 2019-11-27 02:36:40
Since I am fairly new to R, I do not know what the S3 methods and objects are. I found that there are S3 and S4 object systems, and some recommend to use S3 over S4 if possible (http://google-styleguide.googlecode.com/svn/trunk/google-r-style.html). However, I do not know the exact definition of S3 methods/objects. Most of the relevant information can be found by looking at ?S3 or ?UseMethod , but in a nutshell: S3 refers to a scheme of method dispatching. If you've used R for a while, you'll notice that there are print , predict and summary methods for a lot of different kinds of objects. In

What does “S3 methods” mean in R?

不羁岁月 提交于 2019-11-26 12:34:33
问题 Since I am fairly new to R, I do not know what the S3 methods and objects are. I found that there are S3 and S4 object systems, and some recommend to use S3 over S4 if possible (http://google-styleguide.googlecode.com/svn/trunk/google-r-style.html). However, I do not know the exact definition of S3 methods/objects. 回答1: Most of the relevant information can be found by looking at ?S3 or ?UseMethod , but in a nutshell: S3 refers to a scheme of method dispatching. If you've used R for a while,