% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/download_resources.R
\name{download_resources}
\alias{download_resources}
\alias{unnest_and_filter}
\alias{preview_resources}
\title{Download resources from umwelt.info}
\usage{
unnest_and_filter(
  data,
  formats = c("Csv", "Zip", "Json", "JsonLd", "GeoJson", "Tsv", "Pdf",
    "MicrosoftExcelSpreadsheet"),
  description_regex = NULL
)

preview_resources(data_preprocessed)

download_resources(data_preprocessed, base_dir = tempdir())
}
\arguments{
\item{data}{An unnested and optionally filtered R dataframe which is written as output by one of the functions fetch_by_url, fetch_by_query or fetch_by_id}

\item{formats}{A list of strings indicating accepted output formats of the recoures
Possible values: see ResourceType in the list of Schemas at the bottom of the API documentation at    https://md.umwelt.info/swagger-ui/ to get a list of existing formats}

\item{description_regex}{A string to filter only resources with a description containing the string}

\item{data_preprocessed}{An unnested and optionally filtered R dataframe which is written as output by unnest_and_filter}

\item{base_dir}{A directory where downloaded resources should be stored.}
}
\value{
No return value (resources are downloaded into the respective folder)
}
\description{
Download all the resources attached to the datasets of a respective query:
}
\examples{
# To download the resources the workflow contains four steps. First you fetch the list of all
# datasets belonging to your query.
# The input link for the query can be generated in the interface of https://umwelt.info.
# See the tutorial
# https://umwelt.info/artikel/so-laden-sie-daten-bei-umweltinfo-mit-python-und-r-herunter
# for further details.
# In a second step the required columns are unnested and you can optionally filter for certain
# file formats (in the example here "MicrosoftExcelSpreadsheet" and "Csv") and create a subset of
# only those entries where the resource description contains the query (in this example "Ozon").
# Note that the unnesting is a prerequisite for preview_resources() and download_resources().
# Third, you create a preview of the resulting resources which would be downloaded.
# If you want to proceed, you can initiate the download in the fourth and final step.
if (interactive()) {
  url <-
  "https://md.umwelt.info/search/all?query=(Ozon)+AND+organisation\%3A\%2FLand\%2FBayern\%2Fopen.bydata"
  results <- fetch_by_url(url,
    columns = "resource_only"
  ) |>
    unnest_and_filter(formats =  c("MicrosoftExcelSpreadsheet", "Csv"),
    description_regex = "Ozon") |>
    preview_resources()
  results |> download_resources(base_dir = tempdir())
}
}
