% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/download.R
\name{oe_download}
\alias{oe_download}
\title{Download a file given a url}
\usage{
oe_download(
  file_url,
  provider = NULL,
  file_basename = basename(file_url),
  download_directory = oe_download_directory(),
  file_size = NA,
  force_download = FALSE,
  max_file_size = 5e+08,
  quiet = FALSE
)
}
\arguments{
\item{file_url}{A URL pointing to a (typically \code{.osm.pbf}) file.}

\item{provider}{Which provider stores the file? If \code{NULL} (the default), the
function tries to infer it. It must be specified for non-standard cases.
See details and examples.}

\item{file_basename}{The basename of the file. The default behaviour is to
auto-generate it from the URL using \code{basename()}.}

\item{download_directory}{Directory to store the file containing OSM data?.}

\item{file_size}{How big is the file? Optional. \code{NA} by default. If it's
bigger than \code{max_file_size} and the function is run in interactive mode,
then an interactive menu is displayed, asking for permission for
downloading the file.}

\item{force_download}{Should the \code{.osm.pbf} file be updated even if it has
already been downloaded? \code{FALSE} by default. This parameter is used to
update old \code{.osm.pbf} files.}

\item{max_file_size}{The maximum file size to download without asking in
interactive mode. Default: \code{5e+8}, half a gigabyte.}

\item{quiet}{Boolean. If \code{FALSE}, the function prints informative messages.
Starting from \code{sf} version
\href{https://r-spatial.github.io/sf/news/index.html#version-0-9-6-2020-09-13}{0.9.6},
if \code{quiet} is equal to \code{FALSE}, then vectortranslate operations will
display a progress bar.}
}
\value{
A character string representing the file's path.
}
\description{
This function is used to download a file given a URL. It focuses on OSM
extracts with \code{.osm.pbf} format stored by one of the providers implemented in
the package. The URL is specified through the parameter \code{file_url}.
}
\details{
This function runs several checks before actually downloading a new
file to avoid overloading the OSM providers. The first step is the
definition of the file path associated to the input \code{file_url}. The path is
created by pasting together the \code{download_directory}, the name of chosen
provider (which may be inferred from the URL), and the \code{basename} of the
URL. For example, if \code{file_url} is equal to
\code{"https://download.geofabrik.de/europe/italy-latest.osm.pbf"}, and
\code{download_directory = "/tmp"}, then the path is built as
\code{"/tmp/geofabrik_italy-latest.osm.pbf"}. If this file already exists, the
function just returns its path. The parameter \code{force_download} can be used
to modify this behaviour. If there is no file associated with the new path,
the function downloads it using \code{\link[httr:GET]{httr::GET()}}. The timeout for the download
can be modified using \code{options("timeout")}. The default value is 300s.
}
\examples{
(its_match = oe_match("ITS Leeds", quiet = TRUE))

\dontrun{
oe_download(
  file_url = its_match$url,
  file_size = its_match$file_size,
  provider = "test",
  download_directory = tempdir()
)
iow_url = oe_match("Isle of Wight")
oe_download(
  file_url = iow_url$url,
  file_size = iow_url$file_size,
  download_directory = tempdir()
)
Sucre_url = oe_match("Sucre", provider = "bbbike")
oe_download(
  file_url = Sucre_url$url,
  file_size = Sucre_url$file_size,
  download_directory = tempdir()
)}
}
