Parse a custom string that represents an R6 distribution

dparse(toparse)

Arguments

toparse

(character(1))
String to parse, which should be in the format Distribution([params]), see examples.

Value

Returns an R6 Distribution

Details

Transform a custom (user) input to a R6 object.

This function is specially useful when you expect a user input which should result in specific distribution. The distribution name must be the ShortName, ClassName or Alias listed in the package, which can be found with listDistributions().

Examples

dparse("N()")
#> Norm(mean = 0, var = 1) 
dparse("norm(0, sd = 2)")
#> Norm(mean = 0, sd = 2) 
# lower and upper case work
dparse("n(sd = 1, mean = 4)")
#> Norm(mean = 4, sd = 1) 
dparse("T(df = 4)")
#> T(df = 4) 
dparse("cHiSq(df = 3)")
#> ChiSq(df = 3) 
# be careful to escape strings properly
dparse("C(list('A', 'B'), c(0.5, 0.5))")
#> Cat(elements = list("a", "b"), probs = c(0.5, 0.5)) 
dparse("Cat(elements = c('A', 'B'), probs = c(0.5, 0.5))")
#> Cat(elements = c("a", "b"), probs = c(0.5, 0.5))