19 lines
801 B
R
19 lines
801 B
R
getStations <- function(headers = headers,dpobs = "public/DPObs/v1/") {
|
|
# Ensure dpobs is defined externally or provide a default/argument for it
|
|
url <- modify_url(base, path = paste0(dpobs, "liste-stations"))
|
|
response <- GET(url, add_headers(.headers = headers))
|
|
# Better error handling
|
|
if (http_status(response)$category == "success") {
|
|
# Directly parse the content as a CSV
|
|
data <- content(response, as = "text")
|
|
# Return the data frame
|
|
return(read.csv(text = data, sep = ";", header = TRUE))
|
|
} else {
|
|
# Optionally: return an informative error message or an empty data frame
|
|
# stop("Failed to retrieve data from the API"), or
|
|
print("Failed to retrieve data from the API")
|
|
return(data.frame()) # Returns an empty data frame as a graceful fallback
|
|
}
|
|
}
|
|
|
|
|