R/model_unknown_statement.R

Defines functions UnknownStatement

Documented in UnknownStatement

#_______________________________________________________________________________
#----                     unknown_statement class                           ----
#_______________________________________________________________________________

#' 
#' Unknown statement class. Any statement not recognized by campsismod.
#' 
#' @export
setClass(
  "unknown_statement",
  representation(
    line = "character"
  ),
  contains = "model_statement",
  validity = function(object) {
    return(expect_one(object, "line"))
  }
)

#' 
#' Create a new ordinary differential equation (ODE).
#' 
#' @param line line which was not recognised
#' @param comment comment if any, single character string
#' @return an unknown statement
#' @export
UnknownStatement <- function(line, comment=as.character(NA)) {
  return(new("unknown_statement", line=line, comment=comment))
}

#_______________________________________________________________________________
#----                            get_name                                    ----
#_______________________________________________________________________________

#' @rdname get_name
setMethod("get_name", signature = c("unknown_statement"), definition = function(x) {
  return(as.character(NA)) # unknown statement non-identifiable 
})

#_______________________________________________________________________________
#----                             replace_all                                ----
#_______________________________________________________________________________

#' @rdname replace_all
setMethod("replace_all", signature=c("unknown_statement", "pattern", "character"), definition=function(object, pattern, replacement, ...) {
  object@line <- object@line %>% replace_all(pattern=pattern, replacement=replacement, ...)
  return(object)
})

#_______________________________________________________________________________
#----                             to_string                                 ----
#_______________________________________________________________________________

#' @rdname to_string
setMethod("to_string", signature=c("unknown_statement"), definition=function(object, ...) {
  args <- list(...)
  dest <- process_extra_arg(args=args, name="dest", default="campsis")
  show <- process_extra_arg(args=args, name="show", default=FALSE)

  if (dest=="campsis") {
    if (show) {
      retValue <- paste0("[UNKNOWN STATEMENT] ", object@line)
    } else {
      retValue <- object@line
    }
  } else if (is_rxode(dest) || dest=="mrgsolve" || dest=="NONMEM") {
    retValue <- object@line
  } else {
    UnsupportedDestException()
  }
  return(retValue %>% append_comment(object, dest))
})

Try the campsismod package in your browser

Any scripts or data that you put into this service are public.

campsismod documentation built on July 30, 2026, 9:06 a.m.