search for: setconstructors3

Displaying 18 results from an estimated 18 matches for "setconstructors3".

2011 Aug 26
1
R.oo data members / inheritance
If someone is able, can you tell me if there is a better way to do this? More specifically, do I have to rewrite all of the data members stuff and extend stuff of parent class in the child class? See below. Thanks in advance! Example 1: setConstructorS3("ClassA", function(A,x) { if(missing(A))A=15; if(missing(x))x=NA; extend(Object(), "ClassA", .size = A, .x=x ) }) setMethodS3("getSize", "ClassA", function(this,...) { this$.size; }) setMethodS3("getX", "ClassA", function...
2011 Oct 27
0
R.oo package, inherit two classes
Hello, How do I inherit two classes using the R.oo package. Below is kind of a silly example, but I am trying to create class PerDog from classes Dog and Person. Error at bottom. I've tried a few other ways of using extend(), but nothing seems to get me what I want. Example: setConstructorS3("Person", function(age=NA) { this = extend(Object(), "Person", .age=age ) this }) setMethodS3("getAge", "Person", function(this, ...) { this$.age; }) setMethodS3("setAge", "Person", function(this,num, ...) { this$.age = num; }...
2008 Nov 05
1
Methods dispatch and inheritance R.oo
Hi to all members, i have a question about class inheritance and methods using R.oo package: I have the following code and it doesn't work, guess i'm doing smth wrong and there is nothing in the help. library(R.oo) setConstructorS3("ClassA", function(A=15) { extend(Object(), "ClassA", .size = A ); }) setMethodS3("print", "ClassA", function(this,...) { print(paste('Class A:',this$.size)); }) objA<-ClassA(); objA [1] "Class A: 15" setConstructorS3(&qu...
2009 Jul 17
1
Help with R.oo
Hi! I'm trying to learn about object oriented R, as it seems like it would be very useful. I'm going over an example from the documentation, and I'm very confused: http://www1.maths.lth.se/help/R/R.oo/ [assume you've called library (R.oo)] setConstructorS3("SavingsAccount", function(balance=0) { if (!is.numeric(balance) && length(balance) != 1) throw("Argument 'balance' must be a single numeric value: ", mode(balance)); if (balance < 0) throw("Trying to create an account with a negative ba...
2011 Oct 24
0
R.oo package: do setMethodS3 work upon construction
Hello (Heinrich), I did not know I could do this. It doesn't seem to be documented anywhere. Thought this would be helpful to the fraction of the community using package R.oo. Note the call of a setMethodS3 method, xOne, in the setConstructorS3. This is extremely useful if xOne (in this case) is a very complex method (that you always want to be called every time you create a new object). If I have something wrong please let me know! (I'm about to implement this in a large'ish program.) Great package for OOP programming! Example 1...
2011 Aug 26
0
R.oo inheritance with pass by reference
...lass and the parent class for demonstration purposes. This is me giving back to the community...hope it helps. Moral of the story is use your sets and gets rather than obj$dataMember. I am new to R.oo so if you know how to do this better or have some tricks please email me at ccquant@g*m@il.com. setConstructorS3("Person", function(age) { if (missing(age)) age <- NA; extend(Object(), "Person", .age=age ) }) setMethodS3("getAge", "Person", function(this, ...) { this$.age; }) setMethodS3("setAge", "Person", function(this,num, ...) {...
2011 Sep 22
1
R.oo: do work on data member at construction
Hello, I'd like to 'do work' on data members upon construction (i.e. without implementing it in a get method). Is this the best way to create data member 'z' upon construction? I'm thinking if .z=paste(x,y) below gets more complex I'll run into issues. setConstructorS3("MyClass", function(x=NA,y=NA,...) { this <- extend(Object(), "MyClass", .x=x, .y=y, .z=paste(x,y) ) }) setMethodS3("getX", "MyClass", function(this, ...) { this$.x; }) setMethodS3("getY", "MyClass", function(this, .....
2011 Aug 08
1
R.oo error upon construction
Hello, Using the R.oo package, how do I throw an error if a field is not present when the user of the class creates the object? Using the example in the R.oo package: setConstructorS3("Person", function(name, age) { if (missing(name)) name <- NA; if (missing(age)) age <- NA; extend(Object(), "Person", .name=name, .age=age ) }) [rest of class methods here...etc...] User types this with no issues because both age and name are there: p...
2008 Dec 10
1
First call to constructor fails (R.oo)
...trying to do some object-oriented programming in R using the R.oo package. Right from the start I encountered a strange (at least for me) problem. I define a new class/constructor based on the R.oo documentation. However the first attempt to create an object fails: === Code: === library(R.oo); setConstructorS3("MyClass",function(param) { print(param); extend(Object(),"MyClass", .param=param); }) print("Attempt1"); obj = MyClass(1); === Output: === Loading required package: R.methodsS3 R.methodsS3 v1.0.3 (2008-07-02) successfully loaded. See ?R.methodsS3 for help....
2008 Oct 24
1
Help regarding oo package
Hi Henrik, I'm sorry to be bothering you, but there is something that I have been stuck with for a while now. I am trying to create a class like : setConstructorS3("MyPTCM",function(tokenslist=0) { extend(Object(), "MyPTCM", .gamma = 0.0, .rho = 0.0, .phi = 0.0, .tokenslist = tokenslist, .uniquetokens = unique(tokenslist), .numtypes = length(uniquetokens), .Nsq = numtypes*numtypes,...
2011 Aug 18
0
Call super methods from inherited classes R.oo
...opment seems to be in place with this library. But...there is something that I'm really missing... *the super method call* Just a little example that shall demonstrate what I mean: Image we have the following class hierachie that I graped from another post - thx to YuriWerewolf ;-). *ClassA* setConstructorS3("ClassA", function(A) { extend(Object(), "ClassA", .size = A ); }) setMethodS3("print", "ClassA", function(this,...) { print(paste('Class A:',this$.size)); }) *ClassB (inherits ClassA)* setConstructorS3("ClassB", function(B=15) {...
2011 Jun 16
1
Question about R.oo package
...testing some functionality of the R.oo, I found that during the first construction of a object from a class, the constructor is twice called, but only one object is finalized. In all subsequent creation processes, the constructor is (expectedly) called once. Here some example code: library(R.oo) setConstructorS3("Test_class",function(val) { cat("constructor\n") if(missing(val)) val<-NA; extend(Object(), "Test_class", .val=val) }) setMethodS3("finalize","Test_class",function(this,...) { cat("destructor\n") }) o<-Test_class(1) rm(o...
2011 Aug 23
1
R.oo modify an object inside another classes method
Can someone show me how to modify one (R.oo) class's object inside another (R.oo) class's method? Is that possible with the R.oo package? A quick example or reference to an example would be outstanding... Thanks, Ben [[alternative HTML version deleted]]
2006 May 26
1
R.oo question
This is a simple R.oo question but I, thankfully, hope that someone would explain it to me so I would better understand this work frame. I create this class: setConstructorS3("MyExample", function(param=0) { print(paste("called with param=", param)) extend(Object(), "MyExample", .param = param ); }) >From what is printed out, who made the second call to the class with the default param? > MyExample(1) [1] "called with...
2003 Oct 27
1
Difficulties with R.oo (static fields, etc.)
...- I get an tcltk error when I try to recreate a turtle world after having tried to destroy it (for the moment, I need to detach tcltk to reset it) #--------------------------------------------------------------------------------------------------------------------- library("R.oo") setConstructorS3("TurtleBasic",function() { new<-extend(Object(),"TurtleBasic",.x=100,.y=100,.a=0,.turtle=NA) ## Create a new Turtle World if necessary require(tcltk) || stop("tcl/ library not available") if(!is.tkwin(new$.canvas)) { # check to see if it is first instanc...
2007 Dec 17
0
Extending data.frame
...ious approaches to OO R, I came across R.oo, which seems nice. Where I'm currently stuck is getting my objects to be mutable. For example, in the following toy code, the addStuff() method has no effect: > library(R.oo) R.oo v1.3.0 (2006-08-29) successfully loaded. See ?R.oo for help. > setConstructorS3("Foo", function(...) { + frame <- data.frame(foo=4, bar=3:5) + extend(frame, "Foo") + }) > setMethodS3("addStuff", "Foo", function(this, ...) { this$field <- 5 }) > f <- Foo(); f foo bar 1 4 3 2 4 4 3 4 5 > addStuff(f); f...
2005 Jul 08
2
R.oo static field
How can I define a static member of a class? not a static method, rather a static field that would be accessed by all instances of the class.
2007 Jan 17
3
R.oo Destructors
Has anyone figured out how to create a destructor in R.oo? How I'd like to use it: I have an object which opens a connection thru RODBC (held as a private member) It would be nice if the connection closes automatically (inside the destructor) when an object gets gc()'ed. Thanks in advance. Regards, Ken BTW, a >BIG< thanks to Henrik Bengtsson for creating the R.oo package! Lucky