% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ts-tree-write.R
\name{ts_tree_write}
\alias{ts_tree_write}
\title{Write a tree-sitter tree to a file}
\usage{
ts_tree_write(tree, file = NULL)
}
\arguments{
\item{tree}{A \code{ts_tree} object as returned by
\code{\link[tsitter:ts_tree_new]{ts_tree_new()}}.}

\item{file}{Character string, connection, or \code{NULL}. The file or connection
to write to. By default it writes to the same file that was used in
\code{\link[tsitter:ts_tree_new]{ts_tree_new()}}, if \code{tree} was read from a
file.}
}
\value{
Invisibly returns \code{NULL}.
}
\description{
Writes the document of a ts \code{ts_tree} object to a file or connection.
}
\details{
If \code{tree} was created from a file, then \code{ts_tree_write()} by default
writes it back to the same file. Otherwise, the \code{file} argument must be
specified.

To write to a connection, pass a connection object to the \code{file}
argument. If the connection is opened in binary mode, the raw bytes
are written using \code{\link[base:writeBin]{base::writeBin()}}. Otherwise, the raw bytes are
converted to characters using the system encoding before writing using
\code{\link[base:rawToChar]{base::rawToChar()}}.\if{html}{\out{
</p><p><!-- ------------------------------------------------------>
}}


Use \code{file = stdout()} to write to the standard output, i.e. to the
console in an interactive R session.
}
\examples{
\dontshow{if (Sys.getenv("IN_PKGDOWN") == "true") withAutoprint(\{ # examplesIf}
# Create a parse tree with tsjsonc -------------------------------------
tree <- tsjsonc::ts_parse_jsonc('{"foo": 42, "bar": [1, 2, 3]}')

# Format and write to file
ts_tree_write(ts_tree_format(tree), "example.json")
\dontshow{\}) # examplesIf}
}
\seealso{
Other ts_tree generics:
\code{\link[=[[.ts_tree]{[[.ts_tree()}},
\code{\link[=[[<-.ts_tree]{[[<-.ts_tree()}},
\code{\link[=format.ts_tree]{format.ts_tree()}},
\code{\link[=print.ts_tree]{print.ts_tree()}},
\code{\link{select-set}},
\code{\link[=ts_tree_ast]{ts_tree_ast()}},
\code{\link[=ts_tree_delete]{ts_tree_delete()}},
\code{\link[=ts_tree_dom]{ts_tree_dom()}},
\code{\link[=ts_tree_format]{ts_tree_format()}},
\code{\link[=ts_tree_insert]{ts_tree_insert()}},
\code{\link[=ts_tree_new]{ts_tree_new()}},
\code{\link[=ts_tree_query]{ts_tree_query()}},
\code{\link[=ts_tree_select]{ts_tree_select()}},
\code{\link[=ts_tree_sexpr]{ts_tree_sexpr()}},
\code{\link[=ts_tree_unserialize]{ts_tree_unserialize()}},
\code{\link[=ts_tree_update]{ts_tree_update()}}
}
\concept{ts_tree generics}
