data.table error: Error in is.finite(if (is.character(from)) from <- as.numeric(from) else from) : default method not implemented for type 'closure'

Hi
I am trying to fill in dates in a datatable between a start date and end date. I found below on Stackoverflow and copied the code and it worked on the example given. However when I tried it out on my similar datatable I got following error:

Error in is.finite(if (is.character(from)) from <- as.numeric(from) else from) :
default method not implemented for type 'closure'

What did you tried exactly ?

Could you ask this with a minimal REPRoducible EXample (reprex)? A reprex makes it much easier for others to understand your issue and figure out how to help.

Shot in the dark: from is a function, not a numeric value. If so, then it's also likely:

  1. This error bubbled up from inside other functions, so from isn't a variable name you've assigned.
  2. At some point in your code, you reference a value that does not exist, but there is a function of the same name.
  3. You sometimes reuse names of functions for other values.

If #3 is true, the best advice is to use unique names for variables. Otherwise, situations like this will keep happening. This can lead to long debugging sessions because the problem is in the names, not the language.

Just for clarity, here's an example of how unique names can help:

## confusing error message ----
library(data.table)
DT <- data.table(x  = c("a", "a", "b", "b"), y = 1:4)
DT2 <- DT[, list(mean = mean(y)), by = x]
DT2
#    x mean
# 1: a  1.5
# 2: b  3.5
DT2[, mean := NULL]
DT2[, is.finite(mean)]
# Error in is.finite(mean) : 
#   default method not implemented for type 'closure'

## sane error message ----
DT3 <- DT[, list(mean_y = mean(y)), by = x]
DT3
#    x mean_y
# 1: a    1.5
# 2: b    3.5
DT3[, mean_y := NULL]
DT3[, is.finite(mean_y)]
# Error in eval(jsub, SDenv, parent.frame()) : object 'mean_y' not found```

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.