search for: getrefclass

Displaying 20 results from an estimated 21 matches for "getrefclass".

Did you mean: setrefclass
2010 Nov 17
2
Reference classes: accessor functions via 'getRefClass(...)$accessors(...)'
Hi there, I''d like to choose between an "static" and "dynamic" access of a reference class field, say ''a''. myObj <- getRefClass("Blabla")$new() Static: myObj$a Dynamic: myObj$a.get() where the function retrieves the data from a database (or some other location), stores it to a buffer and optionally updates the static field value ''a''. I''ve set up suc...
2010 Nov 23
1
Reference Classes: removing methods -> implications for objects/instances of that class
...d 'unregistering' methods for S4 reference classes correctly: If I registered a method and want to 'unregister' (i.e. remove) this method again, objects/instance created of the respective class still feature the removed method until I do an explicit reassign ('my.instance <- getRefClass("Classname")$new()'), right? setRefClass("Shab", fields=list(a="numeric")) # Register method getRefClass("Shab")$methods(list(aSquare=function() a^2)) getRefClass("Shab")$methods() # Create instance shab <- getRefClass("Shab")...
2011 May 26
0
Reference Classes: getter and setter functions/methods and possible shortcuts
...ws=FALSE, check.names=TRUE, stringsAsFactors=default.stringsAsFactors() ){ x.primarydata <- data.frame(..., row.names=row.names, check.rows=check.rows, check.names=check.names, stringsAsFactors=stringsAsFactors) x.generator <- getRefClass(class(.Object)) x.generator$accessors(names(x.generator$fields())) .Object$PRIMARYDATA <- x.primarydata return(.Object) } ) myDataFrameCreate <- function( ..., row.names=NULL, check.rows=FALSE, check.names=TRUE, stringsAsFactors=defaul...
2011 Jun 29
1
Ref Classes: bug with using '.self' within initialize methods?
...te("initializig object of class'", class(.Object), "' inheriting from class 'MyVirtual'", sep=""), sep="\n") } # / # GET GENERATOR OBJECT if(is.null(GENERATOR)){ GENERATOR <- getRefClass(class(.Object)) } flds <- names(GENERATOR$fields()) .Object$someInitFoo( flds=flds, ... ) return(.Object) } ) # / x <- GENERATOR$new() # UPDATED METHOD setMethod( f="initialize", signature=signat...
2011 Jun 06
1
How can I write methods for 'as()'?
...s as I have been coding in S4 a lot, but my first attempt was to write something like this: as.myClass <- function(x, ...){ if(is(x, "data.frame"){ x <- as.list(x) } if(is(x, "character"){ x <- as.list(x) } ... out <- getRefClass("myClass")$new(X=x) return(out) } But that way I'd have to explicitly call 'as.myClass(x)' whereas I'd simply like to type 'as(x, "myClass")'. Also, how is it possible to have method dispatch recognize two signature arguments in S3? I.e., how can...
2011 Feb 03
2
Creating a reference class object from a class definition in a package fails
...kage.skeleton('TestClass') to which I add the following R code: TestClass <- setRefClass('TestClass',fields=c('name')) Unfortunately my R console output bears this: > library(TestClass) > TestClass$new(name='foo') Error: attempt to apply non-function > getRefClass('TestClass')$new(name='foo') Error: attempt to apply non-function Creating the same reference class in the global environment works though: > x <- setRefClass('TestClass',fields='name') > x$new(name='foo') An object of class "TestClass" &...
2011 Jun 06
1
Reference Classes: shortcut like 'isS4' for Ref Classes?
...regarding Ref Classes. Currently, I'm doing it this way, which is a bit clumsy: A <- setRefClass("A", fields=list(X="numeric")) a <- A$new() isRefClass <- function(object, ...){ return(getClass(class(object))@class == "refClassRepresentation") # getRefClass(class(object))@class == "refObjectGenerator" } isRefClass(a) [1] TRUE Regards, Janko
2011 May 26
0
Reference Classes: strange behavior when trying to change class def in the same R session
..., fields=list(a="numeric"), methods=list( foo=function() print("hello world!"))) setMethod( f="initialize", signature=signature(.Object="Horst"), definition=function( .Object ){ return(.Object) } ) gen <- getRefClass("Horst") horst <- gen$new() horst$a horst$a <- 5 horst$a horst$foo() removeClass("Horst") setRefClass(Class="Horst", fields=list(a="character"), methods=list( foo=function(x) print(x))) gen <- getRefClass("Horst") horst <- gen...
2011 Mar 10
1
Testing for a reference class object
...e's a better way to test. Regardless, It would be nice to have such a function in the methods package. I have a case where I'd like to ensure that an object is constructed from a reference class AND that it implements a certain method: if (isRefClassObject(x) && 'run' %in% getRefClass(x)$methods()) x$run() Thanks, Jeff -- http://biostat.mc.vanderbilt.edu/JeffreyHorner
2010 Nov 21
1
Ref classes: can I register fields as I register methods?
Hi there, is it possible to register fields as you can register methods with getRefClass("Classname")$methods(.)? I know that you should usually give some thought on which fields you need and hardcode them in the class def. But I''m playing around with dynamically creating/extending sort of a template class that already offers basic functionality shared by all obj...
2011 May 27
1
Reference Classes/S4 Classes: can method dispatch check superclasses BEFORE resorting to method for "ANY"?
...to build a generic initialization method for all my Reference Class (say "MyDataFrame") objects by having them inherit from class, say "MyRefClassVirtual" (which would have to be a virtual S4 class; there are no virtual Reference Classes, are there?) The problem is that 'getRefClass("MyDataFrame")$new' calls (I think) the method that was written for "ANY". Thus even though I write a explicit initialize method for class "MyRefClassVirtual" which I should be called for "MyDataFrame" as it inherits from this class, this method will n...
2010 Nov 24
2
Reference Classes: how to clone/copy instances?
...bject. Obviously, simply assigning 'b <- a' does not work with respect to autonomy. Nor does exporting the object via 'b <- a$export(Class="A")'. I thought about creating a new instance b and then defining a function that maps the field values from a to b: b <- getRefClass("A")$new() fieldsMap(src=a, tgt=b) Is there already some functionality I can use? Thanks, Janko ########## SYSTEM INFO ########## Windows XP SP3 R 2.12.0 (patched as of 2010-11-22) Eclipse 3.6.1 (Helios) StatET 0.9.x ###############################
2011 Mar 07
1
WG: Reference classes: error with missing arguments in method calls
...uot;\n") ??? if(missing(var.1)) var.1 <- "some default value" ??? cat(paste("* var.1: ", var.1, sep=""), sep="\n")??? }) setRefClass(Class="Xmple", methods=list(foo=function(var.1, ...) fooMthd(.self=.self, var.1=var.1, ...))) xmple <- getRefClass(Class="Xmple")$new() xmple$foo(var.1="hallo") xmple$foo() # Does not work. #+++++ # 3) "Fixed generic" context setGeneric(name="fooMthd", def=function(.self, var.1, ...) standardGeneric("fooMthd"), signature=c(".self"))???? setMethod(...
2011 Jun 01
1
possibly invalid assertion in setRefClass?
> setRefClass("Foo", fields = list()) Error in setRefClass("Foo", fields = list()) : A list argument for fields must have nonempty names for all the fields In my opinion, the above should not fail. There are no fields. Thanks, Michael [[alternative HTML version deleted]]
2010 Nov 17
0
Reference classes: opinion on OOP design
...this? Does this make sense to you or is something like this done in another (and probably more elegant ;-)) way? THE HOMEWORK I DID - I've looked at active bindings which are nice. But this limits me to funs with either none or one argument if I'm not mistaken. - I do like the idea of 'getRefClass("Blabla")$accessors(.)' setting up get/set methods for me, but would need to customize them to my specific needs (e.g. handling the default values of method arguments etc.) I've attached a code example and would really appreciate your comments if you find some time. Thanks a...
2010 Nov 17
0
WG: Reference classes: opinion on OOP design
...implemented this? Does this make sense to you or is something like this done in another (and probably more elegant ;-)) way? THE HOMEWORK I DID - I?ve looked at active bindings which are nice. But this limits me to funs with either none or one argument if I?m not mistaken. - I do like the idea of ?getRefClass(?Blabla?)$accessors( )? setting up get/set methods for me, but would need to customize them to my specific needs (e.g. handling the default values of method arguments etc.) I?ve attached a code example and would really appreciate your comments if you find some time. Thanks a lot!! Janko ------...
2011 Feb 20
0
Reference classes: error with missing arguments in method calls
...ot;) if(missing(var.1)) var.1 <- "some default value" cat(paste("* var.1: ", var.1, sep=""), sep="\n") }) setRefClass(Class="Xmple", methods=list(foo=function(var.1, ...) fooMthd(.self=.self, var.1=var.1, ...))) xmple <- getRefClass(Class="Xmple")$new() xmple$foo(var.1="hallo") xmple$foo() # Does not work. #+++++ # 3) "Fixed generic" context setGeneric(name="fooMthd", def=function(.self, var.1, ...) standardGeneric("fooMthd"), signature=c(".self"))...
2010 Dec 16
0
R 2.12.1 is released
...to version 5.0.0. ? reshape() now makes use of sep when forming names during reshaping to wide format. (PR#14435) ? legend() allows the length of lines to be set by the end user _via_ the new argument seg.len. ? New reference class utility methods copy(), field(), getRefClass() and getClass() have been added. ? When a character value is used for the EXPR argument in switch(), a warning is given if more than one unnamed alternative value is given. This will become an error in R 2.13.0. ? StructTS(type = "BSM") now allows series with just...
2010 Dec 16
0
R 2.12.1 is released
...to version 5.0.0. ? reshape() now makes use of sep when forming names during reshaping to wide format. (PR#14435) ? legend() allows the length of lines to be set by the end user _via_ the new argument seg.len. ? New reference class utility methods copy(), field(), getRefClass() and getClass() have been added. ? When a character value is used for the EXPR argument in switch(), a warning is given if more than one unnamed alternative value is given. This will become an error in R 2.13.0. ? StructTS(type = "BSM") now allows series with just...
2013 Apr 03
0
R 3.0.0 is released
...vailable to copy a device to a quartz() device. dev.copy2pdf() optionally does this for PDF output: quartz.save() defaults to PNG. o The default method of pairs() now allows text.panel = NULL and the use of <foo>.panel = NULL is now documented. o setRefClass() and getRefClass() now return class generator functions, similar to setClass(), but still with the reference fields and methods as before (suggestion of Romain Francois). o New functions bitwNot(), bitwAnd(), bitwOr() and bitwXor(), using the internal interfaces previously used for classes &q...