Skip to content

auto-names throwing warnings+error with if/else list #4274

Closed
@robitalec

Description

@robitalec

Description

My package spatsoc v0.1.11 was returning two warnings and one error from data.table recently. I narrowed it down to version 1.12.6 vs 1.12.8, potentially the new auto-name j (#3802). These are internal warnings so not something I'm too confident diagnosing, but I did find a simple workaround that seems to make them disappear - so that might be informative for you.

The warnings:

longer object length is not a multiple of shorter object length

Different branches of j expression produced different auto-named columns: [NA!=distance]; using the most "last" names

and the error:

Internal error: jvnames is length 2 but ans is 4 and bynames is 1

The fix

The fix: assign the if/else lists and explicitly return it. Here is a commit that makes that change.

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 spatsoc's function's examples from the man.

# Install spatsoc v0.1.11
remotes::install_github('ropensci/spatsoc@v0.1.11')

# 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)

Output of sessionInfo()

R version 3.6.2 (2019-12-12)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Arch Linux

Matrix products: default
BLAS:   /usr/lib/libopenblasp-r0.3.8.so
LAPACK: /usr/lib/liblapack.so.3.9.0

locale:
 [1] LC_CTYPE=en_CA.UTF-8      
 [2] LC_NUMERIC=C              
 [3] LC_TIME=en_CA.UTF-8       
 [4] LC_COLLATE=en_CA.UTF-8    
 [5] LC_MONETARY=en_CA.UTF-8   
 [6] LC_MESSAGES=en_CA.UTF-8   
 [7] LC_PAPER=en_CA.UTF-8      
 [8] LC_NAME=C                 
 [9] LC_ADDRESS=C              
[10] LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_CA.UTF-8
[12] LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils    
[5] datasets  methods   base     

other attached packages:
[1] spatsoc_0.1.11    data.table_1.12.8

loaded via a namespace (and not attached):
[1] compiler_3.6.2 tools_3.6.2   
[3] packrat_0.5.0 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions