Displaying 20 results from an estimated 5000 matches similar to: "class"
2010 Sep 30
1
Assignment to a slot in an S4 object in a list seems to violate copy rules?
Dear R-developers
I came across the following issue, which I find strange:
setClass("A", representation(a = "numeric"))
B <- list()
myA <- new("A", a = 1)
B$otherA <- myA
B$otherA at a <- 2
myA at a
Assigning a new value to slot 'a' in the _copy_ of myA stored
in B$otherA changes the original value of myA -- this was
surprising to me, and I
2006 May 11
2
S4 initialize methods, unexpected recursive callNextMethod
Hi,
Given a simple three class hierarchy: A <-- B <-- C
I want to define an initialize method for each class such that when I
call new("C", x=5), the initialize methods for A and B are used to
incrementally build the object.
When I do what seems obvious to me using callNextMethod, I get an
infinite recursion. An example follows...
setClass("A",
2012 Oct 17
1
Do *not* pass '...' to NextMethod() - it'll do it for you; missing documentation, a bug or just me?
Hi,
although I've done S3 dispatching for more than a decade now, I think
I managed to overlook/avoid the following pitfall when using
NextMethod():
If you explicitly pass argument '...' to NextMethod(), you will
effectively pass those argument twice to the "next" method!
EXAMPLE:
foo0 <- function(...) UseMethod("foo0");
foo1 <- function(...)
2004 Oct 28
1
Another problem with next method
I have another problem with NextMethod. Not sure if its related
to the last problem.
In this example, we have a generic called ff with methods
for AsIs and test classes. We call the generic with an
object of AsIs class. The corresponding method adds 1 to it
and then changes the class to test followed by issuing a
NextMethod. However, that results in this error (using R
2.0.0, 2004-10-04
2010 Feb 14
1
NextMethod() example from S Programming by Venables and Ripley (page 78)
S Programming by Venables and Ripley (page 78) has the example listed
at the end of this email. However, I get the following error when I
try the example. I don't understand the descriptions of NextMethod on
its help page. Could somebody let me know how to fix the error of this
example?
> test(x)
c1
c2
Error in NextMethod() : no method to invoke
Calls: test -> test.c1 -> NextMethod
2018 Feb 22
2
How to modify dots and dispatch NextMethod
The example is invoking NextMethod via an anonymous function, which is
not allowed (see documentation for NextMethod). Normally one gets a
runtime error "'NextMethod' called from an anonymous function", but not
here as the anonymous function is called via do.call. I will fix so that
there is a runtime error in this case as well, thanks for uncovering
this problem.
I
2018 Feb 22
2
How to modify dots and dispatch NextMethod
On 02/22/2018 12:07 PM, I?aki ?car wrote:
> 2018-02-22 10:29 GMT+01:00 Tomas Kalibera <tomas.kalibera at gmail.com>:
>> The example is invoking NextMethod via an anonymous function, which is not
>> allowed (see documentation for NextMethod).
> Thanks for your response. I definitely missed that bit.
>
>> Normally one gets a runtime
>> error
2010 Jul 27
2
Documenting different OO-aproaches in R as a package?
Hello,
I see some people including myself confused by the different object-oriented
approaches in R (S3, S4, OOP, R.oo etc.).
Would it be ok to collect examples and solutions for the different OO-packages
in one package and add a vignette for documentation?
(assuming I find time for this task)
I mean in this case the package would not add data or functionality to R or
serve as a companion
1999 Apr 16
1
NextMethod
>> One clear moral seems to be don't do anything more inside a
>> generic function than you really need to do. Keep it *very*
>> simple indeed.
>>
> I recall JMC saying something like, all generic functions
> should be one line long; a call to the appropriate UseMethod.
It certainly is encouraging to know that others also have been confused by
aspects of
2010 Jul 04
1
Fwd: Functional programming and R: Recommendations?
Hello R list members,
I have a good object-oriented programming and software engineering background
(mostly Java) and know some R.
I'd like to learn more about functional programming concepts and its support
and application in R. Do you have any recommendations (books, links etc)?
I read (and like) "Programming in Scala" (Odersky) and just ordered
"Funktionale
2006 Mar 07
3
Making an S3 object act like a data.frame
"[.ggobiDataset" <- function(x, ..., drop=FALSE) {
x <- as.data.frame(x)
NextMethod("[", x)
}
"[[.ggobiDataset" <- function(x, ..., drop=FALSE) {
x <- as.data.frame(x)
NextMethod("[[", x)
}
"$.ggobiDataset" <- function(x, ..., drop=FALSE) {
x <- as.data.frame(x)
NextMethod("$", x)
}
> class(x)
[1]
2005 May 23
2
Documentation of S3 and S4 classes, inheritance
I'd like to have a class A that computes a likelihood, and a subclass B
that computes the same likelihood by sometimes throws in an additional
term (B includes measurement error).
So B's likelihood needs to call A's, and then (sometimes) multiply by an
additional term.
It sounds as if, in the S3 scheme, NextMethod is supposed to do this:
like.A <- function(stuff) compute value
2019 Aug 07
1
NextMethod() and argument laziness
Hi all, I'd like to ask if the following behavior is a bug. To me it
certainly feels surprising, at the very least. In this example, I would
like to call NextMethod() from my `child` object, have `cols` be left
untouched, and then substitute(cols) in the parent method. It works when
you use a `parent` object (as expected), but I would have also expected to
get `mpg` back when calling it from
2018 Feb 20
2
How to modify dots and dispatch NextMethod
Hi all,
Not sure if this belongs to R-devel or R-package-devel. Anyways...
Suppose we have objects of class c("foo", "bar"), and there are two S3
methods c.foo, c.bar. In c.foo, I'm trying to modify the dots and
forward the dispatch using NextMethod without any success. This is
what I've tried so far:
c.foo <- function(..., recursive=FALSE) {
dots <-
2006 Apr 14
3
The object argument of NextMethod.
My question is when the object argument of NexthMethod be used?
In the following example, weather object argument is used will not
affects the result.
###
foo=function(x) {UseMethod("foo")}
foo.cls1=function(x)
{
x=x+1;class(x)<-"ncls"
NextMethod()
}
foo.ncls=function(x)
{
cat("ncls\n")
}
foo.cls2=function(x)
{
cat("cls2\n");print(x)
}
2024 Sep 21
1
model.matrix() may be misleading for "lme" models
Dear Prof. John Fox,
? Sat, 21 Sep 2024 12:47:49 -0400
John Fox <jfox at mcmaster.ca> ?????:
> NextMethod(formula(object), data=eval(object$call$data),
> contrasts.arg=object$contrasts)
The use of NextMethod worries me a bit. It will work as intended as
long as everyone gives fully-named arguments to the generic, without
relying on positional or partial
2024 Sep 21
1
model.matrix() may be misleading for "lme" models
Dear list members,
After further testing, I found that the following simplified version of
model.matrix.lme(), which omits passing xlev to the default method, is
more robust. The previous version generated spurious warnings in some
circumstances.
model.matrix.lme <- function(object, ...){
data <- object$data
if (is.null(data)){
NextMethod(formula(object),
2001 Dec 11
4
crash bug in get("function.name")() (PR#1211)
R : Copyright 2001, The R Development Core Team
Version 1.3.1 (2001-08-31)
> tmp <- factor(1:3)
> get("print.factor")(tmp)
[1] 1 2 3
Levels: 1 2 3
> print.a <- function(x,...) {
+ print("this is a")
+ NextMethod("print", x, quote = FALSE, right = TRUE, ...)
+ }
>
> get("print.a")
function(x,...) {
print("this is a")
2017 Nov 20
2
Small performance bug in [.Date
Hi all,
I think there's an unnecessary line in [.Date which has a considerable
impact on performance when subsetting large dates:
x <- Sys.Date() + 1:1e6
microbenchmark::microbenchmark(x[1])
#> Unit: microseconds
#> expr min lq mean median uq max neval
#> x[1] 920.651 1039.346 3624.833 2294.404 3786.881 41176.38 100
`[.Date` <- function(x, ...,
2006 Sep 22
2
behavior of [<-.foo
Can someone help me understand the following behavior of "[<-" ?
If I define a simple class based on a matrix, the [<- operation only
inserts into the first column:
> x <- matrix(rnorm(10),nrow=5,ncol=2)
> class(x) <- "foo"
> "[<-.foo" <- function(x, i, j, value) {
+ if(missing(i)) i <- 1:nrow(x)
+ if(missing(j)) j <-