Downloads fMRIPrep, MRIQC, or other derivative outputs from OpenNeuro datasets. Supports filtering by subject, output space, and BIDS suffix. Uses S3 backend (openneuro-derivatives bucket) with HTTPS fallback.
Usage
on_download_derivatives(
dataset_id,
pipeline,
subjects = NULL,
space = NULL,
suffix = NULL,
dry_run = FALSE,
dest_dir = NULL,
use_cache = TRUE,
quiet = FALSE,
verbose = FALSE,
force = FALSE,
backend = NULL,
client = NULL
)Arguments
- dataset_id
Dataset identifier (e.g., "ds000001").
- pipeline
Pipeline name (e.g., "fmriprep", "mriqc").
- subjects
Character vector of subject IDs (e.g.,
c("sub-01", "sub-02")) or a regex pattern wrapped inregex()(e.g.,regex("sub-0[1-5]")). Subject IDs can be specified with or without the "sub-" prefix. IfNULL(default), downloads all subjects.- space
Character string: output space to filter by (e.g., "MNI152NLin2009cAsym", "fsaverage", "T1w"). If
NULL(default), downloads all spaces. Matching is exact (specify full space name). Files without a_space-entity (native space) are always included.- suffix
Character vector of BIDS suffixes to filter by (e.g.,
c("bold", "T1w", "mask")). IfNULL(default), downloads all suffixes. Files without a clear suffix (metadata files) are always included.- dry_run
If
TRUE, returns a tibble of files that would be downloaded without actually downloading them. Default isFALSE.- dest_dir
Destination directory. If
NULL(default) anduse_cacheisTRUE, downloads to BIDS-compliant cache location:{cache}/{dataset_id}/derivatives/{pipeline}/.- use_cache
If
TRUE(default) anddest_dirisNULL, downloads to CRAN-compliant cache location. SetFALSEto use current working directory.- quiet
If
TRUE, suppress all progress output. DefaultFALSE.- verbose
If
TRUE, show per-file progress in addition to overall progress. DefaultFALSE.- force
If
TRUE, re-download files even if they exist with correct size. DefaultFALSE.- backend
Backend to use for downloading: "s3" or "https". If
NULL(default), auto-selects S3 for openneuro-derivatives bucket.- client
An
openneuro_clientobject. IfNULL, creates default client.
Value
If dry_run = TRUE, returns a tibble with columns:
- path
Relative path within derivative
- size
File size in bytes
- size_formatted
Human-readable size (e.g., "1.2 GB")
- dest_path
Full destination path where file would be downloaded
If dry_run = FALSE, invisibly returns a list with:
- downloaded
Number of files downloaded
- skipped
Number of files skipped (already cached)
- failed
Character vector of failed file names
- total_bytes
Total bytes downloaded
- dest_dir
Path to destination directory
- backend
Backend used for download
Details
Filter Logic
All filters combine with AND logic - a file must match ALL specified
filters to be included. For example, subjects = "sub-01", space = "MNI152NLin2009cAsym"
downloads only sub-01's MNI-space files.
Cache Structure
Derivatives are cached in BIDS-compliant structure:
{cache_root}/{dataset_id}/derivatives/{pipeline}/
This keeps derivatives organized alongside raw data while maintaining clear separation by pipeline.
See also
on_derivatives() to discover available derivatives,
on_spaces() to discover available output spaces,
on_download() to download raw datasets
Examples
if (FALSE) { # \dontrun{
# Download all fMRIPrep derivatives for a dataset
on_download_derivatives("ds000001", "fmriprep")
# Download specific subjects
on_download_derivatives("ds000001", "fmriprep",
subjects = c("sub-01", "sub-02"))
# Download only MNI-space outputs
on_download_derivatives("ds000001", "fmriprep",
space = "MNI152NLin2009cAsym")
# Download only BOLD and mask files
on_download_derivatives("ds000001", "fmriprep",
suffix = c("bold", "mask"))
# Preview files without downloading
files <- on_download_derivatives("ds000001", "fmriprep",
subjects = "sub-01",
space = "MNI152NLin2009cAsym",
dry_run = TRUE)
print(files)
# Combine all filters
on_download_derivatives("ds000001", "fmriprep",
subjects = regex("sub-0[1-5]"),
space = "MNI152NLin2009cAsym",
suffix = c("bold", "T1w"))
} # }