Skip to content
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: owidapi
Title: Access the Our World in Data Chart API
Version: 0.1.0.9001
Version: 0.1.0.9002
Authors@R: c(
person("Christoph", "Scheuch", , "christoph@tidy-intelligence.com",
role = c("aut", "cre", "cph"),
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# owidapi (development version)

- Encapsulated request logic in internal `perform_request()` function.
- Updated variable parsing & introduced graceful error handling in `owid_get_catalog()`

# owidapi 0.1.0

Expand Down
46 changes: 34 additions & 12 deletions R/owid_get_catalog.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,41 @@ owid_get_catalog <- function(

req <- request(base_url)

resp <- perform_request(req, "owid_get_catalog")
tryCatch(
{
resp <- perform_request(req, "owid_get_catalog")

catalog_raw <- resp |>
resp_body_string() |>
textConnection() |>
read.csv() |>
tibble::as_tibble()
catalog_raw <- resp |>
resp_body_string() |>
textConnection() |>
read.csv() |>
tibble::as_tibble()

if (snake_case) {
catalog <- to_snake_case(catalog_raw)
} else {
catalog <- catalog_raw
}
# Parse logicals
catalog_raw$isInheritanceEnabled <- catalog_raw$isInheritanceEnabled ==
"True"
catalog_raw$isIndexable <- catalog_raw$isIndexable == "True"
catalog_raw$isPublished <- catalog_raw$isPublished == "True"

catalog
# Parse dates
catalog_raw$createdAt <- as.Date(catalog_raw$createdAt)
catalog_raw$updatedAt <- as.Date(catalog_raw$updatedAt)
catalog_raw$lastEditedAt <- as.Date(catalog_raw$lastEditedAt)
catalog_raw$publishedAt <- as.Date(catalog_raw$publishedAt)

if (snake_case) {
catalog <- to_snake_case(catalog_raw)
} else {
catalog <- catalog_raw
}

catalog
},
error = function(e) {
cli_alert(
conditionMessage(e)
)
invisible(NULL)
}
)
}
2 changes: 1 addition & 1 deletion tests/testthat/test-owid_get_catalog.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test_that("owid_get_catalog handles request errors gracefully", {
cli_abort("Mocked network error")
},
{
expect_error(
expect_message(
owid_get_catalog(),
regexp = "Failed to retrieve data from Our World in Data\\."
)
Expand Down