low-level-read-write {ieegio} | R Documentation |
Low-level file read and write
Description
Interfaces to read from or write to files with common formats.
Usage
io_read_fst(
con,
method = c("proxy", "data_table", "data_frame", "header_only"),
...,
old_format = FALSE
)
io_write_fst(x, con, compress = 50, ...)
io_read_ini(con, ...)
io_read_json(con, ...)
io_write_json(
x,
con = stdout(),
...,
digits = ceiling(-log10(.Machine$double.eps)),
pretty = TRUE,
serialize = TRUE
)
io_read_mat(
con,
method = c("auto", "R.matlab", "pymatreader", "mat73"),
verbose = TRUE,
on_convert_error = c("warning", "error", "ignore"),
...
)
io_write_mat(x, con, method = c("R.matlab", "scipy"), ...)
io_read_yaml(con, ...)
io_write_yaml(x, con, ..., sorted = FALSE)
Arguments
con |
connection or file |
method |
method to read table. For
For
|
... |
passed to internal function calls |
old_format |
see |
x |
data to write to disk |
compress |
compress level from 0 to 100; default is 50 |
digits , pretty |
for writing numeric values to 'json' format |
serialize |
set to |
verbose |
whether to print out the process |
on_convert_error |
for reading |
sorted |
whether to sort the list; default is |
Value
The reader functions returns the data extracted from files, mostly
as R objects, with few exceptions on some 'Matlab' files. When reading a
'Matlab' file requires using 'Python' modules, io_read_mat
will
try its best effort to convert 'Python' objects to R. However, such
conversion might fail. In this case, the result might partially contain
'Python' objects with warnings.
Examples
# ---- fst ----------------------------------------------------------------
f <- tempfile(fileext = ".fst")
x <- data.frame(
a = 1:10,
b = rnorm(10),
c = letters[1:10]
)
io_write_fst(x, con = f)
# default reads in proxy
io_read_fst(f)
# load as data.table
io_read_fst(f, "data_table")
# load as data.frame
io_read_fst(f, "data_frame")
# get header
io_read_fst(f, "header_only")
# clean up
unlink(f)
# ---- json ---------------------------------------------------------------
f <- tempfile(fileext = ".json")
x <- list(a = 1L, b = 2.3, c = "a", d = 1+1i)
# default is serialize
io_write_json(x, f)
io_read_json(f)
cat(readLines(f), sep = "\n")
# just values
io_write_json(x, f, serialize = FALSE, pretty = FALSE)
io_read_json(f)
cat(readLines(f), sep = "\n")
# clean up
unlink(f)
# ---- Matlab .mat --------------------------------------------------------
## Not run:
f <- tempfile(fileext = ".mat")
x <- list(a = 1L, b = 2.3, c = "a", d = 1+1i)
# save as MAT 5.0
io_write_mat(x, f)
io_read_mat(f)
# require setting up Python environment
io_read_mat(f, method = "pymatreader")
# MAT 7.3 example
sample_data <- ieegio_sample_data("mat_v73.mat")
io_read_mat(sample_data)
# clean up
unlink(f)
## End(Not run)
# ---- yaml ---------------------------------------------------------------
f <- tempfile(fileext = ".yaml")
x <- list(a = 1L, b = 2.3, c = "a")
io_write_yaml(x, f)
io_read_yaml(f)
# clean up
unlink(f)