File: throw.R

package info (click to toggle)
r-cran-r.methodss3 1.8.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 300 kB
  • sloc: sh: 12; makefile: 2
file content (19 lines) | stat: -rw-r--r-- 355 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
library("R.methodsS3")

message("TESTING: throw()...")

rbern <- function(n=1, prob=1/2) {
  if (prob < 0 || prob > 1)
    throw("Argument 'prob' is out of range: ", prob)
  rbinom(n=n, size=1, prob=prob)
}

rbern(10, 0.4)
# [1] 0 1 0 0 0 1 0 0 1 0
tryCatch({
  rbern(10, 10*0.4)
}, error=function(ex) {
  print(ex)
})

message("TESTING: throw()...DONE")