Generic function for writing MVPA result objects (searchlight, regional, or simple lists of maps) to a directory on disk in a reproducible layout.
Arguments
- x
A result object (typically a
searchlight_result,regional_mvpa_result, or a named list ofNeuroVol/NeuroVec(and optionallyNeuroSurface/NeuroSurfaceVector) objects.- dir
Directory to write into. It is created if it does not exist.
- level
One of
"minimal","standard","complete":"minimal": write only map files (no manifest, no tables, no aux)."standard": maps + a manifest describing files (default)."complete": maps + manifest + summary tables and auxiliary objects when available.
- stack
One of
c("none","auto","vec")."none": write one NIfTI file per metric (default)."auto": if all volumes are compatible (same space), stack them along the 4th dimension; otherwise fall back to one file per metric."vec": always stack into a single 4D NIfTI (error if not compatible).
- fname
Base filename when writing a 4D file (default
"searchlight.nii.gz"). Only used whenstack = "vec"or whenstack = "auto"and stacking is possible.- include
Character vector of extras to include; subset of
c("manifest","tables","aux"). Thelevelargument sets sensible defaults butincludecan add to these.- dtype
Optional
data_typepassed to neuroim2 writers (e.g.,"FLOAT","DOUBLE").- overwrite
Logical; if
FALSEand a target file already exists, a numeric suffix is appended instead of overwriting.- quiet
Logical; if
TRUE, suppress progress messages.
Value
(invisible) a list describing what was written (file paths grouped
by type such as maps, surfaces, tables, aux,
and manifest).
Details
save_results() is an S3 generic. The main methods are:
save_results.searchlight_result: writes volumetric maps under<dir>/mapsand (optionally) surface maps under<dir>/surfaces. Depending onlevel/include, it can also write a per-metric summary table (<dir>/tables/metric_summary.csv), auxiliary objects (e.g. predictions, CV folds, design) as.rdsfiles under<dir>/aux, and a manifest (manifest.yaml/json/rds) describing all files and their metric names.save_results.regional_mvpa_result: uses thesearchlight_resultmethod to write volumetric maps invol_results, then saves regional tables such asperformance_tableandprediction_tableas tab-delimited text. Forlevel != "minimal", ROI-wise fits (if present) are saved under<dir>/fits. A manifest can be written summarizing ROI counts, presence of fits, and all file paths.save_results.default: ifxis a named list ofNeuroVol/NeuroVec(and/or surface) objects, it is treated as a lightweight searchlight-style result and handled as above. Otherwise a simpleresult.rdsis written todir.
All methods return (invisibly) a nested list of file paths that can be used to track outputs or drive downstream packaging/publishing.
Examples
# \donttest{
# After running a searchlight analysis:
# sl_res <- run_searchlight(mspec, radius = 2)
# Save maps and a manifest into "sl_output"
# save_results(sl_res, "sl_output", level = "standard")
# After running a regional analysis:
# reg_res <- run_regional(mspec, regionMask)
# Save regional maps, performance table, and fits
# save_results(reg_res, "regional_output", level = "complete")
# }