[datatable-help] Avoiding print when using := ?

Steve Lianoglou mailinglist.honeypot at gmail.com
Fri Sep 14 13:43:14 CEST 2012


While taking my dog for a walk, though, I was wondering if we couldn't
hijack the `history` mechanism in the `print.data.table` function to
do this "better".

We might first check `if (interactive())`, then see if the last call
involved `:=`, in which case we could just silence the print ... just
a thought.

-steve

On Fri, Sep 14, 2012 at 7:22 AM, Steve Lianoglou
<mailinglist.honeypot at gmail.com> wrote:
> Hi,
>
> On Fri, Sep 14, 2012 at 1:56 AM, Allan Engelhardt (CYBAEA)
> <allane at cybaea.com> wrote:
>> On 13/09/12 23:42, Steve Lianoglou wrote:
>>>
>>> Perhaps the `nrows` param in print.data.table should be user
>>> configurable by some `option`, maybe something like:
>>>
>>> print.data.table <- function(x,
>>> nrows=getOption('datatable.print.nrows', 100), ...) { ... }
>>>
>>> Then you could `options(datatable.print.nrows=20)` if 100 is too high ...
>>>
>>> Maybe?
>>>
>>> -steve
>>
>>
>> I really like this suggestion. You could perhaps even set it to 0
>> temporarily while you were doing lots of := work. Do you want to raise a
>> feature request Steve?
>
> I just committed code to SVN to support this. In short there are two
> new `options` one can set to customize the amount of a data.table
> summariazed to the console (these can always be sidestepped by calling
> `print(dt)` directly).
>
> The options are:
>
> * datatable.print.nrows : When the data.table has more than this
> number (defaults to 100) the `---` summary stuff is triggered. If this
> is set to 0, no data.table will be printed to the console unless you
> call `print(your.data.table, ...)`
>
> * datatable.print.topn : When a summary is triggered during printing,
> this number show the top and bottom `topn` rows (defaults to 10)
>
> FAQs 2.11 and 2.22 to show you how you might use it, but in short:
>
> R> library(data.table)
> R> dt = data.table(a=letters[1:10], b=rnorm(10))
> R> options(datatable.print.nrows=8)
> R> dt
>     a          b
>  1: a -1.1423662
>  2: b  0.2878413
> ---
>  9: i -0.1247109
> 10: j -0.6932983
>
> R> dt[, something := rnorm(10)]
>     a          b    something
>  1: a -1.1423662  0.700697859
>  2: b  0.2878413 -0.007995077
> ---
>  9: i -0.1247109  0.060807862
> 10: j -0.6932983 -0.796266433
>
> R> options(datatable.print.nrows=0)
> R> dt[, another := runif(10)]
> R> print(dt, 100)
>     a          b    something   another
>  1: a -1.1423662  0.700697859 0.3831220
>  2: b  0.2878413 -0.007995077 0.3894803
>  3: c -0.9657560 -0.511566173 0.1208057
>  4: d -0.1065197  0.685830341 0.2878074
>  5: e -0.7630674 -0.161960447 0.3378524
>  6: f -1.1561141  0.464995932 0.2487832
>  7: g  0.2408447 -0.175998144 0.8600236
>  8: h -0.4386328  1.002378381 0.7682450
>  9: i -0.1247109  0.060807862 0.1635926
> 10: j -0.6932983 -0.796266433 0.4739380
>
> The caveat is that I didn't check in with Matthew to see if he's OK
> with this, so unless he objects ... there it is. It is in SVN now (at
> r-forge), and you can grab it from there and install. If you aren't
> setup to do that, you will have to wait for 1.8.3 to release.
>
> The other thing is that this really doesn't address the `:=` printing
> behavior specifically, so not sure how helpful this is in the long run
> unless you don't mind calling `print` to view things explicitly.
>
> HTH,
> -steve
>
> --
> Steve Lianoglou
> Graduate Student: Computational Systems Biology
>  | Memorial Sloan-Kettering Cancer Center
>  | Weill Medical College of Cornell University
> Contact Info: http://cbio.mskcc.org/~lianos/contact



-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact


More information about the datatable-help mailing list