Displaying 20 results from an estimated 40000 matches similar to: "factor S4 class is NA when as.character method exists"
2010 Jun 23
2
format: different S4 behavior in a package
R-Devel-ers:
I have an S4 method that simply formats an object:
setGeneric("formatMe", function(x) standardGeneric("formatMe"))
setMethod("formatMe", "ANY", function(x) format(x))
If I issue the above in an R session, then define an S4 class with its own
format method, I get the desired result:
> setClass("A",contains="numeric")
2010 May 17
1
format.data.frame containing S4 class with format method
Hi again,
I must be misunderstanding something fundamental about how an S4 class
stored in a data.frame can be persuaded to print according to a desired
format. The help page says:
format.data.frame formats the data frame column by column, applying the
appropriate method of format for each column.
Here is my class:
> setClass("A",contains="character")
[1] "A"
2006 Sep 08
2
Extending [ method to S4 class and drop argument (PR#9211)
Full_Name: John Verzani
Version: 2.4.0 alpha (2006-09-05 r39134)
OS: linux, gentoo 2.6.17
Submission from: (NULL) (163.238.43.26)
When extending the "[" method to a new S4 class, the default value for the drop
argument is not being found. Here is a small example:
setClass("test",representation(x="character"))
2008 Jun 27
1
include S4 class and methods in a package
DeaR list,
Pardon the stupidity of this question but I've been trying this for a
while now without success.
I've followed the example given in the green book "programming with
data", and I now have a working example of a S4 class with a few
methods (plot, summary, as.data.frame). It's all very nice in one
file, but I cannot find the way to put this information in a
2013 Feb 05
1
S4 Classes and Initialize methods
Hello,
I am trying to improve my skill on S4 classes. But there's something
strange (to me) happening with "initialize" methods. This is probably a
normal behaviour... but... something is unclear in my mind
I declare two classes, namely "A", and "B", which has a slot of type A. The
class "A" has an initialize method. What I do not understand is that
2011 Feb 01
1
Help need to define method of an s4 class
I need some help in defining a "print" method for my new S4 class
definition. So fer I have worked like this:
setClass("MyClass", sealed=F, representation(slot1 = "list", #create a
new class
slot2 = "vector",
slot3 = "vector",
slot4 = "vector"))
setMethod("print",
2013 Jul 09
1
Is difftime a "class"
I am trying to write S4 methods with "difftime" in the signature but
am being "informed" (? not a warning or error) that "difftime" is not
a class. Nevertheless, dispatch takes place. Should I simply ignore
that "information"? Here is a toy example:
> setClass("foo", contains = "Date")
> setMethod("+", c("foo",
2008 Sep 09
1
building a package that contains S4 classes and methods
Hello R users,
I am trying to make a my first package and I get an error that I can
understand. The package is build out of three files (one for functions, 1
for s4 classes and 1 for s4 methods).
Once I source them I run
package.skeleton( name="TDC" )
within a R session and I get
Creating directories ...
Creating DESCRIPTION ...
Creating Read-and-delete-me ...
Saving functions and
2009 Jun 30
1
S4 class redefinition
I haven't found much on S4 class redefinition; the little I've seen
indicates the following is to be expected:
1. setClass("foo", ....)
2. create objects of class foo.
3. execute the same setClass("foo", ...) again (source the same file).
4. objects from step 2 are now NULL.
Is that the expected behavior (I ran under R 2.7.1)?
Assuming it is, it's kind of
2004 Apr 19
3
How to write an S4 method for sum or a Summary generic
If I have a class Foo, then i can write an S3 method for sum for it:
>setClass("Foo",representation(a="integer"));aFoo=new("Foo",a=c(1:3,NA))
>sum.Foo <- function(x,na.rm){print(x);print(na.rm);sum(x at a,na.rm=na.rm)}
>sum(aFoo)
But how do I write an S4 method for this? All my attempts to do so have
foundered. For example
2015 May 10
2
S4 method dispatch sometimes leads to incorrect when object loaded from file?
Loading an S4 object from a file without first loading the library sometimes (?,
the example below and actual example involves a virtual base class and the show
generic) leads to incorrect dispatch (to the base class method).
The attached package reproduces the problem. It has
setClass("A")
setClass("B", contains="A")
setMethod("show", "A",
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
2010 Mar 16
1
Problem with S3 to S4 transition
Hello to everybody
I am developing a package using R and have the following problem:
I used to work in a mixture of S3 and S4 mechanism environment: as a
matter of fact, I used to define my classes (say "DB" for illustration)
using the setClass function (with representation field), and
I was using the S3 implicit mechanism writing the functions: print.DB
and plot.DB.
Recently, I
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
2010 Aug 25
1
Change value of a slot of an S4 object within a method.
Dear all,
I have an S4 class with a slot "extra" which is a list. I want to be
able to add an element called "name" to that list, containing the
object "value" (which can be a vector, a dataframe or another S4
object)
Obviously
setMethod("add.extra",signature=c("PM10Data","character","vector"),
function(object,name,value){
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"))
2011 Mar 11
1
WARNING Undocumented S4 methods 'initialize' - why?
Dear all,
I am just writing the documentation file for S4 class 'QualTreeSet' and
get the following warning with R CMD check:
* checking for missing documentation entries ... WARNING
Undocumented S4 methods:
generic 'initialize' and siglist 'QualTreeSet'
All user-level objects in a package (including S4 classes and methods)
should have documentation entries.
See the
2010 Dec 08
2
S4 "["-method called twice - why?
Dear list,
When playing around with the "[" method for S4 classes I noticed that it gets called twice in my example.
setClass("testClass",
representation(a="character"))
setMethod("[", signature(x = "testClass", i = "ANY", j="ANY"),
function (x, i, j, ..., drop){
print("void function")
2005 Jun 20
3
How to define S4 methods for '['
Folks:
This is a question about the S4 formal class system.
Suppose I have a class, 'foo', defined by:
setClass('foo',representation(dat='matrix', id='character') )
I wish to define a '[' method for foo that will extract from the 'dat' slot.
I would have thought that the following would work, but it doesn't:
2011 Apr 05
1
super basic questions about S4 classes
Apologies for asking something that is probably super obvious, i just started
with S4 classes and i guess i am not finding documentation that layout the
grammar rules and give enough examples. Some questions i am having are these
1. I understand that main method of writing a member function is to write a
generic function and setMethod for this particular object. This, however,
presumes that there