Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: arguments have different crs #479

Closed
PedroBelavenutti opened this issue Mar 22, 2023 · 24 comments
Closed

Error: arguments have different crs #479

PedroBelavenutti opened this issue Mar 22, 2023 · 24 comments
Labels

Comments

@PedroBelavenutti
Copy link

When using sf object

@PedroBelavenutti
Copy link
Author

Is it a problem that is only happening to me?

@greyja
Copy link

greyja commented Mar 27, 2023

Happening for me as well using code that worked ~3 weeks ago

@GB-IHE
Copy link

GB-IHE commented Mar 28, 2023

I have the same issue tryin gto use it for aminating a ggplot map.

@kostis-christodoulou
Copy link

I get the same error.

Tried to run the solution referenced here https://stackoverflow.com/questions/68450668/how-can-i-animate-points-on-a-spatial-map-with-gganimate-sf-and-ggplot2 and I get ' Error: arguments have different crs'

R version 4.2.3 (2023-03-15)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Ventura 13.3

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] viridis_0.6.2 viridisLite_0.4.1 tmap_3.3-3 mapview_2.11.0 patchwork_1.1.2 classInt_0.4-9
[7] gganimate_1.0.8 wbstats_1.0.4 rnaturalearth_0.3.2 sf_1.0-12 lubridate_1.9.2 forcats_1.0.0
[13] stringr_1.5.0 purrr_1.0.1 readr_2.1.4 tidyr_1.3.0 tibble_3.2.1 ggplot2_3.4.1
[19] tidyverse_2.0.0

loaded via a namespace (and not attached):
[1] satellite_1.0.4 bit64_4.0.5 webshot_0.5.4 RColorBrewer_1.1-3 progress_1.2.2
[6] httr_1.4.5 repr_1.1.6 tools_4.2.3 bslib_0.4.2 utf8_1.2.3
[11] R6_2.5.1 KernSmooth_2.23-20 DBI_1.1.3 colorspace_2.1-0 raster_3.6-20
[16] withr_2.5.0 sp_1.6-0 rnaturalearthdata_0.1.0 tidyselect_1.2.0 gridExtra_2.3
[21] prettyunits_1.1.1 leaflet_2.1.2 bit_4.0.5 curl_5.0.0 compiler_4.2.3
[26] leafem_0.2.0 cli_3.6.1 labeling_0.4.2 sass_0.4.5 scales_1.2.1
[31] proxy_0.4-27 digest_0.6.31 base64enc_0.1-3 dichromat_2.0-0.1 pkgconfig_2.0.3
[36] htmltools_0.5.5 fastmap_1.1.1 htmlwidgets_1.6.2 rlang_1.1.0 rstudioapi_0.14
[41] jquerylib_0.1.4 farver_2.1.1 generics_0.1.3 jsonlite_1.8.4 crosstalk_1.2.0
[46] vroom_1.6.1 dplyr_1.1.1 magrittr_2.0.3 s2_1.1.2 Rcpp_1.0.10
[51] munsell_0.5.0 fansi_1.0.4 abind_1.4-5 lifecycle_1.0.3 terra_1.7-18
[56] stringi_1.7.12 leafsync_0.1.0 tmaptools_3.1-1 grid_4.2.3 parallel_4.2.3
[61] crayon_1.5.2 lattice_0.20-45 stars_0.6-0 hms_1.1.3 transformr_0.1.4
[66] knitr_1.42 pillar_1.9.0 codetools_0.2-19 lpSolve_5.6.18 stats4_4.2.3
[71] wk_0.7.2 XML_3.99-0.14 glue_1.6.2 gifski_1.6.6-1 png_0.1-8
[76] vctrs_0.6.1 tzdb_0.3.0 tweenr_2.0.2 gtable_0.3.3 cachem_1.0.7
[81] xfun_0.38 skimr_2.1.5 lwgeom_0.2-11 e1071_1.7-13 class_7.3-21
[86] units_0.8-1 timechange_0.2.0

@mpjashby
Copy link

mpjashby commented Apr 5, 2023

Just to provide a reprex for this error, which I'm seeing with gganimate version 1.0.8:

# Load packages
library(gganimate)
#> Loading required package: ggplot2
library(sf)
#> Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
library(tidyverse)


# Load aggravated assaults, Chicago, 2010 to 2019
assaults <- read_csv("https://mpjashby.github.io/crimemappingdata/chicago_aggravated_assaults.csv.gz")
#> Rows: 148636 Columns: 5
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ","
#> chr  (1): loc_cat
#> dbl  (3): longitude, latitude, district
#> dttm (1): date
#> 
#> ℹ Use `spec()` to retrieve the full column specification for this data.
#> ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

# Calculate number of assaults each hour
hour_layers <- assaults |> 
  mutate(hour_name = hour(date)) |> 
  st_as_sf(coords = c("longitude", "latitude"), crs = "EPSG:4326")

# Create map
ggplot() +
  geom_sf(data = hour_layers) +
  transition_states(states = hour_name)
#> Error: arguments have different crs

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

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.2.2 (2022-10-31)
#>  os       macOS Ventura 13.3
#>  system   aarch64, darwin20
#>  ui       X11
#>  language (EN)
#>  collate  en_US.UTF-8
#>  ctype    en_US.UTF-8
#>  tz       Europe/London
#>  date     2023-04-05
#>  pandoc   2.19.2 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date (UTC) lib source
#>  bit           4.0.5   2022-11-15 [1] CRAN (R 4.2.0)
#>  bit64         4.0.5   2020-08-30 [1] CRAN (R 4.2.0)
#>  class         7.3-21  2023-01-23 [1] CRAN (R 4.2.0)
#>  classInt      0.4-9   2023-02-28 [1] CRAN (R 4.2.0)
#>  cli           3.6.1   2023-03-23 [1] CRAN (R 4.2.0)
#>  colorspace    2.1-0   2023-01-23 [1] CRAN (R 4.2.0)
#>  crayon        1.5.2   2022-09-29 [1] CRAN (R 4.2.0)
#>  curl          5.0.0   2023-01-12 [1] CRAN (R 4.2.0)
#>  DBI           1.1.3   2022-06-18 [1] CRAN (R 4.2.0)
#>  digest        0.6.31  2022-12-11 [1] CRAN (R 4.2.0)
#>  dplyr       * 1.1.1   2023-03-22 [1] CRAN (R 4.2.0)
#>  e1071         1.7-13  2023-02-01 [1] CRAN (R 4.2.0)
#>  ellipsis      0.3.2   2021-04-29 [1] CRAN (R 4.2.0)
#>  evaluate      0.20    2023-01-17 [1] CRAN (R 4.2.0)
#>  fansi         1.0.4   2023-01-22 [1] CRAN (R 4.2.0)
#>  farver        2.1.1   2022-07-06 [1] CRAN (R 4.2.0)
#>  fastmap       1.1.1   2023-02-24 [1] CRAN (R 4.2.0)
#>  forcats     * 1.0.0   2023-01-29 [1] CRAN (R 4.2.0)
#>  fs            1.6.1   2023-02-06 [1] CRAN (R 4.2.0)
#>  generics      0.1.3   2022-07-05 [1] CRAN (R 4.2.0)
#>  gganimate   * 1.0.8   2022-09-08 [1] CRAN (R 4.2.0)
#>  ggplot2     * 3.4.1   2023-02-10 [1] CRAN (R 4.2.0)
#>  gifski        1.6.6-1 2022-04-05 [1] CRAN (R 4.2.0)
#>  glue          1.6.2   2022-02-24 [1] CRAN (R 4.2.0)
#>  gtable        0.3.3   2023-03-21 [1] CRAN (R 4.2.2)
#>  hms           1.1.2   2022-08-19 [1] CRAN (R 4.2.0)
#>  htmltools     0.5.4   2022-12-07 [1] CRAN (R 4.2.0)
#>  KernSmooth    2.23-20 2021-05-03 [1] CRAN (R 4.2.2)
#>  knitr         1.42    2023-01-25 [1] CRAN (R 4.2.0)
#>  lifecycle     1.0.3   2022-10-07 [1] CRAN (R 4.2.0)
#>  lpSolve       5.6.18  2023-02-01 [1] CRAN (R 4.2.0)
#>  lubridate   * 1.9.2   2023-02-10 [1] CRAN (R 4.2.0)
#>  magrittr      2.0.3   2022-03-30 [1] CRAN (R 4.2.0)
#>  munsell       0.5.0   2018-06-12 [1] CRAN (R 4.2.0)
#>  pillar        1.9.0   2023-03-22 [1] CRAN (R 4.2.0)
#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.2.0)
#>  prettyunits   1.1.1   2020-01-24 [1] CRAN (R 4.2.0)
#>  progress      1.2.2   2019-05-16 [1] CRAN (R 4.2.0)
#>  proxy         0.4-27  2022-06-09 [1] CRAN (R 4.2.0)
#>  purrr       * 1.0.1   2023-01-10 [1] CRAN (R 4.2.0)
#>  R.cache       0.16.0  2022-07-21 [1] CRAN (R 4.2.0)
#>  R.methodsS3   1.8.2   2022-06-13 [1] CRAN (R 4.2.0)
#>  R.oo          1.25.0  2022-06-12 [1] CRAN (R 4.2.0)
#>  R.utils       2.12.2  2022-11-11 [1] CRAN (R 4.2.0)
#>  R6            2.5.1   2021-08-19 [1] CRAN (R 4.2.0)
#>  Rcpp          1.0.10  2023-01-22 [1] CRAN (R 4.2.0)
#>  readr       * 2.1.4   2023-02-10 [1] CRAN (R 4.2.0)
#>  reprex        2.0.2   2022-08-17 [1] CRAN (R 4.2.0)
#>  rlang         1.1.0   2023-03-14 [1] CRAN (R 4.2.2)
#>  rmarkdown     2.20    2023-01-19 [1] CRAN (R 4.2.0)
#>  rstudioapi    0.14    2022-08-22 [1] CRAN (R 4.2.0)
#>  scales        1.2.1   2022-08-20 [1] CRAN (R 4.2.0)
#>  sessioninfo   1.2.2   2021-12-06 [1] CRAN (R 4.2.0)
#>  sf          * 1.0-12  2023-03-19 [1] CRAN (R 4.2.0)
#>  stringi       1.7.12  2023-01-11 [1] CRAN (R 4.2.0)
#>  stringr     * 1.5.0   2022-12-02 [1] CRAN (R 4.2.0)
#>  styler        1.9.1   2023-03-04 [1] CRAN (R 4.2.0)
#>  tibble      * 3.2.1   2023-03-20 [1] CRAN (R 4.2.2)
#>  tidyr       * 1.3.0   2023-01-24 [1] CRAN (R 4.2.0)
#>  tidyselect    1.2.0   2022-10-10 [1] CRAN (R 4.2.0)
#>  tidyverse   * 2.0.0   2023-02-22 [1] CRAN (R 4.2.0)
#>  timechange    0.2.0   2023-01-11 [1] CRAN (R 4.2.0)
#>  transformr    0.1.4   2022-08-18 [1] CRAN (R 4.2.0)
#>  tweenr        2.0.2   2022-09-06 [1] CRAN (R 4.2.0)
#>  tzdb          0.3.0   2022-03-28 [1] CRAN (R 4.2.0)
#>  units         0.8-1   2022-12-10 [1] CRAN (R 4.2.0)
#>  utf8          1.2.3   2023-01-31 [1] CRAN (R 4.2.0)
#>  vctrs         0.6.1   2023-03-22 [1] CRAN (R 4.2.0)
#>  vroom         1.6.1   2023-01-22 [1] CRAN (R 4.2.0)
#>  withr         2.5.0   2022-03-03 [1] CRAN (R 4.2.0)
#>  xfun          0.37    2023-01-31 [1] CRAN (R 4.2.0)
#>  yaml          2.3.7   2023-01-23 [1] CRAN (R 4.2.0)
#> 
#>  [1] /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────

@ttalVlatt
Copy link

This appears to be a somewhat widespread bug. It seems it will happily animate a geom_sf with no crs, but when one is applied it spits the error out

library(tidyverse)
library(sf)
library(gganimate)

df <- quakes %>%
  st_as_sf(coords = c("long", "lat"))

## No CRS
st_crs(df)

## Runs fine
ggplot(df) +
  geom_sf(aes(color = mag)) +
  transition_time(stations)

## Apply a CRS
df_crs <- quakes %>%
  st_as_sf(coords = c("long", "lat"),
           crs = 4326)

## Gets the error
ggplot(df_crs) +
  geom_sf(aes(color = mag)) +
  transition_time(stations)

@jpkrooney
Copy link

jpkrooney commented Apr 23, 2023

Just to provide a reprex for this error, which I'm seeing with gganimate version 1.0.8:

Can confirm reprex reproduces the error here too. Sharing sessioninfo:

> sessionInfo()
R version 4.1.3 (2022-03-10)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Monterey 12.6

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
 [1] lubridate_1.9.2 forcats_1.0.0   stringr_1.5.0   dplyr_1.1.2     purrr_1.0.1     readr_2.1.4     tidyr_1.3.0    
 [8] tibble_3.2.1    tidyverse_2.0.0 sf_1.0-12       gganimate_1.0.8 ggplot2_3.4.2  

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.10           pillar_1.9.0          compiler_4.1.3        prettyunits_1.1.1     class_7.3-20         
 [6] tools_4.1.3           progress_1.2.2        bit_4.0.4             timechange_0.2.0      lifecycle_1.0.3      
[11] gtable_0.3.0          pkgconfig_2.0.3       rlang_1.1.0           cli_3.6.1             DBI_1.1.2            
[16] rstudioapi_0.14       magick_2.7.3          curl_4.3.2            parallel_4.1.3        e1071_1.7-9          
[21] transformr_0.1.4.9000 withr_2.5.0           generics_0.1.3        vctrs_0.6.2           hms_1.1.2            
[26] bit64_4.0.5           classInt_0.4-8        grid_4.1.3            tidyselect_1.2.0      glue_1.6.2           
[31] R6_2.5.1              fansi_1.0.3           vroom_1.6.1           tzdb_0.3.0            tweenr_2.0.2         
[36] farver_2.1.1          magrittr_2.0.3        units_0.8-0           scales_1.2.0          ellipsis_0.3.2       
[41] lpSolve_5.6.15        colorspace_2.0-3      KernSmooth_2.23-20    utf8_1.2.2            stringi_1.7.8        
[46] proxy_0.4-26          munsell_0.5.0         crayon_1.5.1         
> 

@jamesgasek
Copy link

also experienceing this issue, bump

@phdmi-sctimst
Copy link

Same issue here.

@TheAviationDoctor
Copy link

TheAviationDoctor commented May 6, 2023

Seeing this issue as well on a ggplot2 choropleth map with geom_sf data points that I am animating with gganimate's transition_states.

Relevant sessionInfo dump:

> sessionInfo()
R version 4.3.0 (2023-04-21 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22621)

other attached packages:
 [1] transformr_0.1.4        lubridate_1.9.2         forcats_1.0.0           stringr_1.5.0           dplyr_1.1.2             purrr_1.0.1             readr_2.1.4             tidyr_1.3.0            
 [9] tibble_3.2.1            tidyverse_2.0.0         sf_1.0-12               rnaturalearthdata_0.1.0 rnaturalearth_0.3.2     gganimate_1.0.8         ggplot2_3.4.2          

loaded via a namespace (and not attached):
 [1] utf8_1.2.3         generics_0.1.3     class_7.3-21       lpSolve_5.6.18     KernSmooth_2.23-20 stringi_1.7.12     lattice_0.21-8     hms_1.1.3          magrittr_2.0.3     timechange_0.2.0  
[11] grid_4.3.0         jsonlite_1.8.4     progress_1.2.2     e1071_1.7-13       DBI_1.1.3          httr_1.4.5         fansi_1.0.4        scales_1.2.1       tweenr_2.0.2       cli_3.6.1         
[21] rlang_1.1.1        crayon_1.5.2       units_0.8-2        bit64_4.0.5        munsell_0.5.0      withr_2.5.0        parallel_4.3.0     tools_4.3.0        tzdb_0.3.0         colorspace_2.1-0  
[31] vctrs_0.6.2        R6_2.5.1           proxy_0.4-27       lifecycle_1.0.3    classInt_0.4-9     bit_4.0.5          vroom_1.6.3        pkgconfig_2.0.3    pillar_1.9.0       gtable_0.3.3      
[41] data.table_1.14.8  glue_1.6.2         Rcpp_1.0.10        tidyselect_1.2.0   rstudioapi_0.14    farver_2.1.1       compiler_4.3.0     prettyunits_1.1.1  sp_1.6-0

Edit: Found a temporary workaround. I downgraded gganimate from v1.0.8 to v1.0.7 using the following syntax:

remove.packages("gganimate")

install.packages("https://cran.r-project.org/src/contrib/Archive/gganimate/gganimate_1.0.7.tar.gz", repos = NULL, type = "source")

Unexpectedly, that did not resolve the issue. So I also downgraded transformr from v0.1.4 to v0.1.3 as follows:

remove.packages("transformr")

install.packages("https://cran.r-project.org/src/contrib/Archive/transformr/transformr_0.1.3.tar.gz", repos = NULL, type = "source")

And now my animation is working again.

@kbvernon
Copy link

kbvernon commented Aug 20, 2023

Here's another reprex, but just adapting the transformr example (where the crs is normally missing):

library(sf)
library(transformr)

star_hole <- poly_star_hole(st = TRUE)
circles <- poly_circles(st = TRUE)
spiral <- path_spiral(st = TRUE)
waves <- path_waves(st = TRUE)
random <- point_random(st = TRUE)
grid <- point_grid(st = TRUE)

# include crs in st_sfc()
df1 <- data.frame(geo = sf::st_sfc(star_hole, spiral, random, crs = 4326))
df2 <- data.frame(geo = sf::st_sfc(circles, waves, grid, crs = 4326))

tween_sf(df1, df2, 'linear', 30)
# Error: arguments have different crs

I believe the point where the crs is being dropped is here, with the call to tween_sf_col(): https://github.com/thomasp85/transformr/blob/edea9ce38b56c9c2ce47c534def2865f91d82bad/R/tween_sf.R#L69

The issue is that the call to st_sfc() never adds a crs back in, so when it tries to rbind() the tweened states without crs to the original sf with crs, the error occurs.

Or, at least, that's my best guess. I mean, if it's right, it makes it kinda mysterious why this ever worked at all...

Actually, just checked, and the error is now occurring because vctrs::vec_rbind() has a stronger check on the column type than rbind() does (switching from one to the other was the big change in the latest release).

df1 <- data.frame(geo = sf::st_sfc(star_hole, spiral, random, crs = 4326))
df3 <- data.frame(geo = sf::st_sfc(star_hole, spiral, random))

rbind(df1, df3)
#                         geometry
# 1 POLYGON ((0 1, 0.2938926 0....
# 2 LINESTRING (0 0, 0.00050334...
# 3 MULTIPOINT ((0.6164571 0.89...
# 4 POLYGON ((0 1, 0.2938926 0....
# 5 LINESTRING (0 0, 0.00050334...
# 6 MULTIPOINT ((0.6164571 0.89...

vctrs::vec_rbind(df1, df3)
# Error: arguments have different crs

Interestingly enough, rbind() updates the missing crs with the existing crs. I don't think this would happen though if these data.frames had class sf.

@thomasp85, would you like a pull-request to fix this? I think just adding crs = sf::st_crs(from$geometry) to st_sfc() will fix it, but happy to do that myself if you want.

@thomasp85 thomasp85 added the bug label Aug 30, 2023
@thomasp85
Copy link
Owner

I am not able to reproduce any of these issues. My guess is that this was fixed upstream, but can some of you confirm with the latest dev versions of the involved packages that it behaves as it should?

@kbvernon
Copy link

Ah, yeah, should have included the package versions, sorry. Here's how I did this last time:

library(sf)
library(transformr)
library(vctrs)

packageVersion("sf")
# [1] ‘1.0.14'
packageVersion("transformr")
# [1] ‘0.1.4’
packageVersion("vctrs")
# [1] ‘0.6.3’

df1 <- data.frame(geo = sf::st_sfc(poly_star_hole(st = TRUE), crs = 4326))
df3 <- data.frame(geo = sf::st_sfc(poly_star_hole(st = TRUE)))
 
rbind(df1, df3)
#                         geometry
# 1 POLYGON ((0 1, 0.2938926 0....
# 2 POLYGON ((0 1, 0.2938926 0....

vec_rbind(df1, df3)
# Error: arguments have different crs

After restarting the R session and updating packages (looks like I had basically the most up-to-date versions), still getting the error:

pak::pak("r-spatial/sf")
pak::pak("thomasp85/transformr")
pak::pak("r-lib/vctrs")

library(sf)
library(transformr)
library(vctrs)

packageVersion("sf")
# ‘1.0.14’
packageVersion("transformr")
# ‘0.1.4.9000’
packageVersion("vctrs")
# ‘0.6.3.9000’

df1 <- data.frame(geo = sf::st_sfc(poly_star_hole(st = TRUE), crs = 4326))
df3 <- data.frame(geo = sf::st_sfc(poly_star_hole(st = TRUE)))

rbind(df1, df3)
#                         geometry
# 1 POLYGON ((0 1, 0.2938926 0....
# 2 POLYGON ((0 1, 0.2938926 0....

vec_rbind(df1, df3)
# Error: arguments have different crs

Here's the full session info:

sessioninfo::session_info()
─ Session info ──────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.3.1 (2023-06-16 ucrt)
 os       Windows 11 x64 (build 22621)
 system   x86_64, mingw32
 ui       RStudio
 language (EN)
 collate  English_United States.utf8
 ctype    English_United States.utf8
 tz       America/Denver
 date     2023-08-30
 rstudio  2023.06.1+524 Mountain Hydrangea (desktop)
 pandoc   NA

─ Packages ──────────────────────────────────────────────────────────────────
 package     * version    date (UTC) lib source
 class         7.3-22     2023-05-03 [2] CRAN (R 4.3.1)
 classInt      0.4-9      2023-02-28 [1] CRAN (R 4.3.1)
 cli           3.6.1      2023-03-23 [1] CRAN (R 4.3.1)
 DBI           1.1.3      2022-06-18 [1] CRAN (R 4.3.1)
 dplyr         1.1.2      2023-04-20 [1] CRAN (R 4.3.1)
 e1071         1.7-13     2023-02-01 [1] CRAN (R 4.3.1)
 fansi         1.0.4      2023-01-22 [1] CRAN (R 4.3.1)
 farver        2.1.1      2022-07-06 [1] CRAN (R 4.3.1)
 generics      0.1.3      2022-07-05 [1] CRAN (R 4.3.1)
 glue          1.6.2      2022-02-24 [1] CRAN (R 4.3.1)
 KernSmooth    2.23-21    2023-05-03 [2] CRAN (R 4.3.1)
 lifecycle     1.0.3      2022-10-07 [1] CRAN (R 4.3.1)
 lpSolve       5.6.18     2023-02-01 [1] CRAN (R 4.3.0)
 magrittr      2.0.3      2022-03-30 [1] CRAN (R 4.3.1)
 pillar        1.9.0      2023-03-22 [1] CRAN (R 4.3.1)
 pkgconfig     2.0.3      2019-09-22 [1] CRAN (R 4.3.1)
 proxy         0.4-27     2022-06-09 [1] CRAN (R 4.3.1)
 R6            2.5.1      2021-08-19 [1] CRAN (R 4.3.1)
 Rcpp          1.0.11     2023-07-06 [1] CRAN (R 4.3.1)
 rlang         1.1.1      2023-04-28 [1] CRAN (R 4.3.1)
 rstudioapi    0.15.0     2023-07-07 [1] CRAN (R 4.3.1)
 sessioninfo   1.2.2      2021-12-06 [1] CRAN (R 4.3.1)
 sf          * 1.0-14     2023-08-30 [1] Github (r-spatial/sf@e45ceca)
 tibble        3.2.1      2023-03-20 [1] CRAN (R 4.3.1)
 tidyselect    1.2.0      2022-10-10 [1] CRAN (R 4.3.1)
 transformr  * 0.1.4.9000 2023-08-30 [1] Github (thomasp85/transformr@edea9ce)
 tweenr        2.0.2      2022-09-06 [1] CRAN (R 4.3.1)
 units         0.8-2      2023-04-27 [1] CRAN (R 4.3.1)
 utf8          1.2.3      2023-01-31 [1] CRAN (R 4.3.1)
 vctrs       * 0.6.3.9000 2023-08-30 [1] Github (r-lib/vctrs@8bbd8c4)

 [1] C:/***
 [2] C:/***

─────────────────────────────────────────────────────────────────────────────

@kbvernon
Copy link

Sorry, here's this with tween_sf() to:

library(sf)
library(transformr)
library(vctrs)

packageVersion("sf")
# ‘1.0.14’
packageVersion("transformr")
# ‘0.1.4.9000’
packageVersion("vctrs")
# ‘0.6.3.9000’

df1 <- data.frame(geo = sf::st_sfc(poly_star_hole(st = TRUE), crs = 4326))
df2 <- data.frame(geo = sf::st_sfc(poly_star_hole(st = TRUE)))
df3 <- data.frame(geo = sf::st_sfc(poly_star_hole(st = TRUE)))

tween_sf(df1, df2, 'linear', 30)
# Error: arguments have different crs

tween_sf(df2, df3, 'linear', 30) |> head()
#                         geometry .id     .phase .frame
# 1 POLYGON ((0 1, 0.2938926 0....   1        raw      1
# 2 MULTIPOLYGON (((0 1, 0.0587...   1 transition      2
# 3 MULTIPOLYGON (((0 1, 0.0587...   1 transition      3
# 4 MULTIPOLYGON (((0 1, 0.0587...   1 transition      4
# 5 MULTIPOLYGON (((0 1, 0.0587...   1 transition      5
# 6 MULTIPOLYGON (((0 1, 0.0587...   1 transition      6

@thomasp85
Copy link
Owner

Thanks - this appears to be caused by changes in sf then... I'll investigate

In any case it is a tweenr/transformr issue, but let us just keep the issue here

@thomasp85
Copy link
Owner

Should be fixed in dev transformr now

@anarvaezv
Copy link

anarvaezv commented Oct 10, 2023

I still have the problem with the new versions. I have checked, The problem is not in gganimate but in transformr . transformr 0.1.3 works perfect

@michaelschulte
Copy link

I still have the problem with the new versions. I have checked, The problem is not in gganimate but in transformr . transformr 0.1.3 works perfect

same here ... old version works - new one breaks

@TarJae
Copy link

TarJae commented Nov 2, 2023

I can confirm @michaelschulte . After installing Version 1.6.3 of transformr package. The Error: arguments have different crs disappear. First start a fresh R session, then devtools::install_version("transformr", version = "0.1.3"), library(transformr) and check with packageVersion("transformr")!

@Robinlovelace
Copy link

Confirmed re. issue, going to try the fix..

@bart1
Copy link

bart1 commented Dec 19, 2023

the unreleased version of transformr indeed fixed this for me

@ptr-64
Copy link

ptr-64 commented Jan 22, 2024

the unreleased version of transformr indeed fixed this for me

I tried the fix but it seems to have stopped working in the last few weeks. Here's the package version:
packageVersion("transformr") [1] ‘0.1.3’

The code I am using (expected output is an animated map of the USA with colors corresponding to each states' minimum wage at the start of the year):

usa <- tigris::states(class = "sf") %>% shift_geometry() %>% mutate(name = tolower(NAME))
bzipmw <- read_excel("data/mw_state_excel/mw_state_monthly.xlsx") %>%
    transmute(
        date_by_month = as.Date(lubridate::fast_strptime(gsub("m", "", `Monthly Date`), "%Y%m")),
        year = year(lubridate::fast_strptime(gsub("m", "", `Monthly Date`), "%Y%m")),
        state = `State Abbreviation`, 
        mw = pmax(`Monthly Federal Minimum`, `Monthly State Minimum`), 
        name = tolower(`Name`)
    ) %>%
        distinct()
usa %>%
    mutate(name = tolower(NAME)) %>%
    right_join(
        bzipmw %>% select(!date_by_month) %>% distinct(),
        by = "name"
    ) %>%
    filter(year %in% seq(2005, 2008) ) %>% 
    ggplot(data = ., aes(fill = mw)) +
    geom_sf() +
    transition_states(states = year) 

which produces the familiar error: Error: arguments have different crs

Removing the transition_states(states = year) renders the map perfectly.

Here's the sessionInfo()

R version 4.3.2 (2023-10-31)
Platform: aarch64-apple-darwin22.6.0 (64-bit)
Running under: macOS Sonoma 14.2.1

Matrix products: default
BLAS:   /opt/homebrew/Cellar/openblas/0.3.25/lib/libopenblasp-r0.3.25.dylib 
LAPACK: /opt/homebrew/Cellar/r/4.3.2/lib/R/lib/libRlapack.dylib;  LAPACK version 3.11.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/New_York
tzcode source: internal

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

other attached packages:
 [1] gifski_1.12.0-2   transformr_0.1.3  gganimate_1.0.8   tigris_2.0.3     
 [5] janitor_2.2.0     fs_1.6.3          readxl_1.4.3      latex2exp_0.9.6  
 [9] xtable_1.8-4      rvest_1.0.3       strucchange_1.5-3 sandwich_3.0-2   
[13] knitr_1.43        broom_1.0.5       viridis_0.6.4     viridisLite_0.4.2
[17] lmtest_0.9-40     zoo_1.8-12        maps_3.4.1        wbstats_1.0.4    
[21] lubridate_1.9.2   forcats_1.0.0     stringr_1.5.0     dplyr_1.1.3      
[25] purrr_1.0.2       readr_2.1.4       tidyr_1.3.0       tibble_3.2.1     
[29] ggplot2_3.4.3     tidyverse_2.0.0   sf_1.0-15        

loaded via a namespace (and not attached):
 [1] tidyselect_1.2.0    farver_2.1.1        tweenr_2.0.2       
 [4] timechange_0.2.0    lifecycle_1.0.4     terra_1.7-65       
 [7] magrittr_2.0.3      compiler_4.3.2      progress_1.2.2     
[10] rlang_1.1.3         tools_4.3.2         utf8_1.2.3         
[13] prettyunits_1.1.1   labeling_0.4.3      bit_4.0.5          
[16] classInt_0.4-10     curl_5.2.0          xml2_1.3.5         
[19] KernSmooth_2.23-22  withr_2.5.0         grid_4.3.2         
[22] httpgd_1.3.1        fansi_1.0.4         e1071_1.7-14       
[25] colorspace_2.1-0    scales_1.2.1        cli_3.6.2          
[28] crayon_1.5.2        generics_0.1.3      httr_1.4.7         
[31] tzdb_0.4.0          DBI_1.2.1           proxy_0.4-27       
[34] rnaturalearth_1.0.1 parallel_4.3.2      cellranger_1.1.0   
[37] vctrs_0.6.5         jsonlite_1.8.7      hms_1.1.3          
[40] bit64_4.0.5         systemfonts_1.0.4   units_0.8-5        
[43] glue_1.7.0          codetools_0.2-19    stringi_1.7.12     
[46] gtable_0.3.4        later_1.3.1         munsell_0.5.0      
[49] pillar_1.9.0        rappdirs_0.3.3      R6_2.5.1           
[52] lpSolve_5.6.20      vroom_1.6.3         lattice_0.21-9     
[55] backports_1.4.1     snakecase_0.11.1    class_7.3-22       
[58] Rcpp_1.0.12         uuid_1.1-1          gridExtra_2.3      
[61] xfun_0.40           pkgconfig_2.0.3 

@mecohn
Copy link

mecohn commented Jan 22, 2024

@ptr-64 I also just had this happen again on code that worked as of a week ago. When this first happened, I installed the old version of transformr and it fixed it. Obviously that didn't work this time. Thankfully, I just updated R to 4.3.2 so I had a feeling that's what caused this issue. I installed the previous version, 4.2.3. After this, for some reason when calling library(gganimate) I got this message:
No renderer backend detected. gganimate will default to writing frames to separate files Consider installing: the gifski package for gif output / the av package for video output / and restarting the R session

I'm not sure how I was able to produce gifs without explicitly calling gifski before this, but I installed it anyway. Then, after running animate(), there was no animation in the viewer, the console printed an output similar to frame_vars(), and I got the error Warning message: file_renderer failed to copy frames to the destination directory

Finally, after adding renderer = gifski_renderer() to animate(), my gif worked.

TL;DR: Here's how I fixed the return of the arguments have different crs error that was initially fixed by installing the old version of transformr:

  1. install R 4.2.3
  2. run install.packages("gifski") and library(gifski)
  3. add renderer = gifski_renderer() to animate()

@ptr-64
Copy link

ptr-64 commented Jan 24, 2024

@mecohn Your solution worked, but I had to install the older R version in a docker container. Also, I think one of the packages got updated because the code chunk I posted above worked this morning without issue.
min_wage_usa0518

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests