as_bids_tabular {bidsr} | R Documentation |
Class definitions and utilities for 'BIDS' tabular
Description
Official specification link:
https://bids-specification.readthedocs.io/en/stable/common-principles.html#tabular-files.
Function save_tabular
is the high-level generic function that by
default calls low-level function save_bids_tabular_default
by default.
Usage
as_bids_tabular(x, ...)
save_bids_tabular(x, path, meta = TRUE, ...)
BIDSTabularColumnDescriptor(..., .list = list())
BIDSTabularMetaSidecar(columns = list())
BIDSTabular(content, meta = NULL)
save_bids_tabular_default(
x,
path,
meta = TRUE,
compact_meta = TRUE,
milliseconds = TRUE,
utc = TRUE,
...
)
new_bids_tabular_class(
table_name,
parent = BIDSTabular,
content_setter = NULL,
meta_preset = NULL,
prepare_save = NULL,
lower_case_column_names = FALSE
)
Arguments
x |
R object that can be converted (e.g. list, table), or a path to a tabular file. |
... , .list |
for |
path |
path to save the file; the file is always saved as tabular-separated value ('TSV') format |
meta |
instance of |
columns |
a named list, where each key correspond to a table column
name, and each item is a named list of descriptors, or a
|
content |
a data frame or table with column names non-blanks and
possibly all in snake-cases (see specification); |
compact_meta |
logical, whether the meta side-car ('JSON' file) should use compact format; default is true |
milliseconds , utc |
used to convert |
table_name |
name of the table, used to generate a new class;
the class name will be |
parent |
parent class of the new class; default is |
content_setter |
a |
meta_preset |
a |
prepare_save |
a function to prepare the content before saving; should
take the |
lower_case_column_names |
if |
Value
A component in BIDSTabular
.
Author(s)
Zhengjia Wang
Examples
# convert a data table into BIDS tabular
table <- data.frame(
a = c(1, 2, 3, NA, NA, 6, 7, 8, 9, 10),
b = sample(c('a', 'b'), size = 10, replace = TRUE)
)
# basic
as_bids_tabular(table)
# add descriptors
tabular <- as_bids_tabular(
table,
a = list(LongName = "An integer"),
b = list("Levels" = list('a' = "Abnormal", 'b' = "Bipolar"))
)
tabular
# query data
is.data.frame(tabular$content)
tabular$content$a
# query meta
tabular$meta$columns$a
# save to tsv
tsv <- tempfile(fileext = ".tsv")
paths <- save_bids_tabular(tabular, tsv)
print(paths)
# use base R to read
read.table(tsv, header = TRUE, na.strings = "n/a")
# get sidecar
cat(readLines(paths$sidecar_path), sep = "\n")
unlink(tsv)
unlink(paths$sidecar_path)