Skip to content

Confusing test failure for sf_transform_xy() "no arguments in initialization list" #5201

Closed as not planned
@MichaelChirico

Description

@MichaelChirico

We are observing this test failure:

── Error ('test-coord_sf.R:290'): sf_transform_xy() works ──────────────────────
Error in `proj_from_crs(from)`: no arguments in initialization list: GEOGCRS["WGS 84",
    DATUM["World Geodetic System 1984",
        ELLIPSOID["WGS 84",6378137,298.257223563,
            LENGTHUNIT["metre",1]]],
    PRIMEM["Greenwich",0,
        ANGLEUNIT["degree",0.0174532925199433]],
    CS[ellipsoidal,2],
        AXIS["geodetic latitude (Lat)",north,
            ORDER[1],
            ANGLEUNIT["degree",0.0174532925199433]],
        AXIS["geodetic longitude (Lon)",east,
            ORDER[2],
            ANGLEUNIT["degree",0.0174532925199433]],
    USAGE[
        SCOPE["unknown"],
        AREA["World"],
        BBOX[-90,-180,90,180]],
    ID["EPSG",4326]]
Backtrace:
    ▆
 1. └─ggplot2::sf_transform_xy(data, 3347, 4326) at test-coord_sf.R:290:2
 2.   └─sf::sf_project(...)
 3.     └─sf (local) proj_from_crs(from)

Probably this is related to missing certain GDAL drivers. But I hope you agree the error message is not very helpful. I'm not sure if this is something on the ggplot2 or the sf side; I know sf offers some things we could use to escape here e.g. sf_extSoftVersion() or is_driver_available():

https://github.com/r-spatial/sf/blob/b798413d4cd681cd173f9bdc110f2a014555ee09/tests/testthat/test_read.R#L176

https://github.com/r-spatial/sf/blob/b798413d4cd681cd173f9bdc110f2a014555ee09/tests/testthat/test_read.R#L121

Happy to offer more details as needed but I'm not sure what would help.


FWIW, the issue also causes some examples to fail:

ggplot2/man/geom_map.Rd

Lines 125 to 162 in 519bc83

if (require(maps)) {
crimes <- data.frame(state = tolower(rownames(USArrests)), USArrests)
# Equivalent to crimes \%>\% tidyr::pivot_longer(Murder:Rape)
vars <- lapply(names(crimes)[-1], function(j) {
data.frame(state = crimes$state, variable = j, value = crimes[[j]])
})
crimes_long <- do.call("rbind", vars)
states_map <- map_data("state")
# without geospatial coordinate system, the resulting plot
# looks weird
ggplot(crimes, aes(map_id = state)) +
geom_map(aes(fill = Murder), map = states_map) +
expand_limits(x = states_map$long, y = states_map$lat)
# in combination with `coord_sf()` we get an appropriate result
ggplot(crimes, aes(map_id = state)) +
geom_map(aes(fill = Murder), map = states_map) +
# crs = 5070 is a Conus Albers projection for North America,
# see: https://epsg.io/5070
# default_crs = 4326 tells coord_sf() that the input map data
# are in longitude-latitude format
coord_sf(
crs = 5070, default_crs = 4326,
xlim = c(-125, -70), ylim = c(25, 52)
)
ggplot(crimes_long, aes(map_id = state)) +
geom_map(aes(fill = value), map = states_map) +
coord_sf(
crs = 5070, default_crs = 4326,
xlim = c(-125, -70), ylim = c(25, 52)
) +
facet_wrap(~variable)
}

\examples{
if (requireNamespace("sf", quietly = TRUE)) {
# location of cities in NC by long (x) and lat (y)
data <- data.frame(
city = c("Charlotte", "Raleigh", "Greensboro"),
x = c(-80.843, -78.639, -79.792),
y = c(35.227, 35.772, 36.073)
)
# transform to projected coordinates
data_proj <- sf_transform_xy(data, 3347, 4326)
data_proj
# transform back
sf_transform_xy(data_proj, 4326, 3347)
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    internals 🔎messagesrequests for improvements to error, warning, or feedback messages

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions