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

Use [.data.table (currently [ is dispatched to the data.frame() method) #28

Open
MichaelChirico opened this issue Jun 13, 2022 · 1 comment

Comments

@MichaelChirico
Copy link

MichaelChirico commented Jun 13, 2022

See https://cran.r-project.org/web/packages/data.table/vignettes/datatable-importing.html, relevant section "data.table in Imports but nothing imported"

Basically, because fastDummies Imports data.table but does not importFrom(data.table, ...) in its NAMESPACE, to be conservative data.table assumes that fastDummies is "unaware" of data.table [ semantics and dispatches to [.data.frame.

That's evident e.g. here:

.data <- .data[-which(names(.data) %in% char_cols)]

Where that code won't work under [.data.table. The data.table equivalent is:

.data[, !..char_cols]
# or
.data[, !char_cols, with = FALSE]
# or
.data[, .SD, .SDcols = !char_cols]

The solution is

  1. Set .datatable.aware = TRUE anywhere in the package namespace
  2. Edit [ usages to use [.data.table semantics where appropriate.

Happy to file a PR fixing this.

If [.data.frame usage is intentional, I'd recommend (1) using as.data.frame() or data.table::setDF() to make the use of [.data.frame more intentional/explicit or (2) defining .datatable.aware=FALSE in your namespace to make it clearer that this is intentional.

@jacobkap
Copy link
Owner

Hi, please make a PR. Thanks!

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