Skip to content

sit_traps() breaks if one of the variables is a factor.

library(sit)

## Working example from ?traps_sf()
traps_sf <- sf::st_as_sf(
  data.frame(
    x = 1:3,
    y = 3:1,
    "Trap.Id" = letters[1:3],
    Type = "BGS",
    area = "sit"
  ),
  coords = c("x", "y")
)
sit_traps(traps_sf, id = "Trap.Id", type = "Type", area = "area")
#> Simple feature collection with 3 features and 8 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 1 ymin: 1 xmax: 3 ymax: 3
#> CRS:           NA
#>   id code area label   type_name type_label type_stage type_description
#> 1  1    a  sit    NA BG-Sentinel        BGS      adult               NA
#> 2  2    b  sit    NA BG-Sentinel        BGS      adult               NA
#> 3  3    c  sit    NA BG-Sentinel        BGS      adult               NA
#>      geometry
#> 1 POINT (1 3)
#> 2 POINT (2 2)
#> 3 POINT (3 1)

## Issue when one of the variables is a factor
traps_sf$area <- factor(traps_sf$area)
sit_traps(
  traps_sf,
  id = "Trap.Id", type = "Type", area = "area"
)
#> Error in lapply(x[i], as.numeric): 'list' object cannot be coerced to type 'double'

Created on 2023-03-05 with reprex v2.0.2

Edited by Facundo Muñoz