| Title: | Client for the 'TemplateFlow' Archive |
|---|---|
| Description: | R client for querying and fetching resources from the TemplateFlow archive using a local cache backed by the public TemplateFlow S3 bucket. Provides functions to list template assets, download missing files, read template metadata, and retrieve citations. |
| Authors: | Bradley Buchsbaum [aut, cre], NiPreps [aut, cph], OpenAI Codex [aut] |
| Maintainer: | Bradley Buchsbaum <[email protected]> |
| License: | Apache License (>= 2) |
| Version: | 0.1.0 |
| Built: | 2026-06-03 08:14:54 UTC |
| Source: | https://github.com/bbuchsbaum/templateflow |
Print a TemplateFlowClient
## S3 method for class 'TemplateFlowClient' print(x, ...)## S3 method for class 'TemplateFlowClient' print(x, ...)
x |
A 'TemplateFlowClient' object. |
... |
Additional arguments (ignored). |
'x', invisibly.
Create a client for querying the TemplateFlow archive.
TemplateFlowClient(root = NULL, cache = NULL, ...)TemplateFlowClient(root = NULL, cache = NULL, ...)
root |
Optional cache root (defaults to '~/.cache/templateflow' or 'TEMPLATEFLOW_HOME'). |
cache |
Optional pre-built 'TemplateFlowCache'. |
... |
Additional config passed to 'tf_default_config()'. |
A 'TemplateFlowClient' object.
## Not run: client <- TemplateFlowClient() client <- TemplateFlowClient(root = "/tmp/tf-cache") ## End(Not run)## Not run: client <- TemplateFlowClient() client <- TemplateFlowClient(root = "/tmp/tf-cache") ## End(Not run)
Rebuild the layout index without downloading any files.
tf_cache_refresh(cache = NULL)tf_cache_refresh(cache = NULL)
cache |
A 'TemplateFlowCache' object or a character path to the cache root (optional; uses default client cache). |
The updated cache (invisibly), or a 'TemplateFlowLayout' if a character path was supplied.
## Not run: tf_cache_refresh() ## End(Not run)## Not run: tf_cache_refresh() ## End(Not run)
Find zero-byte stubs and S3 XML error responses in the cache.
tf_cache_scan(cache = NULL)tf_cache_scan(cache = NULL)
cache |
A 'TemplateFlowCache' object or a character path to the cache root (optional; uses default client cache). |
A list with 'zero' (zero-byte paths) and 'xml' (XML error paths).
## Not run: tf_cache_scan() ## End(Not run)## Not run: tf_cache_scan() ## End(Not run)
Report the number and total size of cached files.
tf_cache_stats(cache = NULL)tf_cache_stats(cache = NULL)
cache |
A 'TemplateFlowCache' object or a character path to the cache root (optional; uses default client cache). |
A list with 'cache_files', 'cache_bytes', and 'cache_size_human'.
## Not run: tf_cache_stats() ## End(Not run)## Not run: tf_cache_stats() ## End(Not run)
Re-extract the skeleton archive, optionally fetching the latest version from the remote repository.
tf_cache_update(cache = NULL, local = FALSE, overwrite = TRUE, silent = FALSE)tf_cache_update(cache = NULL, local = FALSE, overwrite = TRUE, silent = FALSE)
cache |
A 'TemplateFlowCache' object (optional; uses default client cache). |
local |
If 'TRUE', only use the bundled skeleton (no network). |
overwrite |
If 'TRUE', overwrite existing stub files. |
silent |
If 'TRUE', suppress progress messages. |
The updated cache (invisibly).
## Not run: tf_cache_update() tf_cache_update(local = TRUE) ## End(Not run)## Not run: tf_cache_update() tf_cache_update(local = TRUE) ## End(Not run)
Delete the entire local template cache directory. Not supported when using the DataLad backend (use 'datalad drop' instead).
tf_cache_wipe(cache = NULL)tf_cache_wipe(cache = NULL)
cache |
A 'TemplateFlowCache' object (optional; uses default client cache). |
The cache object (invisibly).
## Not run: tf_cache_wipe() ## End(Not run)## Not run: tf_cache_wipe() ## End(Not run)
Command-line interface for the TemplateFlow archive. Supports subcommands: 'config', 'ls', 'get', 'wipe', 'update', 'meta', 'cite', 'refresh', 'doctor'.
tf_cli(args = commandArgs(trailingOnly = TRUE))tf_cli(args = commandArgs(trailingOnly = TRUE))
args |
Character vector of CLI-style arguments (defaults to commandArgs). |
Invisible result of the requested command.
## Not run: tf_cli(c("ls", "MNI152Lin", "--suffix", "T1w")) tf_cli(c("config")) tf_cli(c("meta", "MNI152Lin")) tf_cli(c("doctor", "--fix")) ## End(Not run)## Not run: tf_cli(c("ls", "MNI152Lin", "--suffix", "T1w")) tf_cli(c("config")) tf_cli(c("meta", "MNI152Lin")) tf_cli(c("doctor", "--fix")) ## End(Not run)
Get or create the default global TemplateFlow client
tf_client()tf_client()
A 'TemplateFlowClient'.
Tests whether the 'datalad' command-line tool is installed and accessible.
tf_datalad_available()tf_datalad_available()
TRUE if datalad is available, FALSE otherwise.
Retrieve (download) specific files from a DataLad dataset.
tf_datalad_get(files, dataset)tf_datalad_get(files, dataset)
files |
Character vector of file paths to retrieve. |
dataset |
Path to the DataLad dataset root. |
Invisible files vector.
## Not run: tf_datalad_get(c("tpl-MNI152Lin/tpl-MNI152Lin_res-01_T1w.nii.gz"), dataset = "~/.cache/templateflow") ## End(Not run)## Not run: tf_datalad_get(c("tpl-MNI152Lin/tpl-MNI152Lin_res-01_T1w.nii.gz"), dataset = "~/.cache/templateflow") ## End(Not run)
Clone/install a DataLad dataset to a local path.
tf_datalad_install(path, source, recursive = TRUE)tf_datalad_install(path, source, recursive = TRUE)
path |
Local destination path. |
source |
Dataset source URL or path. |
recursive |
If TRUE, install subdatasets recursively. |
Invisible path.
## Not run: tf_datalad_install("~/.cache/templateflow", source = "https://github.com/templateflow/templateflow.git") ## End(Not run)## Not run: tf_datalad_install("~/.cache/templateflow", source = "https://github.com/templateflow/templateflow.git") ## End(Not run)
Fetch updates from the remote and optionally merge.
tf_datalad_update(dataset, recursive = TRUE, merge = TRUE)tf_datalad_update(dataset, recursive = TRUE, merge = TRUE)
dataset |
Path to the DataLad dataset root. |
recursive |
If TRUE, update subdatasets recursively. |
merge |
If TRUE, merge fetched changes. |
Invisible TRUE.
## Not run: tf_datalad_update("~/.cache/templateflow", recursive = TRUE, merge = TRUE) ## End(Not run)## Not run: tf_datalad_update("~/.cache/templateflow", recursive = TRUE, merge = TRUE) ## End(Not run)
Returns the entity names recognised by TemplateFlow for filtering template files (e.g. 'resolution', 'atlas', 'suffix').
tf_entities()tf_entities()
A character vector of entity names sorted alphabetically.
tf_entities()tf_entities()
Handles compound extensions like '.nii.gz', '.surf.gii', etc.
tf_file_extension(path)tf_file_extension(path)
path |
File path. |
The file extension including leading dot.
Download template files from the TemplateFlow archive and optionally read them into R objects. Like [tf_ls()], entity filters support 'NULL' values to exclude files containing that entity.
tf_get(client = NULL, template, raise_empty = FALSE, read = FALSE, ...)tf_get(client = NULL, template, raise_empty = FALSE, read = FALSE, ...)
client |
A 'TemplateFlowClient' (optional; default global client). |
template |
Template identifier (e.g., '"MNI152Lin"'). |
raise_empty |
If 'TRUE', error when no files match the query. |
read |
If 'TRUE', read downloaded files into R objects using appropriate readers (NIfTI via RNifti, GIFTI via gifti, JSON, TSV). Requires optional packages for neuroimaging formats. |
... |
Entity filters (resolution, suffix, atlas, desc, hemi, space, density, label, segmentation, cohort, scale, roi, extension, etc.). Pass 'NULL' to exclude files containing that entity. |
Path string, character vector, or R object(s) if 'read = TRUE'. When a single file matches, a scalar path (or single R object) is returned; when multiple files match, a character vector (or list of R objects).
## Not run: path <- tf_get(template = "MNI152Lin", resolution = 1, suffix = "T1w") img <- tf_get(template = "MNI152Lin", resolution = 1, suffix = "T1w", read = TRUE) ## End(Not run)## Not run: path <- tf_get(template = "MNI152Lin", resolution = 1, suffix = "T1w") img <- tf_get(template = "MNI152Lin", resolution = 1, suffix = "T1w", read = TRUE) ## End(Not run)
Retrieve template citations
tf_get_citations(client = NULL, template, bibtex = FALSE)tf_get_citations(client = NULL, template, bibtex = FALSE)
client |
A 'TemplateFlowClient' (optional; default global client). |
template |
Template identifier (e.g., '"MNI152Lin"'). |
bibtex |
If TRUE, fetch citations in BibTeX format. |
Character vector of citation URLs or BibTeX entries.
## Not run: tf_get_citations(template = "MNI152NLin2009cAsym") tf_get_citations(template = "MNI152NLin2009cAsym", bibtex = TRUE) ## End(Not run)## Not run: tf_get_citations(template = "MNI152NLin2009cAsym") tf_get_citations(template = "MNI152NLin2009cAsym", bibtex = TRUE) ## End(Not run)
Read template metadata
tf_get_metadata(client = NULL, template)tf_get_metadata(client = NULL, template)
client |
A 'TemplateFlowClient' (optional; default global client). |
template |
Template identifier (e.g., '"MNI152Lin"'). |
List parsed from 'template_description.json'.
## Not run: meta <- tf_get_metadata(template = "MNI152Lin") meta$Name ## End(Not run)## Not run: meta <- tf_get_metadata(template = "MNI152Lin") meta$Name ## End(Not run)
Query the TemplateFlow cache for files matching a template and optional entity filters.
tf_ls(client = NULL, template, as_df = FALSE, ...)tf_ls(client = NULL, template, as_df = FALSE, ...)
client |
A 'TemplateFlowClient' (optional; default global client). |
template |
Template identifier (e.g., '"MNI152Lin"'). |
as_df |
If 'TRUE', return a data frame instead of file paths. |
... |
Entity filters (resolution, suffix, atlas, desc, hemi, space, density, label, segmentation, cohort, scale, roi, extension, etc.). Pass 'NULL' to exclude files containing that entity. |
Entity filters are passed via '...'. Use 'NULL' to *exclude* an entity — for example, 'desc = NULL' returns only files that do **not** have a 'desc-' key in their filename. This matches the Python client's behaviour where 'desc=None' filters out files with a description tag.
Character vector of file paths, or a data frame if 'as_df = TRUE'.
## Not run: tf_ls(template = "MNI152Lin", resolution = 1, suffix = "T1w") tf_ls(template = "MNI152Lin", extension = ".nii.gz") tf_ls(template = "MNI152Lin", as_df = TRUE) ## End(Not run)## Not run: tf_ls(template = "MNI152Lin", resolution = 1, suffix = "T1w") tf_ls(template = "MNI152Lin", extension = ".nii.gz") tf_ls(template = "MNI152Lin", as_df = TRUE) ## End(Not run)
Downloads all zero-byte skeleton stubs matching the given filters.
tf_prefetch(client = NULL, templates = NULL, ...)tf_prefetch(client = NULL, templates = NULL, ...)
client |
A 'TemplateFlowClient' (optional; default global client). |
templates |
Character vector of template names to prefetch. If NULL, prefetches all templates. |
... |
Entity filters passed to 'tf_ls()'. |
Invisible count of files downloaded.
## Not run: tf_prefetch(templates = "MNI152Lin") tf_prefetch() ## End(Not run)## Not run: tf_prefetch(templates = "MNI152Lin") tf_prefetch() ## End(Not run)
Dispatches by file extension to the appropriate reader. NIfTI files use 'RNifti' or 'oro.nifti' (soft deps), GIFTI files use 'gifti', JSON files use 'jsonlite', and TSV files use 'utils::read.delim()'.
tf_read_file(path)tf_read_file(path)
path |
Path to the file. |
An R object appropriate for the file type, or the path if no reader is available.
Set global client
tf_set_client(client)tf_set_client(client)
client |
A 'TemplateFlowClient'. |
The client (invisibly).
## Not run: client <- TemplateFlowClient() tf_set_client(client) ## End(Not run)## Not run: client <- TemplateFlowClient() tf_set_client(client) ## End(Not run)
List available templates
tf_templates(client = NULL, ...)tf_templates(client = NULL, ...)
client |
A 'TemplateFlowClient' (optional; default global client). |
... |
Entity filters (resolution, suffix, atlas, desc, hemi, space, density, label, segmentation, cohort, scale, roi, extension, etc.). Pass 'NULL' to exclude files containing that entity. |
Character vector of template IDs.
## Not run: tf_templates() ## End(Not run)## Not run: tf_templates() ## End(Not run)