similar to: Defining an iterator

Displaying 20 results from an estimated 10000 matches similar to: "Defining an iterator"

2020 Oct 05
2
S4 - inheritance changed by order of setClassUnion and setAs()
Dear colleagues, there is a behaviour with S4 (virtual) classes that I find very hard to understand: Depending on the position of setAs(), the tree of inheritance changes. This is my baseline example that defines the classes "grandma", "mother", "daughter" and a virtual class "mr_x". For a new instance if "daughter", "mr_x" is betweeen
2009 Oct 13
1
for loop over S4
Hello, Consider this : > setClass("track", representation(x="numeric", y="numeric")) [1] "track" > o <- new( "track", x = 1, y = 2 ) > for( i in o ){ + cat( "hello\n") + } Error: invalid type/length (S4/1) in vector allocation This happens at those lines of do_for: n = LENGTH(val); PROTECT_WITH_INDEX(v =
2009 Aug 05
1
S4 method dispatch: coercion of arguments with setAs defined
Hi list, I've got a class B that contains a slot obj of class A. I'd like to be able to call all the methods of class A directly on objects of class B as if I had called the method on slot obj. This without overloading all methods of class A to work on class B. I don't define B as an extension of A, because I want class B to also work with objects of classes that inherit from
2007 Mar 23
1
Bug in str or issue with class management in my package?
Dear developeRs, with R 2.4.1 (and also 2.4.0), the function str() fails on objects of class relimplmbooteval, if there are unused slots, which is very often the case. I am not sure whether this is a bug in str() or a correct behavior of str() that unmasks some sloppiness in my usage of S4 classes (that I am not aware of)? Reproducible example (package relaimpo needed): The program
2012 Mar 15
1
Extending a group of S4 classes by setClassUnion ?
Hi, I would like to create some S4 classes as follows setClass("Father",representation(name="character")) setClass("Son1",contains="Father",representation(par="numeric")) setClass("Son2",contains="Father",representation(par="logical")) Son1<-new("Son1") Son1 at name<-"Son1" Son1 at par<-3
2006 Aug 30
1
setMethod() and log()
Hi I am having difficulty with setMethod(). I have a "brob" class of objects whose representation has two slots: "x" and "positive". Slot "x" (double) holds the log of a number and slot "positive" (logical) its sign. The idea is that large numbers can be handled. I'm trying to implement a log() method using an analogue of the
2011 Sep 13
4
S4 vs Reference Classes
Hi, I'm looking for some guidance on whether to use S4 or Reference Classes for an analysis application I'm developing. I'm a C++/Python developer, and like to 'think' in OOD. I started my app with S4, thinking that was the best set of OO features in R. However, it appears that one needs Reference Classes to allow object methods to assign values (other than
2011 Sep 14
1
S4 method dispatch
List, In order to get rid of some old, unreadable S3 code in package sp, I'm trying to rewrite things using S4 methods. Somewhere I fail, and I cannot sort out why. In order to isolate the problem, I created two functions, doNothing<- and dosth, and both should do nothing. The issue is that in most cases they do nothing, but in some cases dosth(obj) changes the class of obj and breaks with
2006 Oct 31
1
setReplaceMethod
Hi If x <- 1:10 then x[5] <- 1i will promote x to be a complex vector. Suppose I have an S4 class "brob", and have functions is.brob(), 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
2005 May 07
4
how to add method to .Primitive function
Hi, I tried to write the dim method for the list class, but R doesn't seem to dispatch to it: > dim.list = function(x) c(length(x[[1]]), length(x)) > dim(list(1)) NULL > dim.list(list(1)) [1] 1 1 What is the correct way of registering dim.list with .Primitive("dim")? Thanks, Vadim [[alternative HTML version deleted]]
2008 Apr 23
1
S4 default for coercing
Something has changed in the S4 default for coercing. Am I now suppose to use setAs, or is there something else I should do to make this work: R version 2.7.0 (2008-04-22) .... > require("methods") > setClassUnion("OptionalPOSIXct", c("POSIXct", "NULL")) [1] "OptionalPOSIXct" > setClass("TSmetax",
2006 Apr 07
4
setIs and method dispatch in S4 classes
Dear all, I have a question regarding setIs and method dispatch in S4 classes: Consider the following example: ##################################################### ## A02 "contains" A01 by setIs: setClass("A01", representation(a="numeric",b="numeric")) setClass("A02", representation(a="numeric",d="numeric"))
2006 Apr 09
2
type converters not being saved to workspace
Any one can explain why this happens or any work arounds? > setClass('foo') [1] "foo" > setAs('foo', 'character', function(from) from) > showMethods('coerce') Function "coerce": from = "ANY", to = "array" from = "ANY", to = "call" from = "ANY", to = "character" from =
2006 Apr 09
2
type converters not being saved to workspace
Any one can explain why this happens or any work arounds? > setClass('foo') [1] "foo" > setAs('foo', 'character', function(from) from) > showMethods('coerce') Function "coerce": from = "ANY", to = "array" from = "ANY", to = "call" from = "ANY", to = "character" from =
2012 Sep 19
1
different behavior accessing type-specific as.data.frame inside a function vs inside R shell
hello we are developing an R package called ANTsR for which we have some special types. one of these types is an " antsMatrix " type. we implemented a "as.data.frame" function that casts an antsMatrix to a data.frame this works fine in a basic shell script. for instance: # install R CMD INSTALL ANTsR # open R # in R do library(ANTsR) a <- new( "antsMatrix",
2008 Mar 17
1
setAs vs setIs
Hi the list I am fighting with the twins setAs and setIs... Here are some questions and comments (comments to myself but that migth be wrong, it is why I am posting them) 1. Very surprising : using setIs define 'is', 'as<-' but not 'as' ??? 2. Using setAs define 'as', 'as<-' but not 'is'... What surprise me is that as<- can be define by
2004 Oct 08
1
Function _coerce_ in _setIs_ never entered (S4).
Hi, Please consider the following trivial example. In the sample code I first define a class MVCa using composition. This class contains a slot of type list. Next I define an inheritance relation using the function setIs -> MVCa "is a" list. Then I define a function printlength which prints the list-length which is defined for the type "list". If I call this function
2009 Jan 19
1
pass by reference for S4
Hi all; Is it possible to modify the "@" operator that it can handle references (or external pointers) of S4 Object instead of the real Objects? Or is there any technical or compatibility issue which make it impossible? I look forward to hear from you and also hope that you don't hate me for my nooby question. Yours sincerely, Rudolf Biczok [[alternative
2008 Apr 09
1
coerce methods and inheritance
Hi, It doesn't seem that the dispatching algo is finding my coerce method under some circumstances. Let's say I have 2 classes, A and AA and that AA is just a direct extension of A with no additional slots: setClass("A", representation(ii="integer")) setClass("AA", contains="A") I can define a method for coercing my objects to an integer
2014 Feb 11
1
getting environment from "top" promise
Hi all, It seems that there is a use case for obtaining the environment for the "top" promise. By "top", I mean following the promise chain up the call stack until hitting a non-promise. S4 data containers often mimic the API of base R data structures. This means writing S4 methods for functions that quote their arguments, like with() and subset(). The methods package