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

BUG: Scaling fails when the scaling column is the only ID column #82

Open
spencerpease opened this issue May 6, 2022 · 0 comments
Open
Labels
bug Something isn't working

Comments

@spencerpease
Copy link
Member

Describe the bug
When scaling data where the only ID column is the column you want to scale over, the function errors. I believe there is some internal assumption that there will be more ID columns and scale() is trying to do some grouping by those non-existent columns.

To Reproduce

library(data.table)

dt <- data.table(
  id = c("a", "a1", "a2", "a3"),
  value = c(10, 2, 3, 4)
)

mapping <- data.table(
  parent = "a",
  child = c("a1", "a2", "a3")
)

dt_scaled <- hierarchyUtils::scale(
  dt = dt,
  id_cols = "id",
  value_cols = "value",
  col_stem = "id",
  col_type = "categorical",
  mapping = mapping
)

This produces the error and warning:

Scaling id
Scaling 1 of 1: a
Error in merge.data.table(unique(children_dt[, .SD, .SDcols = by_id_cols]),  : 
  A non-empty vector of column names for `by` is required.
In addition: Warning message:
In merge.data.table(unique(children_dt[, .SD, .SDcols = by_id_cols]),  :
  You are trying to join data.tables where 'x' argument is 0 columns data.table.

Expected behavior
If the scaling column is the only ID column, no internal grouping should be applied.

Desktop (please complete the following information):

  • OS: Linux
  • R: 4.1.3
@spencerpease spencerpease added the bug Something isn't working label May 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant