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

Matthew Dowle mdowle at mdowle.plus.com
Tue Nov 8 22:41:30 CET 2011



> 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, 

We could very easily make the default changeable by user. It's just
changing the argument to be nomatch=getOption("datatable-nomatch",NA),
so then you can put "options(datatable-nomatch=0)" in your .Rprofile.
Shall we do that?

> and I end up with overwrite whole data.table function. At that time,
> data.table.fn <- function() {...} is not enough.

It would be enough, normally. But most data.table functions start with a
call to cedta() [Calling Environment Data Table Aware]. That's how the
switch to [.data.frame happens for non-datatable-aware packages.  As
soon as a function exists in .GlobalEnv, though, cedta() believes it is
datatable aware and it won't work as expected when called by a
non-datatable-aware package (guessing what the problem was in your
case). It depends on namespaces to do that, and where the function is,
see data.table:::cedta.

>  I found that I need to add scope operator ::: to overwrite internal
> function. 
Yep, should be clear why, now. Or, use assignInNamespace(). 

It's fine to do that (hence I assume why assignInNamespace is provided
by base). If a reproducible problem is posted, it'll quickly become
clear if it's in fact due to your use of assignInNamespace (or similar)
since it won't be reproducible by us, in theory. So feel free :-)

Matthew





More information about the datatable-help mailing list