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

chaining DT using function which should return invisible result #1081

Closed
jangorecki opened this issue Mar 15, 2015 · 3 comments
Closed

chaining DT using function which should return invisible result #1081

jangorecki opened this issue Mar 15, 2015 · 3 comments

Comments

@jangorecki
Copy link
Member

The same way as := makes results invisible I would like to use my function to results invisibly (e.g. writing to database).
Currently my dt[,invisible(.SD)] makes always return visible object, which results below.
.SD only represents some transformation:

library(data.table)
dt <- data.table(a=1:2,b=letters[1:2])
f <- function(x) invisible(x)
dt[,f(.SD)] # visible result

# nice workaround can be made by:
library(magrittr)
dt[, .SD] %>% invisible # suppress any previous function results visibility
dt[, .SD] %>% f # invisible only because `f`

but the nice workaround require additional dependency in the scripts, maybe there is some trick to make it in data.table?

@arunsrinivasan
Copy link
Member

duplicate of #482. I don't think this is possible.

@jangorecki
Copy link
Member Author

maybe a simple feature:

# add to `[.data.table`
`[.data.table` <- function(...){
  on.exit({
    if(getOption("datatable.inv",FALSE)){
      # suppress print the same why as for `:=`
      options("datatable.inv"=FALSE)
  })
  # ...
}
# usage
f <- function(x){
  options("datatable.inv"=TRUE)
  x
}
dt[, f(.SD)]

@arunsrinivasan
Copy link
Member

As I wrote under #482,

I've added the label 'won't fix' for now. As it's a problem with the way base R forces visibility on [.

Even if there was a fix, it'd be dirty, and I don't think it's worth it. Let's keep the discussion on the other thread.

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

No branches or pull requests

2 participants