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

Uninformative error message when specifying bbox as vector #810

Open
PPaccioretti opened this issue Nov 7, 2023 · 2 comments
Open

Uninformative error message when specifying bbox as vector #810

PPaccioretti opened this issue Nov 7, 2023 · 2 comments
Labels

Comments

@PPaccioretti
Copy link

I'm using the development version. When specifying a bbox as a vector or matrix without crs attribute, I encounter an error message that lacks informative details. This issue makes it challenging to diagnose and resolve the problem.

library(tmap)
#> The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
#> which was just loaded, were retired in October 2023.
#> Please refer to R-spatial evolution reports for details, especially
#> https://r-spatial.org/r/2023/05/15/evolution4.html.
#> It may be desirable to make the sf package available;
#> package maintainers should consider adding sf to Suggests:.
#> 
#> Attaching package: 'tmap'
#> The following object is masked from 'package:datasets':
#> 
#>     rivers

packageVersion('tmap')
#> [1] '3.99.9000'
data(World)
tm_shape(World, bbox = as.vector(sf::st_bbox(World))) + 
  tm_polygons()
#> Error in if (!maybe_longlat(b)) {: missing value where TRUE/FALSE needed

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

Thank you for your dedication!!

@Nowosad Nowosad added the bug label Nov 8, 2023
@olivroy
Copy link
Contributor

olivroy commented Jan 12, 2024

This example runs without error in 3.3.4, is this wrong?

What would be the correct code ?

@mtennekes
Copy link
Member

To start with @olivroy's question: these ones are 'correct':

tm_shape(World, bbox = World) + tm_polygons()
tm_shape(World, bbox = sf::st_bbox(World)) + tm_polygons()

Under the hood, the specified bbox argument is feed to sf::st_bbox, which accepts many formats. However, I cannot cope unnamed numeric vectors well (imho) :

sf::st_bbox(c(-180, -89, 180, 83))
#> xmin ymin xmax ymax 
#>   NA   NA   NA   NA
sf::st_bbox(c(xmin = -180, ymin = -89, xmax = 180, ymax = 83))
#> xmin ymin xmax ymax 
#> -180  -89  180   83

@edzer Why is this? I would expect a warning here, e.g.: "Names have not been specified:, xmin, ymin, xmax and ymax assumed."

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

4 participants