Skip to content

[help] Using format = "url" with alternative modified metadata? #1334

Closed Answered by andrewheiss
andrewheiss asked this question in Help
Discussion options

You must be logged in to vote

WAIT I FIGURED IT OUT! This works and seems to be the most {targets}-esque approach:

library(targets)
library(tarchetypes)

get_latest_timestamp <- function(url) {
  response <- httr2::request(url) |>
    httr2::req_perform() |>
    httr2::resp_body_json()

  response |>
    purrr::pluck("last-modified")
}

download_data <- function(url) {
  httr2::request(url) |>
    httr2::req_perform() |>
    httr2::resp_body_json()
}

url <- "https://election-testing.andhs.co/county?county=example"

list(
  tar_change(
    dataset,
    download_data(url),
    change = get_latest_timestamp(url)
  )
)

That change function just returns the timestamp from the API, and it stores it as text in the {targets}…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@andrewheiss
Comment options

Answer selected by wlandau
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
1 participant