| Type: | Package |
| Title: | Process Models in the Plain-Text Language 'tok' |
| Version: | 1.0.3 |
| Description: | Reads, checks, formats and exports process models written in 'tok', a plain-text language for Business Process Model and Notation (BPMN) 2.0 processes with their Decision Model and Notation (DMN) decisions, 'Camunda' forms and simulation parameters. Models are checked against the rules of BPMN 2.0, with diagnostics in English or Polish, and exported to BPMN files with a diagram layout, Scalable Vector Graphics (SVG) pictures, DMN and form files; they are drawn in the viewer and in 'R Markdown' and 'Quarto' documents through a 'knitr' engine. Processes are simulated as discrete-event models, giving indicators, an event log for process mining and a table of cases. The work is done by the 'Rust' engine of 'tok', shared with its 'Python' package and command line tool. |
| License: | GPL (≥ 3) |
| URL: | https://tok-lang-bpm.github.io/, https://github.com/tok-lang-bpm/tok |
| BugReports: | https://github.com/tok-lang-bpm/tok/issues |
| Encoding: | UTF-8 |
| Depends: | R (≥ 4.2) |
| Suggests: | knitr, rmarkdown, testthat (≥ 3.0.0) |
| Config/testthat/edition: | 3 |
| SystemRequirements: | Cargo (Rust's package manager), rustc >= 1.88 |
| RoxygenNote: | 8.0.0 |
| Copyright: | Marek Deja; the authors of the bundled Rust crates listed in inst/AUTHORS. |
| NeedsCompilation: | yes |
| Packaged: | 2026-10-31 14:59:24 UTC; dejam |
| Author: | Marek Deja [aut, cre, cph] |
| Maintainer: | Marek Deja <marek.deja@uj.edu.pl> |
| Repository: | CRAN |
| Date/Publication: | 2026-11-26 16:20:02 UTC |
knitr engine for tok
Description
Loading the package registers the engine tok, so a chunk written as
```{tok} in R Markdown or Quarto holds a model. Chunk options:
Usage
eng_tok(options)
Arguments
options |
Chunk options, passed by knitr. |
Details
-
tok.output:"svg"(default) draws the diagram;"check"prints the diagnostics;"fmt"prints the canonical text;"bpmn"prints the BPMN XML. -
tok.title: title drawn above the diagram. -
tok.lang: language of the messages (default: the optiontok.lang, then"en"). -
tok.export: a directory; every file oftok exportis also written there.
The diagram is written as an SVG file and included like a figure (fig.cap and the
other figure options apply), which suits HTML output; for PDF output use
tok.output = "check" or include an exported picture.
Value
The chunk output, for knitr.
Examples
# the engine is registered when the package is loaded
if (requireNamespace("knitr", quietly = TRUE)) {
is.function(knitr::knit_engines$get("tok"))
}
BPMN 2.0 XML and SVG of a model
Description
tok_bpmn() exports BPMN 2.0 XML with diagram layout, which opens in Camunda Modeler
and bpmn.io; tok_svg() draws the diagram. Both stop with the list of errors when the
model has errors (see tok_check()).
Usage
tok_bpmn(x, file = NULL, lang = getOption("tok.lang", "en"))
tok_svg(x, file = NULL, title = NULL, lang = getOption("tok.lang", "en"))
Arguments
x |
A model: a |
file |
Optional path to write to. |
lang |
Language of the messages, |
title |
Title drawn above the diagram (SVG only). |
Value
The XML or SVG text; invisibly when written to file.
Examples
model <- system.file("examples", "wypozyczenie.tok", package = "tokr")
xml <- tok_bpmn(model)
substr(xml, 1, 120)
svg <- tok_svg(model, title = "Interlibrary loan")
nchar(svg)
Check a model
Description
Runs the checks of tok check: syntax, identifiers, flows, pools and lanes, decision
tables, forms, simulation parameters and the BPMN 2.0 rules.
Usage
tok_check(
x,
lang = getOption("tok.lang", "en"),
level = c("full", "analytic", "basic"),
bpmn = TRUE
)
Arguments
x |
A model: a |
lang |
Language of the messages, |
level |
|
bpmn |
Whether to run the BPMN 2.0 rules on the exported model. |
Value
A data frame of class tok_diagnostics with the columns line, code,
severity ("error", "warning" or "note"), id and message, one row per
problem; no rows when the model has no problems.
Examples
tok_check('tok 0.3 "Example"
start s "Start"
task a "Work"
end e "End"
flow s -> a -> e')
Evaluate a decision
Description
Evaluates a decision of the model for the given inputs, as tok eval does. In a
model of language 0.7 the decision is evaluated with the decisions, input data and
business knowledge models it requires, and the inputs are the input data by FEEL
name; in earlier models the decision table alone is evaluated with the hit policy of
the table.
Usage
tok_eval(x, decision, inputs = list(), lang = getOption("tok.lang", "en"))
Arguments
x |
A model: a |
decision |
Identifier of the decision. |
inputs |
Named list of inputs: numbers, strings, logical values, |
lang |
Language of the messages, |
Value
In a model of language 0.7 the value of the decision (a number, string,
logical value, list or named list; NULL for null), a list of named lists as a data
frame. In earlier models: for the hit policies unique, first, any and
priority a named list output name → value (NULL when no rule matches); for
collect a data frame with one row per matched rule.
Examples
f <- system.file("examples", "propozycja-zakupu.tok", package = "tokr")
tok_eval(f, "tryb-akceptacji", list(rodzaj = "drukowana", cena = 120))
Export every file of a model
Description
Writes what tok export writes: NAME.bpmn, NAME.svg, one .dmn file per decision
table and one .form file per form, ready to deploy to Camunda 8.
Usage
tok_export(x, dir = ".", name = NULL, lang = getOption("tok.lang", "en"))
Arguments
x |
A model: a |
dir |
Output directory, created when missing. |
name |
Base name of the BPMN and SVG files; by default the name of the |
lang |
Language of the messages, |
Value
The paths of the written files, invisibly.
Examples
out <- file.path(tempdir(), "tok-export")
files <- tok_export(system.file("examples", "propozycja-zakupu.tok", package = "tokr"),
dir = out)
basename(files)
unlink(out, recursive = TRUE)
Canonical text of a model
Description
Prints the model as tok fmt does: one statement per line, canonical order of
attributes, comments kept.
Usage
tok_fmt(x, write = FALSE, lang = getOption("tok.lang", "en"))
Arguments
x |
A model: a |
write |
When |
lang |
Language of the messages, |
Value
The canonical text (invisibly when the file is rewritten).
Examples
tok_fmt(system.file("examples", "wypozyczenie.tok", package = "tokr"))
Convert BPMN 2.0 to tok
Description
Reads a BPMN 2.0 file (for example drawn in Camunda Modeler) and returns the model as tok
text, as tok import does.
Usage
tok_import(file, keep_ids = TRUE)
Arguments
file |
Path of a |
keep_ids |
Keep the identifiers of the BPMN file; |
Value
A tok_model; warnings about elements tok does not keep are in its element
warnings and are also signalled.
Examples
bpmn <- tempfile(fileext = ".bpmn")
tok_bpmn(system.file("examples", "wypozyczenie.tok", package = "tokr"), file = bpmn)
m <- tok_import(bpmn)
m
unlink(bpmn)
Draw a model
Description
Shows the diagram in the RStudio or Positron viewer, or in the web browser.
Usage
tok_plot(x, title = NULL, lang = getOption("tok.lang", "en"))
Arguments
x |
A model: a |
title |
Title drawn above the diagram (SVG only). |
lang |
Language of the messages, |
Value
The path of the temporary SVG file, invisibly.
Examples
if (interactive()) {
tok_plot(system.file("examples", "wypozyczenie.tok", package = "tokr"))
}
Read a tok model
Description
Reads a .tok file. The result can be passed to every other function of the package;
they also accept the path of a .tok file or the text of a model directly.
Usage
tok_read(path)
Arguments
path |
Path of a |
Value
An object of class tok_model: a list with the elements text, path and
name (the file name without the extension).
Examples
m <- tok_read(system.file("examples", "wypozyczenie.tok", package = "tokr"))
m
Simulate a process
Description
Runs the discrete-event simulation of tok sim: cases arrive, wait for the resources
of by=, take the durations of duration= and choose flows by their conditions and
probabilities, as the simulate, resource and variable statements of the model
say. The same model and seed always give the same result, number by number the result
of tok sim and of the Python package.
Usage
tok_sim(x, cases = NULL, seed = NULL, lang = getOption("tok.lang", "en"))
Arguments
x |
A model: a |
cases |
Number of cases; |
seed |
Seed of the random number generator; |
lang |
Language of the messages, |
Details
Times of the simulation are calendar times counted from start= of simulate. In the
event log and the table of cases they are POSIXct values in UTC; a start= without a
UTC offset is taken as UTC, so the clock times are those of tok sim --log.
The event log has one row per activity instance, as tok sim --log writes it: the
columns case, activity (identifier), label, resource ("" when the activity has
no by=), enqueue (when the case reached the activity), start (when a performer
started the work; NA when the activity was interrupted while waiting), end (when it
completed or was interrupted) and status ("completed" or "interrupted"). The
columns case_id, activity_id (the label, or the identifier when the activity has no
label), activity_instance_id (the row number), resource_id (NA when none),
schedule (= enqueue) and complete (= end of completed instances, NA for
interrupted ones) repeat them under the names process-mining packages expect. For
example, with bupaR:
bupaR::activitylog(s$log, case_id = "case_id", activity_id = "activity_id",
resource_id = "resource_id",
timestamps = c("schedule", "start", "complete"))
Value
An object of class tok_sim, a list with the elements:
-
kpi: the indicators oftok sim --json, a list withseed;cases(a list ofstarted,finishedandby_end_event, a named integer vector of finished cases per end event);cycle_time(a list ofmean_s,median_sandp90_sin seconds,NAwithout finished cases, and the same as short textsmean,median,p90);activities, a data frame with one row per activity (activity,label,countof completed instances,mean_wait_s,mean_processing_s,mean_wait,mean_processing);resources, a data frame with one row per resource (resource,label,count,utilizationas a fraction);horizon_s, the simulated period in seconds; andwarnings. -
log: the event log, a data frame described above. -
cases: a data frame with one row per case:case,start,end(NAfor an unfinished case),end_event(NAfor an unfinished case),cycle_time_s, and one column per case variable. A variable that holds a single value in every case is a vector (logical, numeric or character,NAwhere the case has no value; durations in seconds), any other a list; a variable named like one of the first five columns gets the prefixvariable_. -
warnings: conditions or expressions the simulator could not evaluate. -
seed: the seed used, as a number. -
horizon: the simulated period in seconds, from the first arrival to the last event. -
report: the text report oftok simin the languagelang, whichprint()shows.
The object also keeps the model, the number of cases and the seed of the run, so
tok_xes() can write its event log as XES.
as.data.frame() returns the event log. The function stops with the errors of the
model (see tok_check()) and with the errors of the simulator as tok sim reports
them, for example tok.sim.SimError: the process 'process' has no start event.
Examples
f <- system.file("examples", "kwerenda-symulacja.tok", package = "tokr")
s <- tok_sim(f)
s
s$kpi$resources
head(s$log)
table(tok_sim(f, cases = 50, seed = 3)$cases$end_event)
Version of the tok engine
Description
Version of the tok engine
Usage
tok_version()
Value
The version of the Rust engine compiled into the package.
Examples
tok_version()
XES event log of a simulation
Description
Writes the event log of tok_sim() as an XES document (IEEE 1849-2016, eXtensible
Event Stream), the exchange format of process-mining tools such as ProM, pm4py,
bupaR, Disco and Celonis; it is the file of tok sim --xes.
Usage
tok_xes(
x,
file = NULL,
cases = NULL,
seed = NULL,
lang = getOption("tok.lang", "en")
)
Arguments
x |
A result of |
file |
Optional path to write to. |
cases, seed |
As in |
lang |
Language of the messages, |
Details
The log has one trace per case and up to three events per activity instance, with the
transitions of the standard lifecycle model: schedule when the case reached the
activity, start when a performer started the work and complete when it completed;
an instance interrupted by a boundary timer ends with ati_abort when it was running
and with withdraw when it was still waiting for a performer. Events carry
concept:name (the label of the activity), concept:instance, org:resource,
time:timestamp (with milliseconds and the UTC offset of start= of simulate) and
activity (the identifier). Traces carry the case number, start, end,
end_event, cycle_time_s and the case variables as typed attributes. See
docs/simulation.md in the repository for the details.
Value
The XES text; invisibly when written to file.
Examples
f <- system.file("examples", "kwerenda-symulacja.tok", package = "tokr")
s <- tok_sim(f, cases = 20)
xes <- tempfile(fileext = ".xes")
tok_xes(s, xes)
substr(tok_xes(f, cases = 2, seed = 7), 1, 200)