R/fetch_dataset.R

Defines functions fetch_dataset

fetch_dataset <- function(key, revision = NA) {
  if (is.na(revision)) {
    dataset_url <- sprintf(
      "https://docs.google.com/spreadsheets/d/%s/export?id=%s&format=csv",
      key, key)
  } else {
    dataset_url <- sprintf(
      "https://docs.google.com/spreadsheets/d/%s/export?id=%s&format=csv&revision=%s",
      key, key, revision)
  }
  
  tryCatch({
    suppressMessages({
      dataset_url %>%
        httr::GET() %>%
        httr::content(col_names = TRUE, col_types = NULL, encoding = "UTF-8")
    })
  },
  error = function(e) {
    cat(sprintf("Can't load dataset with key '%s' and revision '%s'. Exception: %s.\n",
                key, revision, e))
  })
}
erikriverson/metalab-package documentation built on Oct. 9, 2020, 10:48 a.m.