Skip to content

Commit

Permalink
check
Browse files Browse the repository at this point in the history
  • Loading branch information
sbfnk committed Nov 14, 2024
1 parent 4321c27 commit 7bb7525
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
20 changes: 20 additions & 0 deletions R/check.r
Original file line number Diff line number Diff line change
@@ -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))
}
13 changes: 3 additions & 10 deletions R/clean.r
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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))
}
22 changes: 22 additions & 0 deletions man/check-model.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7bb7525

Please sign in to comment.