#' Count the number of trees in a \code{.trees} file
#' @inheritParams default_params_doc
#' @return the number of trees
#' @seealso if the \code{.trees} file is invalid,
#' use \link{is_trees_file} with \code{verbose = TRUE}
#' for the reason
#' @author Richèl J.C. Bilderbeek
#' @export
count_trees_in_file <- function(
trees_filename
) {
if (!file.exists(trees_filename)) {
stop(
"'trees_filename' absent.\n",
"File '", trees_filename, "' not found"
)
}
if (!tracerer::is_trees_file(trees_filename = trees_filename)) {
stop(
"'trees_filename' invalid"
)
}
# pattern = "(^tree STATE_)|(\tTREE \\* UNTITLED = \\[&R\\] \\()")
sum(
stringr::str_detect(
string = readLines(trees_filename, warn = FALSE),
pattern = "(^tree STATE_)|(\tTREE \\* (UNTITLED|STATE_[:digit:]*) = \\[&R\\] \\()"
)
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.