search for: setrefclass

Displaying 20 results from an estimated 73 matches for "setrefclass".

2011 Dec 08
1
Reference class finalize() fails with 'attempt to apply non-function'
...reference classes have finalize methods. The problem is that garbage collection can be run after the methods package is no longer available. It affects (periodically) the Bioconductor AnnotationDbi package as well as packages that contain Rcpp classes. To reproduce: library(methods) a = setRefClass("A", methods=list(finalize=function() cat("A\n"))) b = setRefClass("B", contains="A") repeat b = setRefClass("B", contains="A") until finalize does not run (no garbage collection triggered during setRefClass) b = setRefClass(&quot...
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]]
2011 Apr 24
0
should I use setRefClass() ?
Hello, I am somewhat new to R programming and a novice C++ programmer. I'd like to know if I should use setRefClass() to manage objects, functions, and data in a very large program I am attempting to code. See: http://stat.ethz.ch/R-manual/R-devel/library/methods/html/refClass.html I like the referential class structure that C++ provides and R seems to provides via setRefClass(). Mainly what I like is that I ca...
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. Thanks for your help. For example my class...
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 = as.charact...
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 = newObject$copy() copyObject$value = 3 print(newObject$value) print(copyObject$value)...
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...
2011 May 04
1
General "nil" reference class object
...here'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 <- setRefClass("Bar", fields=list(foo="Foo")) > Bar$new(foo=NULL) Error in as(value, "Foo") : no method or default for coercing "NULL" to "Foo" > setClassUnion("FooOrNull", c("Foo","NULL&...
2014 Feb 11
2
$new cannot be accessed when running from Rscript and methods package is not loaded
Hi Accesses the $new method for a class defined in a package fails if the methods package is not loaded. I have created a test package with the following single code file: newTest <- function() { cl <- get("someClass") cl$new } someClass <- setRefClass("someClass") (This is similar to code actually used in the testthat package.) If methods is not loaded, executing the newTest function fails in the following scenarios: - Package "depends" on methods (scenario "depend") - Package "imports" methods and imp...
2010 Nov 21
1
reference classes: question on inheritance
Dear list, I have a reference class which should act as a "generic" superclass for other classes. I've read the respective section at ?setRefClass and put the name of the superclass to the 'contains' argument of an example subclass (see class defs below). Classnames are set in a way that shouldn't result in collation issues (virtual def sourced before superclass def sourced before subclass). Yet, this results in the following err...
2011 Jun 03
2
Bug or feature: using "ANY" as a generic field class (was: '[R] Is there a (virtual) class that all R objects inherit from?)
...ot;, representation(x="ANY")) > new("A", x=1:3) > > setClass("A", representation(x="ANY")) > setClass("B", contains="A", representation(x="character")) > new("B", x=1:3) > > # Reference Classes > setRefClass( > Class="A", > fields=list( > .PRIMARYDATA="ANY" > ), > contains=c("VIRTUAL") > ) > B <- setRefClass( > Class="B", > fields=list( > .PRIMARYDATA="character" > ), > contains=c("A") > ) Bug, I'...
2020 Mar 27
4
object.size vs lobstr::obj_size
.../27/20 07:01, Tomas Kalibera wrote: > they provide an over-approximation They can also provide an "under-approximation" (to say the least) e.g. on reference objects where the entire substance of the object is ignored which makes object.size() completely meaningless in that case: setRefClass("A", fields=c(stuff="ANY")) object.size(new("A", stuff=raw(0))) # 680 bytes object.size(new("A", stuff=runif(1e8))) # 680 bytes Why wouldn't object.size() look at the content of environments? Thanks, H. -- Herv? Pag?s Program in Computati...
2011 Feb 03
2
Creating a reference class object from a class definition in a package fails
...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 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 Creat...
2011 Jun 29
1
Ref Classes: bug with using '.self' within initialize methods?
...see section "METHODS" in example below). Instead I have to go with 'someInitFooRefInner(.self=.Object, ...)' (see section "UPDATED METHOD" in example below). Yet, this is only possible because there actually IS such a method (I try to stick to the recommendations at ?setRefClass where it says: "Reference methods should be kept simple; if they need to do some specialized *R* computation, that computation should use a separate *R* function that is called from the reference method") The same problem occurs when, say 'someInitFoo()' calls yet another Ref...
2010 Oct 28
2
Reference Classes: Generalizing Reference Class Generator objects?
...rator? I have tried adding a "new" method to the methods of the class, but that is obviously not correct. I have also tried adding it to the class generator, but the class generator still uses the default constructor. As a simple example, this is the current interface: TestClass <- setRefClass ("TestClass", fields = list (text = "character"), methods = list ( print = function () {cat(text)}) ) test <- TestClass$new (text="Hello World") test$print() I would like to override $new(...) to be something like (add a "\n...
2020 Mar 27
2
object.size vs lobstr::obj_size
...an over-approximation > > They can also provide an "under-approximation" (to say the least) e.g. > on reference objects where the entire substance of the object is > ignored > which makes object.size() completely meaningless in that case: > > ? ?setRefClass("A", fields=c(stuff="ANY")) > ? ?object.size(new("A", stuff=raw(0)))? ? ? # 680 bytes > ? ?object.size(new("A", stuff=runif(1e8)))? # 680 bytes > > Why wouldn't object.size() look at the content of environments? > > >...
2012 Apr 13
0
Reference Class import() behaviour
...ases that illustrate the point but the general idea is that importing appears to work fine for everything except viewports and grid grobs. Code to illustrate the point follows. # This first case is an example to show that the importing process # I have been using works for simple cases test <- setRefClass("classTest", fields = c("nums", "testlist"), methods = list( initialize = function(nums = 1:10, testlist = NULL) { nums <<- nums testlist <<- testlist }, view = function() { print(nums) print(t...
2012 Mar 13
2
Problem installing gWidgetsRGtk2 on Ubuntu 10.04
...o install the RQDA package. It fails because of a dependency with gWidgetsRGtk2, which doesn't install because of the following: > * installing *source* package ?gWidgetsRGtk2? ... ** R ** inst ** preparing package for lazy loading Error in eval(expr, envir, enclos) : konnte Funktion "setRefClass" nicht finden (=could not find function "setRefClass") Error : unable to load R code in package 'gWidgetsRGtk2' ERROR: lazy loading failed for package ?gWidgetsRGtk2? * removing ?/home/k/R/i486-pc-linux-gnu-library/2.10/gWidgetsRGtk2? I have no idea what this could mean. I...
2012 Jan 04
1
Is there a way to update a method on an existing Reference Class object?
...hough, I have one problem: I cannot find a way to update a method on an existing object. The flexibility that scripting gives (really needed for interactive data analysis) is lost if everything have to be recalculated all the time. For example I would normally work something like this: cl1 <- setRefClass("cl1", ? fields=list(x="data.frame"), ? methods=list( ? ? init=function(){"Read and process data"}, ? ? fitModel=function(){"Fit different kind of models and keep the results in x and other fields"}, ? ? plotFit1=function(){"Plot the fit one way"},...
2012 Aug 05
1
setting invalid fields on reference classes sometimes allowed
I've found that reference class objects tend 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...