mregions icon indicating copy to clipboard operation
mregions copied to clipboard

Search API fails when using spaces in R > 4.0 and Windows 10

Open salvafern opened this issue 3 years ago • 9 comments

@brittlnv noticed that mr_geo_code() does not work when performing a search with spaces.

I digged in a bit and this seems to be a feature - not a bug - of httr. If you use plus symbols + instead of spaces, the requests work fine as explained in https://github.com/r-lib/httr/issues/335

library(mregions)
#> Warning: package 'mregions' was built under R version 4.0.5

cs <- mr_geo_code("Continental+Shelf")
head(cs)
#>   MRGID gazetteerSource                               placeType  latitude
#> 1 63050            <NA> Continental Shelf (CLCS Recommendation) -43.05362
#> 2 63044            <NA> Continental Shelf (CLCS Recommendation) -13.78329
#> 3 63045            <NA> Continental Shelf (CLCS Recommendation) -36.28064
#> 4 63047            <NA> Continental Shelf (CLCS Recommendation) -58.09272
#> 5 63043            <NA> Continental Shelf (CLCS Recommendation) -33.77674
#> 6 63046            <NA> Continental Shelf (CLCS Recommendation) -48.38320
#>   longitude minLatitude minLongitude maxLatitude maxLongitude precision
#> 1 -56.14215   -47.66977    -60.89235   -37.85991    -50.59635        NA
#> 2 118.06045   -14.68730    117.06350   -13.09524    118.41225        NA
#> 3 129.26419   -37.75001    125.92733   -34.99314    132.74821        NA
#> 4  76.88420   -63.65003     61.80664   -49.50886     89.16208        NA
#> 5 109.76407   -36.84570    107.83853   -30.75226    112.36359        NA
#> 6 149.11460   -50.88755    142.73669   -42.21693    153.71630        NA
#>                                         preferredGazetteerName
#> 1                                Argentinean Continental Shelf
#> 2                   Australian Continental Shelf (Argo region)
#> 3 Australian Continental Shelf (Great Australian Bight region)
#> 4      Australian Continental Shelf (Kerguelen Plateau region)
#> 5    Australian Continental Shelf (Naturaliste Plateau region)
#> 6      Australian Continental Shelf (South Tasman Rise region)
#>   preferredGazetteerNameLang   status accepted
#> 1                    English standard    63050
#> 2                    English standard    63044
#> 3                    English standard    63045
#> 4                    English standard    63047
#> 5                    English standard    63043
#> 6                    English standard    63046

url <- httr::GET("http://marineregions.org/rest/getGazetteerRecordsByName.json/Continental+Shelf/true/false")
httr::status_code(url)
#> [1] 200

cs <- mr_geo_code("Continental Shelf")
#> Error in mr_geo_code("Continental Shelf"): Bad Request (HTTP 400).

url <- httr::GET("http://marineregions.org/rest/getGazetteerRecordsByName.json/Continental Shelf/true/false")
httr::status_code(url)
#> [1] 400

Created on 2022-03-03 by the reprex package (v2.0.0)

We shall consider to make it easier for our users by adding an exception.

salvafern avatar Mar 03 '22 16:03 salvafern