search for: setreplacemethod

Displaying 20 results from an estimated 50 matches for "setreplacemethod".

2007 May 25
1
Question about setReplaceMethod
...avior that much. I'm wondering how to make this work? Any help would be really appreciated. Thank you. setClass("foo", representation(x="data.frame", y="character")) setGeneric("setX<-", function(this, value), standardGeneric("setX<-")) setReplaceMethod("setX", "foo", function(this,value) { this@x <- value }) setGeneric("generateFrame", function(this), standardGeneric("generateFrame")) setReplaceMethod("generateFrame", "foo", function(this) { frame <- read.csv(file="myfile.csv&...
2017 Jun 23
1
setReplaceMethod creates 'object' in the userworkspace
Hi, I recognized that the function 'setReplaceMethod' is creating a character vector in the user workspace having the name (e.g. "newClass") of the class used as value. If you can sort out a mistake by myself, I would like you to file a bug report. BBFN, Jonathan setClass("newClass", representation(value="numeric")...
2017 Jun 23
1
setReplaceMethod creates 'object' in the userworkspace
Hi, I recognized that the function 'setReplaceMethod' is creating a character vector in the user workspace having the name (e.g. "newClass") of the class used as value. If you can sort out a mistake by myself, I would like you to file a bug report. BBFN, Jonathan setClass("newClass", representation(value="numeric")...
2006 Oct 31
1
setReplaceMethod
...b(), as.brob(), as.numeric() and so forth (minimal self-contained code below). If x is numeric (1:10, say) and y is a brob, what is the best way to make x[5] <- y promote x to a brob in the same way as the complex example? Or is this not desirable for some reason? My first idea was to use setReplaceMethod("[",signature("ANY","brob"), ...) but this gives a seal error: Error in setMethod(paste(f, "<-", sep = ""), ..., where = where) : the method for function "[<-" and signature x="ANY", i="brob" is sealed and ca...
2017 Jun 27
0
[Rd] setReplaceMethod creates 'object' in the userworkspace
>>>>> Jonathan Fritzemeier <clausjonathan.fritzemeier at uni-duesseldorf.de> >>>>> on Fri, 23 Jun 2017 16:15:30 +0200 writes: > Hi, > I recognized that the function 'setReplaceMethod' is creating a > character vector in the user workspace having the name (e.g. "newClass") > of the class used as value. If you can sort out a mistake by myself, I > would like you to file a bug report. Yes, a mistake by yourself (and really not fit for R-devel, b...
2011 Dec 09
1
'callNextMethod' in a '[<-' function does not work ?
Hi the list, I try to use callNextMethod in a setteur ([<-) but it does not work. Any raison ? Any other option ? --- 8< ------------------ ### Class B0 ### setClass("B0" , representation(b0 = "numeric")) setReplaceMethod("[","B0",function(x,i,j,value){x at b0 <- -value}) a <- new("B0") a at b0 <- 3 a a["b0"] <- 3 a ### Class B1 ### setClass("B1", representation(b1 = "character"), contains = "B0") setReplaceMethod("[",&quo...
2003 Jul 26
2
How to make "<-" generic?
...doesn't work: > isGeneric("<-") [1] FALSE > setClass("A",representation(x = "numeric")) [1] "A" > setClass("B",representation(x = "numeric")) [1] "B" > myAssign.A <- function(x,value) + { return(x); } > setReplaceMethod("",c("A","B"),myAssign.A) [1] "<-" > ## because > ##> setReplaceMethod > ##function (f, ...) > ##setMethod(paste(f, "<-", sep = ""), ...) > ## and > isGeneric("<-") [1] TRUE > a <- new("A&...
2009 Oct 27
1
How to reduce key strokes when defining S4 classes?
I feel tedious when I define a S4 class and the methods. For each method, I have to call both setMethod and setGeneric (or both setReplaceMethod and setGeneric). I would like a more compact grammar so that I can reduce the key strokes. I'm wondering if there is a better way available. setClass( Class='A', representation=representation( x='numeric' ) ) setMethod( f='initialize',...
2003 May 23
1
isSeekable returns F on seekable file
Hi, Seems that on RWin 1.7.0 and 1.6.2 isSeekable returns F on binary files, while seek() works as expected on the same connection - see example below: > con = file(nm, "rb") > isSeekable(con) [1] FALSE > readBin(con, double(), 10) [1] 7.263824e-317 5.968155e-317 2.340685e-317 2.734062e-312 4.088386e-312 4.670335e-317 [7] 6.097545e-317 3.396341e-312 6.615484e-317
2011 Sep 14
1
S4 method dispatch
...obj) changes the class of obj and breaks with the error. I couldn't find a pattern when this happens, but have a few cases where it consistently breaks. Here's the code snippet: setGeneric("doNothing<-", function(object, value) standardGeneric("doNothing<-")) setReplaceMethod("doNothing", signature(object = "Spatial", value = "ANY"), function(object, value) object) dosth = function(obj) { cl1 = class(obj) doNothing(obj) = TRUE cl2 = class(obj) if (!identical(cl1, cl2)) { print(paste(cl1, cl2)) stopif...
2005 Mar 26
2
Is there a diferent way to do this?
Hi, I started creating a small class but I'm courious about how it is working. To create a instance of my class "Partri" I write this at Rgui: x <- new("Partri", name="Gilvan") and to change the slot "name" of this instance, I write: setName(x, newname="Justino") It is not working, because when I type "x" at Rgui, it shows
2008 Apr 02
1
"[<-" plus drop-type extra argument
...h 'NC' is the sum of x (in my application, calculating NC is an expensive multidimensional integral). setClass("foo", representation = representation(x="numeric" , NC="numeric"), prototype = list(x=double() , NC=NA_real_) ) setReplaceMethod("[",signature(x="foo"), function(x,i,j,recalculate=FALSE,value){ jj <- x at x jj[i] <- value if(recalculate){ return(new("foo" , x=jj , NC=sum(jj)))...
2007 Nov 13
5
How to overload the assignment operator?
Dear all, what is the proper way to make the assignment operator generic and define methods depending on the class of the assigned value? Best regards Jens Oehlschl?gel P.S. I vaguely remember that this was possible in S+. In R I tried to no avail: # using this like h<-1:3 gives Error: in `<-.default`(h, 1:3) : invalid (do_set) left-hand side to assignment
2005 Jun 04
3
How to change the value of a class slot
I defined an S4 class with a slot i. Then I wrote a regular function that attempted to increment i. This didn't work, apparently because of the general rule that a function can't change the values of its arguments outside the function. I gather there are ways around it, but the Green book admonishes "cheating on the S evaluation model is to be avoided" (p. 190). Thinking that
2007 Mar 30
2
Replacing slot of S4 class in method of S4 class?
...method": "mymethod.MyClass" <- function(object, myname=character(0), ...) { object at myname <- myname; #or: myName(object) <- myname } setMethod("mymethod", "MyClass", mymethod.MyClass); Furthermore, I have a replacement method: setReplaceMethod("myName", signature(object="MyClass", value="character"), function(object, value) { object at myname <- value; return(object); } ) I know that it is possible to call: myName(myclass) <- "newname" However, I want to replace the val...
2003 Mar 02
1
'methods' and "[<-"
Dear List, I am trying to override the replace method "[<-" for objects of class "matrix"... with little success... Would anyone know where I am wrong ? > library(methods) > setReplaceMethod("[", "matrix", function(x, i, j, ..., value) {cat("I'm here.\n")}) [1] "[<-" > m <- new("matrix", 0, 5, 2) > m[1,1] <- 2 > # ..did not use my new method it seems Thanks, L/ PS: I am using R-1.6.2
2004 Jan 29
1
setMethodReplace.. Help!
...g the signature to include omitted arguments in definition: i = "missing", j = "missing" Error in .MakeSignature(new("signature"), def, signature) : The names in signature for method (x, , ) don't match function's arguments (x, i, j, drop) The same.... setReplaceMethod("[","track" ,function(x,...,value) { x at y[...]=as(value,"numeric") } ) Please Help. Eryk.
2008 Apr 14
3
Doing the right amount of copy for large data frames.
...tmp*' mechanism (this does not happen for components of a list, tracemem( ) on R-2.6.2 says so). Suggested solution :: Store the columns of the data.frame as a list inside of an environment slot of an S4 class, and define the '[', '[<-' etc. operators using setMethod( ) and setReplaceMethod( ). Question :: This implementation will violate copy on modify principle of R (since environments are not copied), but will save a lot of memory. Do you see any other obvious problem(s) with the idea? Have you seen a related setup implemented / considered before (apart from the packages like fil...
2011 Jun 04
1
S4 class, passing argument names to function, modify original
...t; ), prototype( N = 10000 ) ) .foo.update <- function(object, ...) { args <- list(...) for (i in slotNames("Foo")[pmatch(names(args), slotNames("Foo"), nomatch=0)]) { slot(object, i) <- args[[i]] # indeed more to do here return(object) } } setReplaceMethod("$", "Foo", function(x, name, value) { x <- .foo.update(x, name=value) x } ) x <- new("Foo") x x$N <- 99 x # NULL????
2012 Aug 05
1
setting invalid fields on reference classes sometimes allowed
...to behave like plain old environments wrt field access, unless a method on e.g. $<- is explicitly defined. Here is a code snippet: library(methods) Foo <- setRefClass("Foo") foo <- Foo$new() foo$a <- 2 # why does this succeed? not a valid field! ## set a silly $<- method setReplaceMethod("$", "Foo", function(x, name, value) { callNextMethod(x, "b", value)}) foo$b <- 3 At first, we can set the non-existent field "a" without any error (I don't think this is the intended behavior). Then we set a silly override on $<- and things st...