MikkoVihtakari / ggOceanMaps

Plot oceanographic research data on maps using ggplot2
GNU General Public License v3.0
46 stars 7 forks source link

Error in cls[2, ]: incorrect number of dimensions - for some values of 'limits' in basemap #37

Open willboulton opened 1 year ago

willboulton commented 1 year ago

Hi - thank you very much for creating this great package. I'm using the latest github version (due to some issue with CRAN not installing with install.packages, I've used remotes::install_github) and came across the following issue that seems not to work on the latest github@HEAD version but had worked for me previously - code is:

min_lat = 87
max_lat = 88

min_long = 90
max_long = 110

basemap(limits = c(min_long, max_long, min_lat, max_lat), 
    bathymetry = FALSE, 
    legends = FALSE
)

Would you be able to help with this issue?

The error I get is:

Error in cls[2, ]: incorrect number of dimensions Traceback:

  1. basemap(limits = c(min_long, max_long, min_lat, max_lat), bathymetry = FALSE, . legends = FALSE, bathy.alpha = 0.25)
  2. basemap_data(limits = limits, data = data, shapefiles = shapefiles, . crs = crs, bathymetry = bathymetry, bathy.type = bathy.type, . downsample = downsample, glaciers = glaciers, lon.interval = lon.interval, . lat.interval = lat.interval, rotate = rotate, expand.factor = expand.factor, . verbose = verbose)
  3. sf::st_cast(x$shapefiles$land, "MULTIPOLYGON")
  4. st_cast.sf(x$shapefiles$land, "MULTIPOLYGON")
  5. st_cast(st_geometry(x), to, group_or_split = do_split)
  6. st_cast.sfc(st_geometry(x), to, group_or_split = do_split)
  7. is_exotic(x)
  8. cls[2, ] %in% c("MULTICURVE", "COMPOUNDCURVE", "CURVEPOLYGON", . "MULTISURFACE")

My R version is 4.3.2 Apologies if this isn't enough information for you to go on - I don't generally use R much so am not sure if this stack trace has enough detail for an R person to follow.

MikkoVihtakari commented 1 year ago

It seems like you are using a dplyr pipe %>% instead of the ggplot2 + operator in your code throwing the error. Could that be the issue?

willboulton commented 1 year ago

Thanks for your quick reply! Apologies - as the stack trace I posted above didn't quite match the code above - I've edited my original comment so that running the above code should produce the error with the exact stack trace listed (they are almost the same). But unfortunately I don't think it's the dplyr pipe that was the problem, as I was more or less using this as a shortcut for a little bit of other plotting code (plotting a ggspatial line).

MikkoVihtakari commented 1 year ago

Could you run the code below using reprex::reprex() and post the output?

library(ggOceanMaps)
#> Loading required package: ggplot2
#> ggOceanMaps: Setting data download folder to a temporary folder
#> /var/folders/9v/b70pd53x04d3jjmlrbcgp4_w0000gv/T//RtmpfPjs5g. This
#> means that any downloaded map data need to be downloaded again when you
#> restart R. To avoid this problem, change the default path to a
#> permanent folder on your computer. Add following lines to your
#> .Rprofile file: {.ggOceanMapsenv <- new.env(); .ggOceanMapsenv$datapath
#> <- 'YourCustomPath'}. You can use usethis::edit_r_profile() to edit the
#> file. '~/ggOceanMapsLargeData' would make it in a writable folder on
#> most operating systems.
sessionInfo()
#> R version 4.3.1 (2023-06-16)
#> Platform: x86_64-apple-darwin20 (64-bit)
#> Running under: macOS Ventura 13.6.1
#> 
#> Matrix products: default
#> BLAS:   /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRblas.0.dylib 
#> LAPACK: /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/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: Europe/Oslo
#> tzcode source: internal
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] ggOceanMaps_2.1.12 ggplot2_3.4.3     
#> 
#> loaded via a namespace (and not attached):
#>  [1] gtable_0.3.4       dplyr_1.1.3        compiler_4.3.1     reprex_2.0.2      
#>  [5] tidyselect_1.2.0   Rcpp_1.0.11        parallel_4.3.1     scales_1.2.1      
#>  [9] yaml_2.3.7         fastmap_1.1.1      R6_2.5.1           generics_0.1.3    
#> [13] classInt_0.4-9     sf_1.0-14          knitr_1.43         tibble_3.2.1      
#> [17] stars_0.6-4        units_0.8-3        munsell_0.5.0      DBI_1.1.3         
#> [21] pillar_1.9.0       rlang_1.1.1        utf8_1.2.3         xfun_0.40         
#> [25] fs_1.6.3           cli_3.6.1          withr_2.5.0        magrittr_2.0.3    
#> [29] class_7.3-22       digest_0.6.33      grid_4.3.1         rstudioapi_0.15.0 
#> [33] lifecycle_1.0.3    vctrs_0.6.3        KernSmooth_2.23-22 proxy_0.4-27      
#> [37] evaluate_0.21      glue_1.6.2         abind_1.4-5        fansi_1.0.4       
#> [41] e1071_1.7-13       colorspace_2.1-0   rmarkdown_2.24     tools_4.3.1       
#> [45] pkgconfig_2.0.3    htmltools_0.5.6

min_lat = 87
max_lat = 88

min_long = 90
max_long = 110

basemap(limits = c(min_long, max_long, min_lat, max_lat), 
        bathymetry = FALSE, 
        legends = FALSE
)

Created on 2023-11-22 with reprex v2.0.2

willboulton commented 1 year ago

Thanks! Here you go:

library(ggOceanMaps)
#> Loading required package: ggplot2
#> ggOceanMaps: Using /Users/will/.Rdata as data download folder. This
#> folder is customly defined and does not require downloading the
#> detailed map data again.
sessionInfo()
#> R version 4.3.2 (2023-10-31)
#> Platform: aarch64-apple-darwin22.6.0 (64-bit)
#> Running under: macOS Ventura 13.5
#> 
#> Matrix products: default
#> BLAS:   /opt/homebrew/Cellar/openblas/0.3.24/lib/libopenblasp-r0.3.24.dylib
#> LAPACK: /opt/homebrew/Cellar/r/4.3.2/lib/R/lib/libRlapack.dylib;  LAPACK version 3.11.0
#> 
#> locale:
#> [1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
#> 
#> time zone: Europe/London
#> tzcode source: internal
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base
#> 
#> other attached packages:
#> [1] ggOceanMaps_2.1.11 ggplot2_3.4.3
#> 
#> loaded via a namespace (and not attached):
#>  [1] vctrs_0.6.3        cli_3.6.1          rlang_1.1.1        KernSmooth_2.23-22
#>  [5] DBI_1.1.3          generics_0.1.3     sf_1.0-15          glue_1.6.2
#>  [9] colorspace_2.1-0   e1071_1.7-13       scales_1.2.1       fansi_1.0.4
#> [13] grid_4.3.2         abind_1.4-5        munsell_0.5.0      classInt_0.4-10
#> [17] tibble_3.2.1       lifecycle_1.0.3    compiler_4.3.2     dplyr_1.1.3
#> [21] Rcpp_1.0.11        pkgconfig_2.0.3    R6_2.5.1           class_7.3-22
#> [25] tidyselect_1.2.0   utf8_1.2.3         parallel_4.3.2     pillar_1.9.0
#> [29] magrittr_2.0.3     tools_4.3.2        withr_2.5.0        proxy_0.4-27
#> [33] gtable_0.3.4       stars_0.6-4        units_0.8-4

min_lat = 87
max_lat = 88

min_long = 90
max_long = 110

basemap(limits = c(min_long, max_long, min_lat, max_lat),
        bathymetry = FALSE,
        legends = FALSE
)
#> Error in cls[2, ] : incorrect number of dimensions
traceback()
#> 8: cls[2, ] %in% c("MULTICURVE", "COMPOUNDCURVE", "CURVEPOLYGON",
#>       "MULTISURFACE")
#> 7: is_exotic(x)
#> 6: st_cast.sfc(st_geometry(x), to, group_or_split = do_split)
#> 5: st_cast(st_geometry(x), to, group_or_split = do_split)
#> 4: st_cast.sf(x$shapefiles$land, "MULTIPOLYGON")
#> 3: sf::st_cast(x$shapefiles$land, "MULTIPOLYGON")
#> 2: basemap_data(limits = limits, data = data, shapefiles = shapefiles,
#>       crs = crs, bathymetry = bathymetry, bathy.type = bathy.type,
#>       downsample = downsample, glaciers = glaciers, lon.interval = lon.interval,
#>       lat.interval = lat.interval, rotate = rotate, expand.factor = expand.factor,
#>       verbose = verbose)
#> 1: basemap(limits = c(min_long, max_long, min_lat, max_lat), bathymetry = FALSE,
#>        legends = FALSE)
MikkoVihtakari commented 12 months ago

I don't see potential issues there, except that you could update ggOceanMaps from GitHub in case there was a bug in 2.1.11 version causing this (I doubt it). What does sf::sf_extSoftVersion() return?

sf::sf_extSoftVersion()
#>           GEOS           GDAL         proj.4 GDAL_with_GEOS     USE_PROJ_H 
#>       "3.11.0"        "3.5.3"        "9.1.0"         "true"         "true" 
#>           PROJ 
#>        "9.1.0"

Also, try:

packageVersion("s2")
#> [1] '1.1.4'

Created on 2023-11-27 with reprex v2.0.2

MikkoVihtakari commented 12 months ago

@willboulton, did you manage to solve this issue?

willboulton commented 12 months ago

Thanks and sorry for the late reply! - I haven't, the output of sf_extSoftVersion and packageVersion was:

sf::sf_extSoftVersion()
#> GEOS
    '3.12.0'
GDAL
    '3.7.3'
proj.4
    '9.3.0'
GDAL_with_GEOS
    'true'
USE_PROJ_H
    'true'
PROJ
    '9.3.0'

packageVersion("s2")
#> '1.1.4'

Perhaps if the error is to do with package versions, I can try uninstalling and reinstalling some of these software - the error first appeared for me after brew updating R, so there might be some incompatibility problem with some of the latest software versions.

MikkoVihtakari commented 12 months ago

Possible. It's also possible that it shows up when I update my R and all packages. Sometimes the dependencies change. Your versions seem more updated than mine. Until we have figured out what is going on, let's leave this open.