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.
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.
See also
Other ts_tree generics:
[[.ts_tree(),
[[<-.ts_tree(),
format.ts_tree(),
print.ts_tree(),
select-set,
ts_tree_ast(),
ts_tree_delete(),
ts_tree_dom(),
ts_tree_format(),
ts_tree_insert(),
ts_tree_new(),
ts_tree_query(),
ts_tree_select(),
ts_tree_sexpr(),
ts_tree_unserialize(),
ts_tree_update()
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")