Skip to contents

Low-level helper for arbitrary CKAN resources. Resolves the package by id (slug) and picks the first resource matching pattern, or the first resource if pattern is NULL.

Usage

ato_download(
  id,
  pattern = NULL,
  parse = c("auto", "csv", "xlsx", "none"),
  sheet = 1
)

Arguments

id

CKAN package id (e.g. "taxation-statistics-2022-23" or "corporate-transparency").

pattern

Optional regex applied to the resource filename and name.

parse

One of "auto" (default), "csv", "xlsx", or "none" (returns the cached file path).

sheet

For XLSX resources: sheet index or name.

Value

Either a file path (parse = "none") or an ato_tbl.

Examples

# \donttest{
op <- options(ato.cache_dir = tempdir())
try({
  cat <- ato_download("corporate-transparency",
                      pattern = "2023",
                      parse = "csv")
})
#>  Downloading <https://data.gov.au/data/dataset/c2524c87-cea4-4636-acac-599a820
#>  Downloading <https://data.gov.au/data/dataset/c2524c87-cea4-4636-acac-599a820
#> 
#> Warning: line 1 appears to contain embedded nulls
#> Warning: line 2 appears to contain embedded nulls
#> Warning: line 3 appears to contain embedded nulls
#> Warning: line 4 appears to contain embedded nulls
#> Warning: line 5 appears to contain embedded nulls
#> Error in read.table(file = file, header = header, sep = sep, quote = quote,  : 
#>   more columns than column names
options(op)
# }