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

Bacou, Melanie mel at mbacou.com
Fri Sep 14 00:15:09 CEST 2012


Just to echo Allan's request -- I think many of us data.table users do 
work interactively at times, so the default `:=` print behavior can be a 
problem with large tables.

What would be the cons of using a default print behavior for `:=` that 
only prints top and last `n` rows as in data.table:::print.data.table ?

--Mel.

On 9/13/2012 5:41 PM, Steve Lianoglou wrote:
> Hi,
>
> On Thu, Sep 13, 2012 at 5:16 PM, Allan Engelhardt <allane at cybaea.com> wrote:
>> Is there any way of tuning off the printing when using the := assignment? I
>> have taken to writing code like
>>
>> library("data.table")
>> DT <- data.table(idx = 1:10, key = "idx")
>> for (i in 1) { # Avoid default print
>>      DT[, v := runif(idx)]
>> }
>>
>> just to avoid cluttering my screen. I could of course wrap it in invisible()
>> instead, though I am not sure that makes for much cleaner code, or use
>>
>> DT$v <- with(DT, runif(idx))
>>
>> when adding new columns. But I thought := was clever and used an
>> overallocation trick, and I of course wanted to benefit from this.
> This has come up in the past, see:
>
> https://r-forge.r-project.org/tracker/index.php?func=detail&aid=2128&group_id=240&atid=978
>
> Which also links you here for some ideas on how to get around it:
>
> http://stackoverflow.com/questions/11359553/how-to-suppress-output-when-using-in-r-data-table
>
> But, doesn't this only bite you when you are working interactively? If
> the call to `:=` is inside a function or script, then the output won't
> be printed, so ... does that mean you're writing these for() loops
> during an interactive session? (¡ouch!).
>
> For the interactive session, perhaps your easiest "fix" (for now) is
> to reassign [, := ...] back to itself, or to a one-letter dummy var
>
> HTH,
> -steve


More information about the datatable-help mailing list