mablab / sftrack

sftrack: Modern classes for tracking and movement data
https://mablab.org/sftrack/
Other
53 stars 2 forks source link

Bug with integer timestamps: Error in if (tcl == "POSIXct") { : argument is of length zero #30

Closed basille closed 4 years ago

basille commented 4 years ago

If we start with this simple data.frame:

df1 <- data.frame(
    id = rep(1, 10),
    time = 1:10,
    weather = c("clear", "windy", "clear", "windy", "clear", "clear", "rainy", "clear", "cloudy", "cloudy"),
    x = c(0, 1, 1, 1, NA, 2, 3, 1, 2, 2),
    y = c(0, 0, 1, 1, NA, 0, 1, 1, 2, 2)
)

Conversion to sftrack fails on my system:

library("sftrack")
mysftrack <- as_sftrack(data = df1, group = "id", coords = c("x", "y"), time = "time")
## Error in if (tcl == "POSIXct") { : argument is of length zero

The error shows at the very last line (return(ret)), but I'm not exactly sure why. Here is more information in debug mode, right before the error:

Browse[3]> 
debug: return(ret)
Browse[3]> ret
Error in if (tcl == "POSIXct") { : argument is of length zero
Browse[3]> str(ret)
Classes ‘sftrack’, ‘sf’ and 'data.frame':   10 obs. of  7 variables:
 $ id       : num  1 1 1 1 1 1 1 1 1 1
 $ time     : int  1 2 3 4 5 6 7 8 9 10
 $ weather  : Factor w/ 4 levels "clear","cloudy",..: 1 4 1 4 1 1 3 1 2 2
 $ x        : num  0 1 1 1 NA 2 3 1 2 2
 $ y        : num  0 0 1 1 NA 0 1 1 2 2
 $ sft_group:c_grouping object 
List of 10
 $ :List of 1
  ..$ id: chr "1"
  ..- attr(*, "class")= chr "s_group"
  [list output truncated]
 - attr(*, "active_group")= chr "id"
 - attr(*, "sort_index")= Factor w/ 1 level "1": 1 1 1 1 1 1 1 1 1 1
 $ geometry :sfc_POINT of length 10; first list element: Classes 'XY', 'POINT', 'sfg'  num [1:2] 0 0
 - attr(*, "sf_column")= chr "geometry"
 - attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA NA
  ..- attr(*, "names")= chr  "id" "time" "weather" "x" ...
 - attr(*, "group_col")= chr "sft_group"
 - attr(*, "time_col")= chr "time"
 - attr(*, "error_col")= logi NA
Browse[3]> as.data.frame(ret)
   id time weather  x  y sft_group    geometry
1   1    1   clear  0  0   (id: 1) POINT (0 0)
2   1    2   windy  1  0   (id: 1) POINT (1 0)
3   1    3   clear  1  1   (id: 1) POINT (1 1)
4   1    4   windy  1  1   (id: 1) POINT (1 1)
5   1    5   clear NA NA   (id: 1) POINT EMPTY
6   1    6   clear  2  0   (id: 1) POINT (2 0)
7   1    7   rainy  3  1   (id: 1) POINT (3 1)
8   1    8   clear  1  1   (id: 1) POINT (1 1)
9   1    9  cloudy  2  2   (id: 1) POINT (2 2)
10  1   10  cloudy  2  2   (id: 1) POINT (2 2)
Browse[3]> attributes(ret)
$names
[1] "id"        "time"      "weather"   "x"         "y"         "sft_group"
[7] "geometry" 

$row.names
 [1]  1  2  3  4  5  6  7  8  9 10

$class
[1] "sftrack"    "sf"         "data.frame"

$sf_column
[1] "geometry"

$agr
       id      time   weather         x         y sft_group 
     <NA>      <NA>      <NA>      <NA>      <NA>      <NA> 
Levels: constant aggregate identity

$group_col
[1] "sft_group"

$time_col
[1] "time"

$error_col
[1] NA

Session info:

> sessionInfo()
R version 3.3.3 (2017-03-06)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 9 (stretch)

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

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

other attached packages:
[1] sftrack_0.5

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.5         lubridate_1.7.9    class_7.3-14       crayon_1.3.4      
 [5] sf_0.9-6           dplyr_1.0.0        grid_3.3.3         R6_2.4.1          
 [9] lifecycle_0.2.0    DBI_1.1.0          magrittr_1.5       e1071_1.7-3       
[13] units_0.6-7        pillar_1.4.6       KernSmooth_2.23-15 rlang_0.4.7       
[17] ellipsis_0.3.1     vctrs_0.3.2        generics_0.0.2     tools_3.3.3       
[21] glue_1.4.1         purrr_0.3.4        compiler_3.3.3     pkgconfig_2.0.3   
[25] classInt_0.4-3     tidyselect_1.1.0   tibble_3.0.3      
birderboone commented 4 years ago

Try with the new version. I pushed this to master yesterday but I doubt you had reinstalled the latest version since then.

basille commented 4 years ago

Works beautifully now. I had updated very recently, but did not bother update right before reporting since the version number did not change yet! Closing now.