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

Re-define provider argument in calling function #246

Merged
merged 6 commits into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions R/match.R
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,14 @@ oe_match.character = function(
quiet = quiet
)

# If oe_match finds an exact match in one of the "other" providers and
# oe_match is called from another function (i.e. the parent.frame is not
# the global env), then we should also redefine the provider argument in
# the calling env. See https://github.com/ropensci/osmextract/issues/245
if (!identical(parent.frame(), .GlobalEnv)) {
assign("provider", other_provider, envir = parent.frame())
}

return(
oe_match(
place = place,
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-get.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,16 @@ test_that("We can specify path using ~", {
)
unlink("~/test_for_tilde_in_R_osmextract", recursive = TRUE)
})

test_that("The provider is overwritten when oe_match find a different provider", {
# See https://github.com/ropensci/osmextract/issues/245
skip_on_cran()
skip_if_offline("github.com")

expect_match(
oe_get("Canarias", download_only = TRUE, skip_vectortranslate = TRUE, quiet = TRUE, download_directory = tempdir()),
regexp = "openstreetmap_fr"
)
file.remove(list.files(tempdir(), pattern = "pbf", full.names = TRUE))
})

5 changes: 5 additions & 0 deletions tests/testthat/test-match.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,8 @@ test_that("oe_match returns a warning message with missing CRS in input place",
"The input place has no CRS, setting crs = 4326."
)
})

test_that("oe_match does not create a variable in global env after https://github.com/ropensci/osmextract/pull/246", {
oe_match("Leeds")
expect_false(exists("provider", where = .GlobalEnv))
})