Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[R-Forge #5580] invisible functions become visible in the j-expression #482

Closed
arunsrinivasan opened this issue Jun 8, 2014 · 8 comments

Comments

@arunsrinivasan
Copy link
Member

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.

@arunsrinivasan
Copy link
Member Author

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

@MichaelChirico
Copy link
Member

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

@MichaelChirico
Copy link
Member

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.

@mattdowle
Copy link
Member

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.

@MichaelChirico
Copy link
Member

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.

@arunsrinivasan
Copy link
Member Author

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

@eantonya
Copy link
Contributor

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

@jangorecki
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants