[R] How to figure out which the version of split is used?

William Dunlap wdunlap at tibco.com
Fri Dec 11 18:17:03 CET 2009


> -----Original Message-----
> From: r-help-bounces at r-project.org 
> [mailto:r-help-bounces at r-project.org] On Behalf Of Karl Ove Hufthammer
> Sent: Thursday, December 10, 2009 1:46 AM
> To: r-help at stat.math.ethz.ch
> Subject: Re: [R] How to figure out which the version of split is used?
> 
> On Wed, 9 Dec 2009 19:20:47 -0600 Peng Yu <pengyu.ut at gmail.com> wrote:
> > Is there a way to figure out which of these variants is actually
> > dispatched to when I call split? I know that if the 
> argument is of the
> > type data.frame, split.data.frame will be called? Is it the 
> case that
> > if the argument is not of type data.frame, Date or POSIXct,
> > split.default will be called?
> 
> Yes. See ?UseMethod

You can also use trace() to see what actually happens
in test cases.  E.g.,
  > invisible(lapply(methods("split"),
      function(method)trace(method,
      bquote(cat("Entering", .(method),
      "x=", class(x), "f=", class(f), "\n")))))
  Tracing function "split.data.frame" in package "base"
  Tracing function "split.Date" in package "base"
  Tracing function "split.default" in package "base"
  Tracing function "split.POSIXct" in package "base"
  > split(data.frame(x=1:3,y=1:3), f=c(10,10,20))
  Tracing split.data.frame(data.frame(x = 1:3, y = 1:3), f = c(10, 10,
.... on entry
  Entering split.data.frame x= data.frame f= numeric
  Tracing split.default(seq_len(nrow(x)), f, drop = drop, ...) on entry
  Entering split.default x= integer f= numeric
  $`10`
    x y
  1 1 1
  2 2 2

  $`20`
    x y
  3 3 3


Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com  

> 
> -- 
> Karl Ove Hufthammer
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 




More information about the R-help mailing list