% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ts-tree-update.R
\name{ts_tree_update}
\alias{ts_tree_update}
\title{Replace selected elements with a new element in a tree-sitter tree}
\usage{
ts_tree_update(tree, new, options, ...)
}
\arguments{
\item{tree}{A \code{ts_tree} object.}

\item{new}{The new element to replace the selected elements with.

The type of \code{new} depends on the parser and the method that implements
the insertion. See details in the manual of the specific parser.

See details in the manual of the specific parser.}

\item{options}{A list of options for the update.}

\item{...}{Extra arguments for methods.}
}
\value{
The modified \code{ts_tree} object with the selected elements replaced
by the new element.
}
\description{
Replace all selected elements with a new element.
}
\details{
If the tree does not have a selection, the new element replaces the
whole document.

If the tree has an empty selection, the new element is inserted at the
position of where the selected elements would be.
}
\examples{
\dontshow{if (requireNamespace("tsjsonc", quietly = TRUE)) withAutoprint(\{ # examplesIf}
# Create a parse tree with tsjsonc -------------------------------------
tree <- tsjsonc::ts_parse_jsonc(r"(
  {
    "name": "example",
    "version": "1.0.0",
    "dependencies": {
      "tsjsonc": "^0.1.0"
    }
  }
)")

ts_tree_update(ts_tree_select(tree, "version"), "2.0.0")
\dontshow{\}) # examplesIf}
\dontshow{if (requireNamespace("tstoml", quietly = TRUE)) withAutoprint(\{ # examplesIf}
# Create a parse tree with tstoml --------------------------------------
tree <- tstoml::ts_parse_toml(r"(
  [package]
  name = "example"
  version = "1.0.0"
  depdendencies = { tstoml = "0.1.0" }
)")

ts_tree_update(ts_tree_select(tree, "package", "version"), "2.0.0")
\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_write]{ts_tree_write()}}
}
\concept{ts_tree generics}
