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

Steve Lianoglou mailinglist.honeypot at gmail.com
Thu Sep 13 23:41:56 CEST 2012


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

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