JohnCoene / echarts4r

🐳 ECharts 5 for R
http://echarts4r.john-coene.com/
Other
585 stars 82 forks source link

Error when using date time (POSIXct) on the X axis #549

Closed GillesSanMartin closed 1 year ago

GillesSanMartin commented 1 year ago

I have a piece of code which was still working 2 months ago and that triggers an error message now (not sure of which updates I made in the meanwhile). This happens when I use POSIXct date-time format for the X axis.

Reproducible example :


df <-
structure(list(Date = structure(c(1680863598, 1680863598, 1680864212, 
1680864212, 1680870200, 1680870200, 1680871367, 1680871367, 1680874534, 
1680874534, 1680880821, 1680880821, 1680882099, 1680882099, 1680891923, 
1680891923, 1680895865, 1680895865, 1680926919, 1680926919, 1680931568
), tzone = "", class = c("POSIXct", "POSIXt")), Language = c("Dutch", 
"French", "Dutch", "French", "Dutch", "French", "Dutch", "French", 
"Dutch", "French", "Dutch", "French", "Dutch", "French", "Dutch", 
"French", "Dutch", "French", "Dutch", "French", "Dutch"), Nb_replies = c(130, 
104, 131, 105, 152, 106, 183, 107, 196, 108, 220, 109, 225, 110, 
235, 110, 246, 111, 248, 112, 252)), row.names = c(NA, -21L), class = "data.frame")

df  

library(echarts4r)
df |> 
    group_by(Language) |>
    e_chart(x = Date) |> 
    e_line(serie = Nb_replies, 
           showSymbol = FALSE,
           type='category') 

Error message received :

Error in cl == "character" || cl == "factor" : 
  'length = 2' in coercion to 'logical(1)'

It works with date format

library(dplyr)
df |> 
    mutate(Date = as.Date(Date)) |> 
    group_by(Language) |>
    e_chart(x = Date) |> 
    e_line(serie = Nb_replies, 
           showSymbol = FALSE,
           type='category') 

Session info :

R version 4.3.0 (2023-04-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.2 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so;  LAPACK version 3.10.0

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

time zone: Europe/Brussels
tzcode source: system (glibc)

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

other attached packages:
[1] dplyr_1.1.1     echarts4r_0.4.4

loaded via a namespace (and not attached):
 [1] vctrs_0.6.1       cli_3.6.1         rlang_1.1.0       purrr_1.0.1       promises_1.2.0.1  generics_0.1.3   
 [7] shiny_1.7.4       jsonlite_1.8.4    xtable_1.8-4      glue_1.6.2        htmltools_0.5.5   httpuv_1.6.9     
[13] fansi_1.0.4       tibble_3.2.1      ellipsis_0.3.2    fastmap_1.1.1     yaml_2.3.7        lifecycle_1.0.3  
[19] compiler_4.3.0    htmlwidgets_1.6.2 Rcpp_1.0.10       pkgconfig_2.0.3   rstudioapi_0.14   later_1.3.0      
[25] digest_0.6.31     R6_2.5.1          tidyselect_1.2.0  utf8_1.2.3        pillar_1.9.0      magrittr_2.0.3   
[31] withr_2.5.0       tools_4.3.0       mime_0.12
JohnCoene commented 1 year ago

It's caused by R 4.3.0 changes in if statement (&& and ||), there is a fix on the latest github version of the package

GillesSanMartin commented 1 year ago

Thank you, it works indeed with the latest github version ! Sorry for the inconvenience and thank you for developing and maintaining such a great package !

JohnCoene commented 1 year ago

No worries, thanks for using the package!