diff --git a/R/check.r b/R/check.r new file mode 100644 index 0000000..64f6071 --- /dev/null +++ b/R/check.r @@ -0,0 +1,20 @@ +#' @name check model +#' @title Check model and produce messages/warnings if any problems +#' +#' @description +#' This function currently only checks for balanced braces. +#' @param x a \code{\link{stanedit}} object +#' @importFrom checkmate assert_class +#' @return invisible \code{x} (called for it's side effects) +#' @seealso \code{\link{stanedit}} +#' @keywords internal +check_model <- function(x) { + x <- assert_class(x, "stanedit") + ## check + opening_curls <- length(grep("\\{", x)) + closing_curls <- length(grep("\\}", x)) + if (opening_curls != closing_curls) { + warning("Model contains unbalanced braces.") + } + return(invisible(x)) +} diff --git a/R/clean.r b/R/clean.r index abadbe0..7ad9fca 100644 --- a/R/clean.r +++ b/R/clean.r @@ -42,9 +42,8 @@ clean_model <- function(x) { x[i] <- sub("/\\*.*$", "", x[i]) comment <- TRUE } - if (!grepl("[{};][[:space:]]*$", x[i]) && - !(grepl("#", x[i])) && - i < length(x)) { + if (!grepl("[{};][[:space:]]*$", x[i]) && !(grepl("#", x[i])) && + i < length(x)) { ## line not finished -- merge lines x[i] <- paste(x[i], x[i + 1]) x <- x[-(i + 1)] @@ -71,13 +70,7 @@ clean_model <- function(x) { ## remove empty lines x <- x[x != ""] - ## check - opening_curls <- length(grep("\\{", x)) - closing_curls <- length(grep("\\}", x)) - if (opening_curls != closing_curls) { - warning("Model contains unbalanced braces.") - } model <- structure(x, class = "stanedit") - return(model) + return(check_model(model)) } diff --git a/man/check-model.Rd b/man/check-model.Rd new file mode 100644 index 0000000..c287b51 --- /dev/null +++ b/man/check-model.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/check.r +\name{check model} +\alias{check model} +\alias{check_model} +\title{Check model and produce messages/warnings if any problems} +\usage{ +check_model(x) +} +\arguments{ +\item{x}{a \code{\link{stanedit}} object} +} +\value{ +invisible \code{x} (called for it's side effects) +} +\description{ +This function currently only checks for balanced braces. +} +\seealso{ +\code{\link{stanedit}} +} +\keyword{internal}