Writes the document of a ts ts_tree object to a file or connection.
Arguments
- tree
A
ts_treeobject as returned byts_tree_new().- file
Character string, connection, or
NULL. The file or connection to write to. By default it writes to the same file that was used ints_tree_new(), iftreewas read from a file.
Details
If tree was created from a file, then ts_tree_write() by default
writes it back to the same file. Otherwise, the file argument must be
specified.
Format a JSONC file:
tree <- tsjsonc::ts_read_jsonc("config.json")
tree |> ts_tree_format() |> ts_tree_write()file
argument. If the connection is opened in binary mode, the raw bytes
are written using base::writeBin(). Otherwise, the raw bytes are
converted to characters using the system encoding before writing using
base::rawToChar().
Use file = stdout() to write to the standard output, i.e. to the
console in an interactive R session.
Examples
# Create a parse tree with tsjsonc -------------------------------------
tree <- tsjsonc::ts_parse_jsonc('{"foo": 42, "bar": [1, 2, 3]}')
# Format and write to file
tree |> ts_tree_format() |> ts_tree_write("example.json")