R/count_trees_in_file.R

Defines functions count_trees_in_file

Documented in count_trees_in_file

#' Count the number of trees in a \code{.trees} file
#' @inheritParams default_params_doc
#' @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"
    )
  }
  sum(stringr::str_count(
    string = readLines(trees_filename ,warn = FALSE),
    pattern = "(^tree STATE_)|(\tTREE \\* UNTITLED = \\[&R\\] \\()")
  )
}
ropensci/tracerer documentation built on March 12, 2019, 8:30 p.m.