[datatable-help] Override the data.frame print function

Branson Owen branson.owen at gmail.com
Tue Nov 8 18:49:38 CET 2011


Thanks for correction!

2011/11/7 Matthew Dowle <mdowle at mdowle.plus.com>

> On Mon, 2011-11-07 at 10:47 -0600, Branson Owen wrote:
> >
> >
> >         On Fri, Nov 4, 2011 at 9:15 AM, Chris Neff <caneff at gmail.com>
> >         wrote:
> >         > I'd rather have the print.data.table function override the
> >         > print.data.frame one. How can I do this?
> >
> >         Try:
> >
> >         print.data.frame <- data.table:::print.data.table
> >
> >
> > Does it create a copy of 'print.data.frame' in global environment?
>
> A copy of print.data.table, yes. It might be a copy-on-write, not sure.
>
> > > base:::print.data.frame <- data.table:::print.data.table
>
> That doesn't work, does it?
>

Oops, no. Shouldn't post my 'guess' before I even try it by myself.

>
> > If print.data.frame is always called in global environment, I guess I
> > worried too much.
>
> Are you thinking about speed here?  .GlobalEnv is always pos 1 on
> search() so those functions are found quickest. base is last on search()
> so they're actually slower if repeated many times in a loop, due to
> searching() for them.  I think compile()'d code might save the location
> in the byte code, to save the searching()ing, not sure.
>
>
Interesting! I posted that problematic suggestion is because it worked for
me in other case before. I was trying to overwrite data.table's default
argument: 'nomatch' = 0 instead of NA. I can't find a smart way to do it,
and I end up with overwrite whole data.table function. At that time,
data.table.fn <- function() {...} is not enough. I found that I need to add
scope operator ::: to overwrite internal function.

Thanks again for the correction!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20111108/2b2fbe7f/attachment.htm>


More information about the datatable-help mailing list