Data.table: [R-Forge #5580] invisible functions become visible in the j-expression

Created on 8 Jun 2014  ·  8Comments  ·  Source: Rdatatable/data.table

Submitted by: Eduard Antonyan; Assigned to: Nobody; R-Forge link

fn = function() {invisible(1:5)}

dt[, fn()]
# [1] 1 2 3 4 5

This is pretty annoying when using e.g. boxplot.

bug wontfix

Most helpful comment

No it is because R internally forces visibility on [ unlike with(). See FAQ 2.22.

All 8 comments

@eantonya could you provide an example usage with boxplot?

The problem here is very much related to :=, as explained in FAQ 2.22.

The best we can do is to return invisibly _iff_ fn() returns a data.table. Else, we'll have to modify _all_ the print methods the same way how print.data.table does cleverly using .global$print.

I've added the label 'won't fix' for now. As it's a problem with the way base R forces visibility on [. If you agree, we can close this as such (unless there's an alternative we can come up with).

Tagging @mattdowle as well.

I think this may be identical to #1471. Just found this.

It's too bad R doesn't return something with an "invisible" attribute when it is the result of invisible. That would make this easy.

Linking back to http://stackoverflow.com/a/36093766/403310 which links here. We could revisit FAQ 2.18 (the solution there didn't work for me when I just tested it) as well as 2.22 and over a year has passed since we last looked so another attempt may be due.

Hmm. Just noticed that with(dt, fn()) _doesn't_ print the output. I guess this is related to the whole .global$print issue more than anything, then.

No it is because R internally forces visibility on [ unlike with(). See FAQ 2.22.

Can't the same global print suppression that works with := work here?

as per Arun comment, we cannot do much about R's [ forcing visibility, solution is to wrap your data.table expression into invisible.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jangorecki picture jangorecki  ·  39Comments

HughParsonage picture HughParsonage  ·  61Comments

geponce picture geponce  ·  30Comments

my-R-help picture my-R-help  ·  39Comments

arunsrinivasan picture arunsrinivasan  ·  54Comments