auto-names throwing warnings+error with if/else list #4274
and the error:
The warnings and error are present in v1.12.8 but not in 1.12.6 and disappear completely with the above fix.
Minimal reproducible example
This will require an install of a couple packages, as I'm not sure how to reproduce it outside of my situation but the warnings and error can be reproduced using one of
# Install spatsoc v0.1.11 remotes::install_github('firstname.lastname@example.org') # Load packages library(data.table) library(spatsoc) # Read example data DT <- fread(system.file("extdata", "DT.csv", package = "spatsoc")) # Cast the character column to POSIXct DT[, datetime := as.POSIXct(datetime, tz = 'UTC')] # Temporal grouping group_times(DT, datetime = 'datetime', threshold = '20 minutes') # Edge list generation # NOTE: this returns the two warnings edge_nn(DT, id = 'ID', coords = c('X', 'Y'), timegroup = 'timegroup') # Edge list generation, returning distance between nearest neighbours # NOTE: this returns the two warnings and the error edge_nn(DT, id = 'ID', coords = c('X', 'Y'), timegroup = 'timegroup', threshold = 100, returnDist = TRUE)
The text was updated successfully, but these errors were encountered:
Sorry about that - I should've clarified which version of
v0.1.12 has the fix (so don't use that one)
I'll update above - the warnings+error can be reproduced with
Thanks @robitalec I see the issue:
I can see three options:
(1) explicitly add
(2) Branch your code before
I'm not sure there's any easy way to get around this from
IINM it's only possible for code like yours to succeed if the
That said, I see a logic error that can help to have made a better error message for diagnosis, at least
Thanks for looking into this so quickly @MichaelChirico.
I'll think about just simplifying this argument or evaluating it outside of the
Yes & yes. the analysis of your j "query" is done before evaluating it (evaluation might take a very long time & there's no way to know in advance that it's trivially fast, like in your case). Your workaround of returning an object assigned to the output of your if/else instead of returning directly I think is perfectly fine, with again the caveat that this could be inefficient.
if your input has 1M groups, each group will run if(returnDistance). that's 999,999 times too many & I'm not sure whether we benefit from branch prediction in such a complex program
@MichaelChirico by the way, there wasn't a noticeable difference in run time for the current version and a modified version of this function that splits the logic if(returnDistance) out of the j query.
Thank you both!