Displaying 20 results from an estimated 8000 matches similar to: "Reference Classes: Generalizing Reference Class Generator objects?"
2011 Feb 03
2
Creating a reference class object from a class definition in a package fails
Hi,
I'm trying to create a package that contains reference class
definitions from which users can create reference objects, but there
seems to be something awry.
My toy example creates an empty package via
package.skeleton('TestClass') to which I add the following R code:
TestClass <- setRefClass('TestClass',fields=c('name'))
Unfortunately my R console output
2011 Jun 08
1
Reference Class error message: may be caused by lazy evaluation?
Dear All,
I came across an error message recently when constructing a reference class,
an example is attached below, it looks like only if I call a specific method
in advance, otherwise it cannot be found in defined method without using
.self, this make it difficulty that sometimes in my initialize method, I
need to call other method defined in the same reference class, the
workaround for this is
2011 May 04
1
General "nil" reference class object
Dear John and others,
I've been wondering about whether there's any way to indicate a "nil"
reference class object, which will represent "no value", and be tested
for, but not fail the internal type checking. NULL is the obvious
choice (or seems so to me), but can only be used if an explicit class
union is created:
> Foo <- setRefClass("Foo")
> Bar
2013 Oct 16
1
Internally accessing ref class methods with .self$x is different from .self[['x']]
When a reference class method is accessed with .self$x, it has
different behavior from .self[['x']]. The former copies the function
to the object's environment (with some attributes attached), and the
latter just return NULL (unless it has already been accessed once with
.self$x). Is this how it's supposed to work?
Here's an example that illustrates:
2011 Oct 31
1
Question about copying reference objects using the initialize method
Dears,
I have a question about copying reference objects using the initialize method.
1) If the latter has no arguments, there is no problem to copy an object.
myClass = setRefClass("myClass", fields = list(value = "numeric") )
myClass$methods(initialize = function(...){
? value <<- 1
? callSuper(...)
})
newObject = myClass$new()
newObject$value = 2
copyObject =
2013 Mar 28
1
Ref classes initFields has incorrect environment?
As suggested by the following code:
A <- setRefClass("A", fields = list(x = "logical"),
methods = list(initialize = function(...) {
x <<- FALSE
initFields(...)
}))
A$new()
# Works as expected
quote <- as.character
A$new()
# Error in function (value) :
# invalid replacement for field ?x?, should be from class ?logical?
or a subclass (was class
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
2012 Dec 12
1
Lost in S4 and S3 classes
Hi all, this is my first post in R devel? sorry if I lost some of the guidelines.
Anyway this is my problem:
Version:
R version 2.15.2 (2012-10-26)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
I want to make an S4 class that use the output object of the function of nls.lm as a slot:
setOldClass("nls.lm")
setClass (
Class="TestClass",
2010 May 12
1
slot assignment in S4 classes
Hi R friends,
I'm still studying S4 classes and I have a question about slot assignment. Why would I have to use a special setter method [example 2 below] if I can assign data to a slot directly when I call new() [example 1 below]?
## first way to do it (the idiosyncratic way?)
setClass(Class = "TestClass", representation = representation(myDf = "data.frame"))
2012 Oct 27
2
Class generator functions for reference classes
As of rev. 61035 in r-devel, setRefClass() now returns a generator
function, as setClass() has done since 2.15.0.
The convenient style is now:
mEdit <- setRefClass("mEdit",......)
xx <- mEdit(data = xMat)
instead of
xx <- mEdit$new(data = xMat)
The returned object still has fields and methods accessible as before.
See the "Value" and "Reference Class
2009 Apr 12
1
Simple class with an automatic printing issue
I don't understand the following behavior for a simple S3 class. The
auto-printing at the command line
doesn't behave as I expect. I'm probably missing something, but it might be
a bug.
> print.testClass <- function(x, ...) cat("Class:", class(x), ":", x, "\n")
> structure(1, class = "testClass")
Class: testClass : 1
> print(1 *
2009 Sep 15
2
S3 objects in S4 slots
Hello,
I am the maintainer of the stringkernels package and have come across
a problem with using S3 objects in my S4 classes.
Specifically, I have an S4 class with a slot that takes a text corpus
as a list of character vectors. tm (version 0.5) saves corpora as
lists with a class attribute of c("VCorpus", "Corpus", "list"). I
don't actually need the
2011 Aug 05
1
initFields() method no longer coerces arguments in R-devel
Dear all,
I've just had a package update bounced from CRAN because of a recent
change in R-devel which seems to affect the behaviour of the
initFields() reference class method. (The change must be very recent
because I tested the package on a week-old build of R-devel.) It seems
that the method no longer coerces its arguments to the expected type
of each field. For a simple example:
> Foo
2010 Jan 15
1
Can an object reference itself?
Dear List,
I am not really familiar with any other language than R, but I?ve heard that
in other languages there is something called ?self referencing?.
Here?s what I?m trying to get an answer for:
Suppose there is a function that takes as its input a value of a slot of an
S4 object. The function itself is stored in another slot of the SAME S4
object. Is it then possible to have the function
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]]
2007 Apr 04
0
[LLVMdev] For a small help
Hi Ferad,
On Wed, 2007-04-04 at 19:48 +0200, Ferad Zyulkyarov wrote:
> Hi,
>
> I want to ask for a small help for creating an instruction that calls
> e member method of an object. I suppose that this is not a headache
> but I am impatient in learning :) I would be very thankful if you can
> show me an example snippet code that does this in LLVM. Below is
> described my
2012 May 03
1
deparse(substitute(x)) on an object with S3 class
Dear list,
can someone explain to me why deparse(substitute(x)) does not seem to work
when x is of a user-defined S3 class?
In my actual problem, my print method is part of a package, and the method
is registered in the NAMESPACE, if that should make a difference.
> print.testclass <- function(x,...){
xname <- deparse(substitute(x))
cat("Your object name
2012 Nov 08
1
Dabbling with R5 setRefClass - Inheritance problems
Hello,
I wrote a class like so:
> rcfdpsuperclass <- setRefClass(
> Class="rcfdpsuperclass",
> fields = list(
> RcfpdVersion = "character"),
> methods = list(
> initialize = function(){
> 'Populates fields with defaults and lock as appropriate'
> initFields(
> RcfpdVersion =
2012 Jun 25
1
Very simple question R5 setRefClass and Initialize
Hi,
New to this list, and glad I found R5 which si a great improvement to R
for my work.
Something seems odd anyway, when I do a setRefClass, the initialize
method execute at the class definition.
I would like it to execute only when an instance is created.
How can I do that? I found no way to test if the code execution is when
the class definition happens or when a $new instance is created.
2012 Aug 23
1
[LLVMdev] Error: "Recursive compilation" when run lli
I edit two files named test.h,test.cpp as follow:
///////////////test.h////////////////////////////////////////////////////////////////class TestClass
{
private:
int fTotal;
public:
TestClass();
~TestClass();
};///////////test.cpp/////////////////////////////////////////////////////////////////////////////#include "test.h"
TestClass::TestClass()
{
fTotal = 2;
}