Flexible state machine builder and associated tools for R. The aim is to evolve the package publicly for the next few months then release it to CRAN.
The aim of the package is two fold:
Make it easy to definite state machines over standard R functions - Very valuable when you're trying to express and maintain complicated workflows.
Introduce guard functions and function overloading - Makes it possible to create many variants of the same function, that only runs when certain conditions are met . E.g. define {function} as {definition} when {constrains when it's applicable}
Package exposes seven functions which together expose enough functionality to define and parameterise a state machine:
INIT(parallel, logErrorFUN, logInfoFUN) - starts the definition of the execution of one or more automata. parallel doesnt do anything right now. the log*FUN functions specify what functions to use for logging.
BEGIN_AUTOMATA(name, startAt, log) - Begins the definition of an automata and sets various key variables. startAt defines which state to start from, log whether to log or not.
END_AUTOMATA() - Ends the definition of an automata. takes no arguments.
VAR(name, value) - add a variable to the definition. Will be available from state at run time. key value arguments.
STATE(name, as, when, failOnError) - add a state. as defines the state body to be used when the boolean function evaluates to true. both functions take one argument (state). State name serves as the key. State name can be overloaded with many definitions. First one where when evaluates to true is used. failOnError will mean the whole automata terminates on error.
TRANSITION(from, to, when, onError) - add a transition between states. Similar to above can be overloaded. when function decides whether the transition will be used. Only one transition applies per turn; first one to evaluate to true in order of definition. On error will mean the definition (including the when clause) will only apply when an error occurs.
EXEC - Executes the automata.
The functions are joint together using the magrittr notation. E.g.
INIT %>%
BEGIN_AUTOMATA("My Automata #1", start="goState") %>%
VAR("some setting", F) %>%
VAR("some other setting",T) %>%
STATE("goState", as=function(state) {print("Whoooo!");state}, when=function(state)T) %>%
STATE("delay", as=function(state){Sys.sleep(1);state}, when=function(state)T) %>%
STATE("end", as=function(state){print("fin.");state}, when=function(state)T) %>%
TRANSITION("goState","delay", when=function(state)T) %>%
TRANSITION("delay","end", when=function(state)T) %>%
TRANSITION("end","goState", when=function(state)T) %>%
END_AUTOMATA %>%
BEGIN_AUTOMATA("My Automata #2", start="start") %>%
...etc...
END_AUTOMATA %>%
EXEC
One can execute as many automata as one wishes at the same time. Automata may run temporarily or forever.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.