# 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)
Run the code above in your browser using DataLab