Skip to contents

Creates a directory for the article and downloads all of its files. Returns (invisibly) a data frame with file info.

Usage

figshare_file_download(
  figshare_id,
  download_to,
  max_file_size = 10,
  max_download_size = 100,
  unzip_types = NULL,
  host = "api.figshare.com",
  pb = NULL
)

Arguments

figshare_id

a Figshare article ID, URL, or DOI

download_to

path to download to; there is no default, because CRAN does not allow writing into the working directory unless you ask for it

max_file_size

maximum file size to download (in MB) - set to NULL or Inf for no restrictions

max_download_size

maximum total size to download - set to NULL or Inf for no restrictions

unzip_types

file categories to extract from .zip files in the article rather than downloading the zip whole, named as data_classify_files() names them: "data", "code", "materials", "documentation", "output", "unknown". More than one may be given. NULL (the default) downloads zips whole and leaves them zipped, as before. max_file_size applies to each extracted member rather than to the archive.

host

the Figshare-compatible API host to query. Default "api.figshare.com"; researchdata4tu_file_download() calls this with "data.4tu.nl" instead (see the note at the top of this file).

pb

a progress bar passed from another function

Value

data frame of file info. When members are extracted from a zip, its row reports the zip with extracted giving the number of members written; size_on_disk and checksum_ok are then NA, because what is on disk is the members rather than the archive Figshare published a size and MD5 for.

Details

Files are downloaded one by one, each from its own download_url. Figshare does document a whole-article zip (GET /v2/articles/{id}/download, which redirects to ndownloader.figshare.com/articles/<id>/versions/<v> and serves application/zip with a Content-Length, verified 2026-10-13), but it is not used here: it always contains every file, so it cannot honour the size limits below, and how it lays out files kept in folders was not verified. Files in folders (Figshare's folder_structure) are saved under those folders. A .zip already present in the article is handled the same way dataverse_file_download() handles one: fetched whole and left as a zip unless unzip_types asks for only specific members out of it.

You can limit downloads to only files under a specific size (defaults to 10MB) and only a maximum download size (largest files will be omitted until total size is under the limit). Omitted files will be listed as messages in verbose mode, and included in the returned data frame with the downloaded column value set to FALSE.

Examples

# \donttest{
if (online("api.figshare.com")) {
  dl <- figshare_file_download("18093368",
                               download_to = file.path(tempdir(), "figshare"),
                               max_download_size = 10)
}
# }