| Line 6... |
Line 6... |
| 6 |
but also that errors or warnings are signalled in appropriate
|
6 |
but also that errors or warnings are signalled in appropriate
|
| 7 |
situations. \code{assertCondition()} allows to perform such checks
|
7 |
situations. \code{assertCondition()} allows to perform such checks
|
| 8 |
conveniently.
|
8 |
conveniently.
|
| 9 |
}
|
9 |
}
|
| 10 |
\usage{
|
10 |
\usage{
|
| 11 |
assertCondition(expr, ..., verbose=getOption("verbose"),
|
11 |
assertCondition(expr, ..., verbose = getOption("verbose"))
|
| 12 |
ignoreWarning = is.na(match("warning", conds)))
|
- |
|
| 13 |
}
|
12 |
}
|
| 14 |
\arguments{
|
13 |
\arguments{
|
| 15 |
\item{expr}{an unevaluated \R expression which will be evaluated via
|
14 |
\item{expr}{an unevaluated \R expression which will be evaluated via
|
| 16 |
\code{\link{tryCatch}(expr, ..)}.}
|
15 |
\code{\link{tryCatch}(expr, ..)}.}
|
| 17 |
\item{\dots}{\code{\link{character}} strings such as \code{"error"} or
|
16 |
\item{\dots}{\code{\link{character}} strings such as \code{"error"} or
|
| 18 |
\code{"warning"}; defaults to \code{"condition"}.}
|
17 |
\code{"warning"}; defaults to \code{"condition"}.}
|
| 19 |
\item{verbose}{logical indicating if the message should be shown even
|
18 |
\item{verbose}{logical indicating if the message should be shown even
|
| 20 |
when the condition is asserted.}
|
19 |
when the condition is asserted.}
|
| 21 |
\item{ignoreWarning}{logical indicating if \code{"warning"} messages
|
- |
|
| 22 |
should be caught. In that case, the warning is typically caught
|
- |
|
| 23 |
\emph{before} an error can be signalled, and so an \code{"error"} can
|
- |
|
| 24 |
not be asserted.}
|
- |
|
| 25 |
}
|
20 |
}
|
| 26 |
%% \details{
|
21 |
%% \details{
|
| 27 |
%% }
|
22 |
%% }
|
| 28 |
\value{
|
23 |
\value{
|
| 29 |
if the \code{assertCondition(*)} does not signal an error, this means that
|
24 |
if the \code{assertCondition(*)} does not signal an error, this means that
|
| Line 54... |
Line 49... |
| 54 |
assertCondition(matrix(1:8, 4, 3), "warning", "error") # ditto
|
49 |
assertCondition(matrix(1:8, 4, 3), "warning", "error") # ditto
|
| 55 |
|
50 |
|
| 56 |
## when both are signalled:
|
51 |
## when both are signalled:
|
| 57 |
ff <- function() { warning("my warning"); stop("my error") }
|
52 |
ff <- function() { warning("my warning"); stop("my error") }
|
| 58 |
assertCondition(ff(), "warning")
|
53 |
assertCondition(ff(), "warning")
|
| 59 |
assertCondition(ff(), "error") # ok + signalling the warning
|
54 |
assertCondition(ff(), "error") # ok
|
| 60 |
assertCondition(ff(), "error", ignoreWarning=TRUE) # ditto
|
- |
|
| 61 |
try(assertCondition(ff(), "error", ignoreWarning=FALSE) )# not ok:
|
- |
|
| 62 |
#-> gets warning instead of error
|
- |
|
| 63 |
assertCondition(ff(), "error", "warning") # ok (quietly, catching warning)
|
55 |
assertCondition(ff(), "error", "warning") # ok (quietly, catching warning)
|
| - |
|
56 |
|
| - |
|
57 |
## assert that assertC..() does not assert [and use *one* argument only]
|
| - |
|
58 |
assertCondition( assertCondition(sqrt( 2 ), "warning") )
|
| - |
|
59 |
assertCondition( assertCondition(sqrt("abc"), "warning"), "error")
|
| - |
|
60 |
assertCondition( assertCondition(matrix(1:8, 4,3), "error"),
|
| - |
|
61 |
"error", verbose=TRUE)
|
| 64 |
}
|
62 |
}
|
| 65 |
\keyword{programming}
|
63 |
\keyword{programming}
|
| 66 |
\keyword{error}
|
64 |
\keyword{error}
|