Create an instance of the Dice S4 class, allowing for the use of non-standard dice and for interactive dice rolling without having to recur to functions of the roll family. See below for more details.

d(faces)

Arguments

faces

Either the number of faces (length(faces) == 1) or a numeric vector specifying the values of the faces.

Value

An object of the Dice S4 class.

Details

If given a numeric vector, d() creates an object of the Dice S4 class representing a die with these values for faces. On the other hand, if given a numeric scalar, it creates a die with faces running from 1 to this value. At the moment, there is no support for specifying each face's probability, although it is possible to create a die where more than one face have the same value.

This function has two main purposes: creating non-standard dice and allowing for interactive dice rolling. Non-standard dice are arbitrary objects that might not have a real world counterpart, e.g., a d(17) or a d(c(1, 1, 3)). Interactive rolling is the ability to get a random result from a die without having to resort to functions of the roll family, explained in detail in the documentation for the Dice S4 class.

See also

Examples

# Create a d6 d6 <- d(6) d6
#> # A die with faces: #> [1] 1 2 3 4 5 6
# Create a die with even faces dEven <- d(c(2, 4, 6)) dEven
#> # A die with faces: #> [1] 2 4 6
# Create a loaded die dLoaded <- d(c(1:6, 6)) dLoaded
#> # A die with faces: #> [1] 1 2 3 4 5 6 6