The R Project SVN R

Rev

Rev 63205 | Rev 76421 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 63205 Rev 63451
Line 19... Line 19...
19
}
19
}
20
\arguments{
20
\arguments{
21
  \item{expr}{an unevaluated \R expression which will be evaluated via
21
  \item{expr}{an unevaluated \R expression which will be evaluated via
22
    \code{\link{tryCatch}(expr, ..)}.}
22
    \code{\link{tryCatch}(expr, ..)}.}
23
  \item{\dots}{\code{\link{character}} strings corresponding to the
23
  \item{\dots}{\code{\link{character}} strings corresponding to the
24
      classes of the conditions that would satisfy the assertion; e.g., \code{"error"} or
24
    classes of the conditions that would satisfy the assertion; e.g., \code{"error"} or
25
    \code{"warning"}. If none are specified, any condition will
25
    \code{"warning"}. If none are specified, any condition will
26
    satisfy the assertion.  See the details section. }
26
    satisfy the assertion.  See the details section. }
27
  \item{.exprString}{The string to be printed corresponding to
27
  \item{.exprString}{The string to be printed corresponding to
28
      \code{expr}. By default, the actual \code{expr} will be
28
    \code{expr}. By default, the actual \code{expr} will be
29
      deparsed.  Will be omitted if the function is supplied with the
29
    deparsed.  Will be omitted if the function is supplied with the
30
      actual expression to be tested.  If \code{assertCondition()} is
30
    actual expression to be tested.  If \code{assertCondition()} is
31
      called from another 
-
 
32
        function, with the actual expression passed as an argument to
31
    called from another function, with the actual expression passed as
33
        that function, supply the deparsed version.}
32
    an argument to that function, supply the deparsed version.}
34
  \item{verbose}{If \code{TRUE}, a message is printed when the
33
  \item{verbose}{If \code{TRUE}, a message is printed when the
35
        condition is satisfied.}
34
    condition is satisfied.}
36
}
35
}
37
\details{
36
\details{
38
  \code{assertCondition()} uses the general condition mechanism to
37
  \code{assertCondition()} uses the general condition mechanism to
39
  check all the conditions generated in evaluating \code{expr}.  The
38
  check all the conditions generated in evaluating \code{expr}.  The
40
  occurrence of any of the supplied condition classes among these satisfies the
39
  occurrence of any of the supplied condition classes among these satisfies the
Line 67... Line 66...
67
 
66
 
68
try( assertCondition(sqrt(2), "warning") )
67
try( assertCondition(sqrt(2), "warning") )
69
## .. Failed to get warning in evaluating sqrt(2)
68
## .. Failed to get warning in evaluating sqrt(2)
70
     assertCondition(sqrt("abc"), "error")   # ok
69
     assertCondition(sqrt("abc"), "error")   # ok
71
try( assertCondition(sqrt("abc"), "warning") )# -> error: had no warning
70
try( assertCondition(sqrt("abc"), "warning") )# -> error: had no warning
72
     assertCondition(sqrt("abc"), "error") 
71
     assertCondition(sqrt("abc"), "error")
73
  ## identical to assertError() call above
72
  ## identical to assertError() call above
74
 
73
 
75
assertCondition(matrix(1:5, 2,3), "warning")
74
assertCondition(matrix(1:5, 2,3), "warning")
76
try( assertCondition(matrix(1:8, 4,3), "error") )
75
try( assertCondition(matrix(1:8, 4,3), "error") )
77
## .. Failed to get expected error ....
76
## .. Failed to get expected error ....
78
 
77
 
79
## either warning or worse:
78
## either warning or worse:
80
assertCondition(matrix(1:8, 4,3), "error","warning") # OK
79
assertCondition(matrix(1:8, 4,3), "error","warning") # OK
81
assertCondition(matrix(1:8, 4, 3), "warning") # OK 
80
assertCondition(matrix(1:8, 4, 3), "warning") # OK
82
 
81
 
83
## when both are signalled:
82
## when both are signalled:
84
ff <- function() { warning("my warning"); stop("my error") }
83
ff <- function() { warning("my warning"); stop("my error") }
85
    assertCondition(ff(), "warning")
84
    assertCondition(ff(), "warning")
86
## but assertWarning does not allow an error to follow
85
## but assertWarning does not allow an error to follow