Displaying 20 results from an estimated 10000 matches similar to: "Using substitute from inside an S4 method"
2008 Jan 22
1
deparse, substitute and S4 generics
Hello everyone,
I encountered the following confusing behavior of 'deparse' and
'substitute' while programming with S4 classes (see example below). It
seems like the presence of '...' argument in the definition of the
generic generates the problem. I have no clue why, can anyone explain
that to me? Are there any "workarounds"?
Thanks a lot for your time!
2006 Feb 14
3
S4 classes and methods with optional arguments
Hi,
i have used S4 classes to implement a unified access to random number generators
(package rstream on CRAN).
I have used a construct to allow optional arguments:
if(!isGeneric("rstream.sample"))
setGeneric("rstream.sample", function(stream,...) standardGeneric("rstream.sample"))
setMethod("rstream.sample",
2010 Sep 03
3
S4 Method Signatures
Hello,
If the signature of a method defines which generic it implements then I'm confused about why this minimal example I invented won't work :
setGeneric("myFun", function(rs, ...){standardGeneric("myFun")})
setGeneric("myFun", function(cs, ...){standardGeneric("myFun")})
setMethod("myFun", "numeric", function(rs, colour =
2010 Mar 15
2
Strange behavior of assign in a S4 method.
Hi the list,
I define a method that want to change an object without assignation
(foo(x) and not x<-foo(x)) using deparse and assign.
But when the argument of the method does not match *exactly* with the
definition of the generic function, assign does not work...
Anything wrong?
Christophe
#------ Does not work ------#
2009 Oct 27
1
How to reduce key strokes when defining S4 classes?
I feel tedious when I define a S4 class and the methods. For each
method, I have to call both setMethod and setGeneric (or both
setReplaceMethod and setGeneric). I would like a more compact grammar
so that I can reduce the key strokes. I'm wondering if there is a
better way available.
setClass(
Class='A',
representation=representation(
x='numeric'
)
2008 May 10
2
Hashes as S4 Classes, or: How to separate environments
For learning purposes mainly I attempted to implement hashes/maps/dictionaries
(Python lingua) as S4 classes, see the coding below. I came across some rough S4
edges, but in the end it worked (for one dictionary).
When testing ones sees that the dictionaries D1 and D2 share their environments
D1 at hash and D2 at hash, though I thought a new and empty environment would be
generated each time
2012 Feb 04
1
'deparse(substitute'))' then 'assign' in a S4 methods
Hi the list,
I am writing a function in which I need to affect a variable on a higher
level. My fnction could be:
++++++++++++++++++
fooBis <- function(x){
nameObject <- deparse(substitute(x))
print(nameObject)
assign(nameObject,4,envir=parent.frame())
}
> fooBis(e)
[1] "e"
> e
[1] 4
-----------------
(to simplify, this fnction can affect only the number
2010 Oct 26
1
S4 methods for rbind()
Hello.
I am trying to write an S4 method for rbind(). I have a class of objects
called 'mdm', and I want to be able to rbind() them to one another.
I do not want the method for rbind() to coerce anything to an mdm object.
I want rbind(x1,x2,x1,x2) to work as expected [ie rbind() should take any
number of arguments].
This is what I have so far:
setGeneric(".rbind_pair",
2005 Mar 25
1
S4 methods semantics questions
Some quick questions about S4 methods.
Does the typing of S4 methods mean that lazy evaluation is no longer
possible? It seems that you would need to evaluate the arguments to
determine their type at dispatch.
Second, what role, if any, do default arguments play in S4 methods? I
notice that you can put default arguments into generics but that the
dispatch is still done on the type of the
2007 Apr 19
2
setClass inside a function
Hello,
I would like to create a function that gets passed a class name and then calls setClass, and a few other functions, inside. I have done this in the past with setmethod, creating accessors for all slots in a set of S4 classes. But setClass is choking when my function is called isnide a package, telling about an error in exists(cname, where). I assume this to be a problem with the
2007 Mar 15
4
R 2.5.0 devel try issue in conjuntion with S4 method dispatch
Hi,
after updating R 2.5.0 devel yesterday we today observed many new
unexpected failures in our daily package build and test system runs,
which can be traced to recent changes in the implementation in try()
(as noted in NEWS).
Investigating this new implementation I come across an issue in
conjuntion with using S4 classes and methods. try(expr) does not return an
object with attribute
2007 Mar 23
1
substitute and S4 objects
Hi all,
I don't understand why this does not what I expect :
## code start here ##############
setClass("num",representation(x="numeric"))
num<-function(x) new("num",x=x)
add<-function(e1,e2) {
cat("Computing
",deparse(substitute(e1)),"+",deparse(substitute(e2)),"\n")
e1@x+e2@x
}
2005 Dec 29
1
trouble with S4 methods for group "Summary"
Hello. This question concerns the Methods package. I have created a
new class and am trying to set a method for it for S4 group generic
"Summary". I have run into some signature problems. An example:
> setClass("track", representation(x="numeric", y="character"))
[1] "track"
> setGeneric("max", group="Summary")
2006 Apr 12
1
S4 method dispatch matrixOrArray
I have some code where the primary dispatching is on
other parameters so I'd like not to have to create a
set of functions for "matrix" and another duplicate
set for "array". But the class union technique isn't
working as implemented below and I don't have my Green
book with me. How do I fix my infinite recursion problem?
2010 Apr 21
1
VERY basic question about S4 classes
Hi,
I'm new to R and S4 classes. I defined a class with two methods (myMethod1 and myMethod2). I want to call myMethod1 within myMethod2. Why does the code below not work? The name 'myMethod1' doesn't appear to have meaning inside myMethod2, even though the two methods belong to the same class.
setClass(Class="SomeClass",
representation=representation(
2010 Sep 07
1
Dispatch method on S3 or S4 class
Hello,
I've been attempting to make a generic method that dispatches on the first argument, which can be either an S3 or an S4 class. This is as far as I've gotten. Any suggestions about what to try next ?
library(aroma.affymetrix)
library(GenomicRanges)
setGeneric("analyse", function(x, y, ...) standardGeneric("analyse"))
setMethodS3("analyse",
2003 Jul 09
2
Packages, generics, S3 and S4
My question has two parts.
The first is with regard to the frame or environment in which generic
functions are defined in packages. It seems as though they are defined
(i.e. exist as objects) in frame 1, even when defined in a package.
The following is a short example:
setClass("track",representation(x="numeric",y="numeric"))
plotTrack <- function(x,y,...)
2010 Jul 21
1
Bug: broken exception handling in S4 methods
Hi all:
we have noticed for quite a while that certain errors cannot be handled
by R try, tryCatch etc blocks, but it was fairly difficult to understand
what were the conditions for this incorrect behaviour. Finally I stabbed
across a very understandable case, which is outlined in the (runnable)
example below.
The main message is: wrapping an S4 method call in a try block will not
help if an
2006 Mar 22
1
setting argument defaults in setMethod
Hi,
I want to set a default value in a method of a generic function. This seems
as though it should be possible. From R help on setMethod...
Method definitions can have default expressions for arguments. If
those arguments are then missing in the call to the generic
function, the default expression in the method is used. If the
method definition has no default for the
2004 Jun 26
1
S4 group "Math", "getGroupMembers", "genericForPrimitive"
Hi,
I found the following on Windows 2000/NT
R Version 1.9.1 (2004-06-21) (also Version 1.9.0):
The S4 group "Math" doesn't work as documented; i.e., "log", "log10",
"gamma" and "lgamma" are included
in the documentation but don't work. See example code below.
Moreover, what about 'genericForPrimitive' which is used
in