download_images: Download images to a local folder

View source: R/download_images.R

download_imagesR Documentation

Download images to a local folder

Description

download_images takes a data frame or a vector of URLs and downloads the files to a local folder, possibly with the use of an additional ID vector to rename the files and check for duplicates.

Usage

download_images(
  x = NULL,
  destination,
  path = photos,
  id = id,
  check_duplicates = TRUE,
  quiet = FALSE
)

Arguments

x

A data frame with a column containing URLs to be downloaded and IDs to be linked to the downloads for file naming and duplicate detection. If x is supplied, the path and id arguments will be interpreted as field names. If x is NULL, they will be interpreted as lists or character vectors.

destination

A character scalar indicating a local folder where images should be downloaded to.

path

If x is supplied, the name of a list or character field in x with URLs to be downloaded. If x is NULL, a list or character vector of URLs. In either case, elements should begin with "http", "https", "ftp" or "ftps". If the URL has no extension, it will be given the extension ".jpg".

id

If x is supplied, the name of a character field (or field which can be coerced to a character field) in x with IDs to match to the file downloads. If x is NULL, a character vector (or vector which can be coerced to a character vector) the same length as path, indicating the IDs of the files to be downloaded. Downloaded files will be named according to the IDs, as id_n.jpg, where id is an element of the id argument, n is an integer sequence of the same length as the id element, and .jpg is the same file extension as the URL. (So if there are three URLs which correspond to the id value of "XXXX", the files downloaded will be "XXXX-1.jpg", "XXXX-2.jpg" and "XXXX-3.jpg".) If id has repeating values, the corresponding path entries will be consolidated and duplicates will be removed.

check_duplicates

A logical scalar (default TRUE) indicating whether to skip downloads for files whose IDs match files already present in the download folder. This check is done per ID rather than per file, which means that if any files with an ID of x are found in the download folder, no new files with an ID of x will be downloaded. If this is set to FALSE, existing files may be overwritten with no warning.

quiet

A logical scalar. Should the function execute quietly, or should it return status updates throughout the function (default)?

Value

Invisibly, a data frame summarizing the results of the downloads.

Examples

## Not run: 
# Setup
df <- data.frame(id = 1:15, photos = example_urls)
dest <- tempdir()
download_images(df, dest)

## End(Not run)

UPGo-McGill/matchr documentation built on July 19, 2023, 1:02 p.m.