[help] Using format = "url"
with alternative modified metadata?
#1334
-
Help
DescriptionIn a pipeline I'm building, I'm accessing JSON data from a URL that doesn't include {
"name": "thing",
"last-modified": "2024-09-11 21:44:53",
"value": 12345
} (I just whipped up this little example server that spits out JSON data formatted in this way, with a For a regular URL, I'd do something like this:
This doesn't work in this case, though, because of the missing metadata:
That all makes sense. It's not a normal website with normal HTTP headers or anything. I'm curious what a recommended "different workaround" in this case might look like. The closest I've come is a process like this:
But that process feels wrong and un-targets-like (especially with the brute force of |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Ahhh there's a similar question/use case from back in 2020 here: #131 (comment) - that led to the creation of tar_change(remote_data, download_data(), change = remote_hash(dep1, dep2)) So in this case, I'd do something like download_data <- function(url) {
httr2::request(url) |>
httr2::req_perform() |>
httr2::resp_body_json()
}
tar_change(
dataset,
download_data("https://election-testing.andhs.co/county?county=example"),
change = SOMETHING_HERE
) I'm not sure how to structure the |
Beta Was this translation helpful? Give feedback.
WAIT I FIGURED IT OUT! This works and seems to be the most {targets}-esque approach:
That
change
function just returns the timestamp from the API, and it stores it as text in the {targets}…