A quick and painful example.  I will craft a better one if I have more
time...

> bigData <- 1:1e7L  # obviously this isn't "big"

> setClass("bigS4", representation(d="integer", comment="character"))
[1] "bigS4"
> s4 <- new("bigS4")
> system.time(s4@d <- bigData)
   user  system elapsed
  0.046   0.028   0.078
> system.time(s4@comment <- "comment")
   user  system elapsed
  0.045   0.028   0.074
>

>
> s3 <- list(d=NULL, comment="")
> system.time(s3$d <- bigData)
   user  system elapsed
  0.028   0.000   0.028
> system.time(s3$comment <- "comment")
   user  system elapsed
      0       0       0

Point is, the entire S4 object gets copied once you call @, whereas the list
structure (which can be a class) doesn't.

If you really want to optimize, look at using environments.  Then your
objects _won't_ ever be copied accidentally.

In the case of S4, I haven't yet found a solid use case where I can justify
the very real costs (performance and opacity).

A bigger issue is really in the Methods used for S4.  That is constantly
moving target/mess IMO.  Just 2 days ago John Chambers committed another
change that requires S3 generics for S4 classes... try keeping up with THAT
;-)

w.r.t BioC, I have no idea why or how they employ S4, all I know is that I
can't afford more copies in R than I already have to endure.

Jeff

On Mon, Jun 14, 2010 at 1:25 PM, Khanh Nguyen <nguyen.h.khanh@gmail.com>wrote:

> Hi,
>
> Thank you for your suggestions! We are hard at work :D but wanted to
> follow up on a few points. In particular S3 vs S4:
>
> On 09/06/2010 21:00, Jeff Ryan wrote:
>
> > Is there a particular reason for using S3 over S4?  I realize this isn't
> > on-topic per se, but it will affect other packages ability to use (and
> use
> > in general, as interoperability is the name of the game these days)
> >
> > S4 really isn't excellent for much at present, in my biased though rather
> > lengthy experience in this area.
> >
> > Aside from general obfuscation and bugginess to S4 itself, the only other
> > thing it can do that S3 can't do directly is dispatch on multiple args
> and
> > provide some sort of protection with respect to types per slot.
> >
> > If we restrict to a paradigm where objects only are altered with accessor
> > functions (recommended), then all the type checking can be handled there.
> >  Multiple args as far as I can tell don't/won't come into play here
> > though.
> >  At least not in a way that would warrant all the "bad" of S4.
> >
> > Additionally S4 is not overly friendly to large objects, as any slot
> > manipulation does a full object copy.  Order book is large almost by
> > definition.
>
> On Thu, Jun 10, 2010 at 4:43 AM, Patrick Burns <patrick@burns-stat.com>
> wrote:
>
> > But I'm confused.  The Bioconductor code is all
> > S4 and the genomics data they deal with is
> > usually huge.
>
> We too are confused! Our datasets will typically be ~1-2 gigabytes,
> and we would greatly appreciate any comments to help us decide between
> S3 and S4 for analyzing datasets of that size. Additionally,
> suggestions as to the best way to read in large amounts of data would
> be appreciated.
>
> Thanks,
>
> Khanh & Andrew.
>
> _______________________________________________
> R-SIG-Finance@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions
> should go.
>



-- 
Jeffrey Ryan
jeffrey.ryan@insightalgo.com

ia: insight algorithmics
www.insightalgo.com

	[[alternative HTML version deleted]]

