Title: | Human and Machine-Readable Justifications and Justified Decisions Based on 'YAML' |
---|---|
Description: | Leverages the 'yum' package to implement a 'YAML' ('YAML Ain't Markup Language', a human friendly standard for data serialization; see <https:yaml.org>) standard for documenting justifications, such as for decisions taken during the planning, execution and analysis of a study or during the development of a behavior change intervention as illustrated by Marques & Peters (2019) <doi:10.17605/osf.io/ndxha>. These justifications are both human- and machine-readable, facilitating efficient extraction and organisation. |
Authors: | Gjalt-Jorn Peters [aut, cre] , Szilvia Zorgo [ctb] |
Maintainer: | Gjalt-Jorn Peters <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.2.6 |
Built: | 2024-12-25 06:54:03 UTC |
Source: | CRAN |
Apply multiple DiagrammeR global graph attributes
apply_graph_theme(graph, ...)
apply_graph_theme(graph, ...)
graph |
The DiagrammeR::DiagrammeR graph to apply the attributes to. |
... |
One or more character vectors of length three, where the first element is
the attribute, the second the value, and the third, the attribute type ( |
The DiagrammeR::DiagrammeR graph.
exampleJustifier <- ' --- assertion: - id: assertion_id label: "An assertion" decision: - id: decision_id label: "A decision" justification: - id: justification_id label: "A justification" assertion: - id: assertion_id description: "A description of an assertion" source: - id: source1_id label: "First source" - id: source2_id label: "second source" --- '; justifications <- justifier::load_justifications(text=exampleJustifier); miniGraph_original <- justifications$decisionGraphs[[1]]; miniGraph <- justifier::apply_graph_theme( miniGraph_original, c("color", "#0000AA", "node"), c("shape", "triangle", "node"), c("fontcolor", "#FF0000", "node") ); ### This line shouldn't be run when executing this example as test, ### because rendering a DiagrammeR graph takes quite long ## Not run: DiagrammeR::render_graph(miniGraph); ## End(Not run)
exampleJustifier <- ' --- assertion: - id: assertion_id label: "An assertion" decision: - id: decision_id label: "A decision" justification: - id: justification_id label: "A justification" assertion: - id: assertion_id description: "A description of an assertion" source: - id: source1_id label: "First source" - id: source2_id label: "second source" --- '; justifications <- justifier::load_justifications(text=exampleJustifier); miniGraph_original <- justifications$decisionGraphs[[1]]; miniGraph <- justifier::apply_graph_theme( miniGraph_original, c("color", "#0000AA", "node"), c("shape", "triangle", "node"), c("fontcolor", "#FF0000", "node") ); ### This line shouldn't be run when executing this example as test, ### because rendering a DiagrammeR graph takes quite long ## Not run: DiagrammeR::render_graph(miniGraph); ## End(Not run)
The conversion functions from base10 to base30 are
used by the generate_id()
functions; the base36
functions are just left here for convenience.
base30toNumeric(x) numericToBase30(x)
base30toNumeric(x) numericToBase30(x)
x |
The vector to convert (numeric for the |
The symbols to represent the 'base 30' system are the 0-9
followed by the alphabet without vowels but including the y. This
vector is available as base30
.
The converted vector (numeric for the base30to
and base36to
funtions,
character for the numericTo
functions).
numericToBase30(654321); base30toNumeric(numericToBase30(654321));
numericToBase30(654321); base30toNumeric(numericToBase30(654321));
These functions can be used to programmatically construct justifications.
## S3 method for class 'justifierElement' c(...) ## S3 method for class 'justifierStructured' c(...) source(label, description = NULL, type = NULL, id = NULL, xdoi = NULL, ...) assert(label, description = "", type = NULL, id = NULL, source = NULL, ...) justify(label, description = "", type = NULL, id = NULL, assertion = NULL, ...) decide( label, description = NULL, type = NULL, id = NULL, alternatives = NULL, justification = NULL, ... )
## S3 method for class 'justifierElement' c(...) ## S3 method for class 'justifierStructured' c(...) source(label, description = NULL, type = NULL, id = NULL, xdoi = NULL, ...) assert(label, description = "", type = NULL, id = NULL, source = NULL, ...) justify(label, description = "", type = NULL, id = NULL, assertion = NULL, ...) decide( label, description = NULL, type = NULL, id = NULL, alternatives = NULL, justification = NULL, ... )
... |
Additional fields and values to store in the element. |
label |
A human-readable label for the |
description |
A human-readable description. This can be used to elaborate on the label. Note that the label should be reader-friendly and self-contained; but because they also have to be as short as possible, descriptions can be used to provide definitions, context, background information, or add any other metadata or comments. |
type |
Types are used when working with a framework. Frameworks define type identifiers, consisting of letters, digits, and underscores. By specifying these identifiers the type of a decision, justification, assertion, or source. Source types can be, for example, types of documents or other data providers, such as "empirical evidence', 'expert consensus', 'personal opinion', or 'that one meeting that we had in May'. Assertion types can be, for example, data types or types of facts, such as 'number', 'prevalence', 'causal relationship', or 'contact information'. Justification types can be, for example, types of reasoning or logical expressions, such as 'deduction', 'induction', or 'intersection'. Decision types are the most framework-specific, heavily depend on the specific context of the decision, and are used by frameworks to organise the decisions in a project. Examples of decision types are the decision to recruit a certain number of participants in a scientific study; the decision to target a certain belief in a behavior change intervention; the decision to merge two codes in a qualitative study; the decision to hire a staff member; or the decision to make a certain purchase. |
id |
The identifier (randomly generated if omitted). |
xdoi |
For |
source |
In assertions, the source (or sources) that the assertion
is based on can be specified using |
assertion |
In justifications, the assertion (or assertions) that
the justification is based on can be specified using |
alternatives |
The alternatives that were considered in a decision. |
justification |
In decisions, the justification (or justifications)
that the decision is based on can be specified using |
The generated object.
### Programmatically create a partial justification object justifierAssertion <- justifier::assert( "This is an assertion", source = c( justifier::source('This is a first source'), justifier::source('This is a second source'))); ### Programmatically create a justification with two assertions ### but without sources justifierJustification <- justifier::justify( "Icecream will make me feel less fit", assertion = c( justifier::assert('Icecream is rich in energy'), justifier::assert('Consuming high-energy foods makes me feel less fit') ), weight = -.5 ); ### Show it justifierJustification; ### Programmatically create a simple decision simpleDecision <- justifier::decide( "decision", justification = justifier::jstf( "justification", assertion = justifierAssertion ) ); ### Programmatically create a justification object for a full decision fullJustifierObject <- justifier::decide( "I decide to go get an icecream", justification = c( justifier::justify( "Having an icecream now would make me happy", assertion = c( justifier::assert( "Decreasing hunger increases happiness", source = justifier::source( "My past experiences" ) ), justifier::assert( "I feel hungry", source = justifier::source( "Bodily sensations" ) ) ), weight = 1 ), justifierJustification, justifier::justify( "I can afford to buy an icecream.", assertion = c( justifier::assert( "My bank account balance is over 300 euro.", source = justifier::source( "My bank app" ) ), justifier::assert( "I need to keep at least 100 euro in my bank account.", source = justifier::source( "Parental advice" ) ) ), weight = .3 ) ) ); ### Show the full object fullJustifierObject; ### Combine both into a list of decisions twoDecisions <- c(simpleDecision, fullJustifierObject); ### Show the combination twoDecisions;
### Programmatically create a partial justification object justifierAssertion <- justifier::assert( "This is an assertion", source = c( justifier::source('This is a first source'), justifier::source('This is a second source'))); ### Programmatically create a justification with two assertions ### but without sources justifierJustification <- justifier::justify( "Icecream will make me feel less fit", assertion = c( justifier::assert('Icecream is rich in energy'), justifier::assert('Consuming high-energy foods makes me feel less fit') ), weight = -.5 ); ### Show it justifierJustification; ### Programmatically create a simple decision simpleDecision <- justifier::decide( "decision", justification = justifier::jstf( "justification", assertion = justifierAssertion ) ); ### Programmatically create a justification object for a full decision fullJustifierObject <- justifier::decide( "I decide to go get an icecream", justification = c( justifier::justify( "Having an icecream now would make me happy", assertion = c( justifier::assert( "Decreasing hunger increases happiness", source = justifier::source( "My past experiences" ) ), justifier::assert( "I feel hungry", source = justifier::source( "Bodily sensations" ) ) ), weight = 1 ), justifierJustification, justifier::justify( "I can afford to buy an icecream.", assertion = c( justifier::assert( "My bank account balance is over 300 euro.", source = justifier::source( "My bank app" ) ), justifier::assert( "I need to keep at least 100 euro in my bank account.", source = justifier::source( "Parental advice" ) ) ), weight = .3 ) ) ); ### Show the full object fullJustifierObject; ### Combine both into a list of decisions twoDecisions <- c(simpleDecision, fullJustifierObject); ### Show the combination twoDecisions;
Concatenate two or more structured justifier objects
## S3 method for class 'justifierStructuredObject' c(...)
## S3 method for class 'justifierStructuredObject' c(...)
... |
Structured justifier objects |
Invisibly, the concatenated list
The cat0 function is to cat what paste0 is to paste; it simply makes concatenating many strings without a separator easier.
cat0(..., sep = "")
cat0(..., sep = "")
... |
The character vector(s) to print; passed to cat. |
sep |
The separator to pass to cat, of course, |
Nothing (invisible NULL
, like cat).
cat0("The first variable is '", names(mtcars)[1], "'.");
cat0("The first variable is '", names(mtcars)[1], "'.");
Clean your workspace
clean_workspace(force = FALSE, silent = justifier::opts$get("silent"))
clean_workspace(force = FALSE, silent = justifier::opts$get("silent"))
force |
Whether to force cleaning the workspace |
silent |
Whether to be chatty or silent. |
### Without `force=TRUE`, presents a query to the user in ### interactive mode: clean_workspace(silent=FALSE); ### Set `force=TRUE` to force clean the workspace clean_workspace(force = TRUE, silent=FALSE);
### Without `force=TRUE`, presents a query to the user in ### interactive mode: clean_workspace(silent=FALSE); ### Set `force=TRUE` to force clean the workspace clean_workspace(force = TRUE, silent=FALSE);
Export justification as YAML
export_justification( x, file = NULL, encoding = "UTF-8", append = TRUE, preventOverwriting = TRUE, silent = justifier::opts$get("silent") )
export_justification( x, file = NULL, encoding = "UTF-8", append = TRUE, preventOverwriting = TRUE, silent = justifier::opts$get("silent") )
x |
The justification, either loaded from one or more files or programmatically constructed. This can be one or more decisions, justifications, assertions, or sources. |
file |
If specified, the file to export the justification to. |
encoding |
The encoding to use when writing the file. |
append |
Whether to append to the file, or replace its contents. |
preventOverwriting |
Whether to prevent overwriting an existing file. |
silent |
Whether to be silent or chatty. |
The generated YAML, invisibly, unless file is NULL.
### Programmatically create a simple justification object justifierObject <- justifier::asrt( "assertion", source = c( justifier::srce('source1'), justifier::srce('source2'))); ### Export to YAML justifierYAML <- justifier::export_justification( justifierObject, file=NULL); ### Show YAML cat(justifierYAML, sep="\n");
### Programmatically create a simple justification object justifierObject <- justifier::asrt( "assertion", source = c( justifier::srce('source1'), justifier::srce('source2'))); ### Export to YAML justifierYAML <- justifier::export_justification( justifierObject, file=NULL); ### Show YAML cat(justifierYAML, sep="\n");
Export a justifier specification to JSON
export_to_json(x, file = NULL, wrap_in_html = FALSE) ## S3 method for class 'justifierStructuredObject' export_to_json(x, file = NULL, wrap_in_html = FALSE) ## S3 method for class 'justifier_json' print(x, ...)
export_to_json(x, file = NULL, wrap_in_html = FALSE) ## S3 method for class 'justifierStructuredObject' export_to_json(x, file = NULL, wrap_in_html = FALSE) ## S3 method for class 'justifier_json' print(x, ...)
x |
The justifier specification. |
file |
Optionally, a file to save the JSON to. |
wrap_in_html |
Whether to wrap the JSON in an HTML element. |
... |
Any additional arguments are ignored. |
If a file is specified to write, to, x
will be returned invisibly
to allow building a pipe chain; if file=NULL
, the resulting JSON
will be returned as a character vector.
### Programmatically create a justification with two assertions ### but without sources; flatten it; and show the json justifier::justify( "Icecream will make me feel less fit", assertion = c( justifier::assert('Icecream is rich in energy'), justifier::assert('Consuming high-energy foods makes me feel less fit') ), weight = -.5 ) |> justifier::flatten() |> justifier::export_to_json();
### Programmatically create a justification with two assertions ### but without sources; flatten it; and show the json justifier::justify( "Icecream will make me feel less fit", assertion = c( justifier::assert('Icecream is rich in energy'), justifier::assert('Consuming high-energy foods makes me feel less fit') ), weight = -.5 ) |> justifier::flatten() |> justifier::export_to_json();
Flattening takes all justifications, assertions, and sources from their parents and returns a structured justifier object containing these elements in separate lists, with each occurrence replaced with a reference to the corresponding identifier.
flatten(x, ..., recursionLevel = 0, silent = justifier::opts$get("silent")) ## S3 method for class 'multipleJustifierElements' flatten(x, ..., recursionLevel = 0, silent = justifier::opts$get("silent")) ## S3 method for class 'singleJustifierElement' flatten(x, ..., recursionLevel = 0, silent = justifier::opts$get("silent"))
flatten(x, ..., recursionLevel = 0, silent = justifier::opts$get("silent")) ## S3 method for class 'multipleJustifierElements' flatten(x, ..., recursionLevel = 0, silent = justifier::opts$get("silent")) ## S3 method for class 'singleJustifierElement' flatten(x, ..., recursionLevel = 0, silent = justifier::opts$get("silent"))
x |
The justifier object or objects. |
... |
Additional arguments are passed to the methods. |
recursionLevel |
The depth of the recursion |
silent |
Whether to be silent or chatty |
A flattened justifier object.
### Programmatically create a justification with two assertions ### but without sources justifierJustification <- justifier::justify( "Icecream will make me feel less fit", assertion = c( justifier::assert('Icecream is rich in energy'), justifier::assert('Consuming high-energy foods makes me feel less fit') ), weight = -.5 ); ### Flatten it into a structures justifier object structuredJustification <- justifier::flatten( justifierJustification ); ### Check it str(structuredJustification, 1);
### Programmatically create a justification with two assertions ### but without sources justifierJustification <- justifier::justify( "Icecream will make me feel less fit", assertion = c( justifier::assert('Icecream is rich in energy'), justifier::assert('Consuming high-energy foods makes me feel less fit') ), weight = -.5 ); ### Flatten it into a structures justifier object structuredJustification <- justifier::flatten( justifierJustification ); ### Check it str(structuredJustification, 1);
Convenience function to generate a unique identifiers for sources, assertions, justifications, and decisions.
generate_id( type, prefix = paste(sample(letters, 4), collapse = ""), stopOnIllegalChars = FALSE )
generate_id( type, prefix = paste(sample(letters, 4), collapse = ""), stopOnIllegalChars = FALSE )
type |
The type of the justifier object; |
prefix |
An identifier prefix. |
stopOnIllegalChars |
Whether to |
A character vector containing the identifier(s).
generate_id(type = "S", 'sourceExample'); generate_id(type = "A", 'assertionExample');
generate_id(type = "S", 'sourceExample'); generate_id(type = "A", 'assertionExample');
This is used to be able to log decisions programmatically.
get_workspace(silent = justifier::opts$get("silent"))
get_workspace(silent = justifier::opts$get("silent"))
silent |
Whether to be suppress messages. |
Invisibly, the workspace identifier.
justifier::get_workspace_id();
justifier::get_workspace_id();
This is used to be able to log decisions programmatically.
get_workspace_id(silent = justifier::opts$get("silent"))
get_workspace_id(silent = justifier::opts$get("silent"))
silent |
Whether to be suppress messages. |
Invisibly, the workspace identifier.
justifier::get_workspace_id();
justifier::get_workspace_id();
Create a reference to one or more justifier objects
idRef(x, what = NULL, silent = justifier::opts$get("silent")) ## S3 method for class 'singleJustifierElement' idRef(x, what = NULL, silent = justifier::opts$get("silent")) ## S3 method for class 'multipleJustifierElements' idRef(x, what = NULL, silent = justifier::opts$get("silent")) ## S3 method for class 'justifierIdRef' idRef(x, what = NULL, silent = justifier::opts$get("silent")) ## S3 method for class 'character' idRef(x, what = NULL, silent = justifier::opts$get("silent")) ## S3 method for class 'justifierStructured' idRef(x, what = NULL, silent = justifier::opts$get("silent"))
idRef(x, what = NULL, silent = justifier::opts$get("silent")) ## S3 method for class 'singleJustifierElement' idRef(x, what = NULL, silent = justifier::opts$get("silent")) ## S3 method for class 'multipleJustifierElements' idRef(x, what = NULL, silent = justifier::opts$get("silent")) ## S3 method for class 'justifierIdRef' idRef(x, what = NULL, silent = justifier::opts$get("silent")) ## S3 method for class 'character' idRef(x, what = NULL, silent = justifier::opts$get("silent")) ## S3 method for class 'justifierStructured' idRef(x, what = NULL, silent = justifier::opts$get("silent"))
x |
The identifier(s) |
what |
Optionally, what |
silent |
Whether to be silent or chatty. |
The justifier id reference object.
exampleSource <- justifier::source("This is a book about R."); exampleAssertion <- justifier::assert( "R is a functional language", source = justifier::idRef(exampleSource) ); ### Get and show the reference (sourceId <- exampleAssertion$source); sourceId <- as.character(sourceId); ### Manually assign an identifier justifier::idRef(sourceId); ### Repeat while specifying what we're passing justifier::idRef(sourceId, what="source");
exampleSource <- justifier::source("This is a book about R."); exampleAssertion <- justifier::assert( "R is a functional language", source = justifier::idRef(exampleSource) ); ### Get and show the reference (sourceId <- exampleAssertion$source); sourceId <- as.character(sourceId); ### Manually assign an identifier justifier::idRef(sourceId); ### Repeat while specifying what we're passing justifier::idRef(sourceId, what="source");
The ifelseObj function just evaluates a condition, returning one object if it's true, and another if it's false.
ifelseObj(condition, ifTrue, ifFalse)
ifelseObj(condition, ifTrue, ifFalse)
condition |
Condition to evaluate. |
ifTrue |
Object to return if the condition is true. |
ifFalse |
Object to return if the condition is false. |
One of the two objects
dat <- ifelseObj(sample(c(TRUE, FALSE), 1), mtcars, Orange);
dat <- ifelseObj(sample(c(TRUE, FALSE), 1), mtcars, Orange);
Import a structured justifier object from JSON
import_from_json(x)
import_from_json(x)
x |
Either a path to an existing file, or a character vector with the JSON to import. |
The justifier object.
### Programmatically create a justification with two assertions ### but without sources; flatten it; and show the json justifier::justify( "Icecream will make me feel less fit", assertion = c( justifier::assert('Icecream is rich in energy'), justifier::assert('Consuming high-energy foods makes me feel less fit') ), weight = -.5 ) |> justifier::flatten() -> originalObject; originalObject |> justifier::export_to_json() -> exportedJSON; ### And import it again importedFromJSON <- justifier::import_from_json( exportedJSON );
### Programmatically create a justification with two assertions ### but without sources; flatten it; and show the json justifier::justify( "Icecream will make me feel less fit", assertion = c( justifier::assert('Icecream is rich in energy'), justifier::assert('Consuming high-energy foods makes me feel less fit') ), weight = -.5 ) |> justifier::flatten() -> originalObject; originalObject |> justifier::export_to_json() -> exportedJSON; ### And import it again importedFromJSON <- justifier::import_from_json( exportedJSON );
These function load justifications from the YAML fragments
in one (load_justifications
) or multiple files (load_justifications_dir
).
load_justifications( text = NULL, file = NULL, delimiterRegEx = "^---$", justificationContainer = c("justifier", "justification", "decision", "assertion", "source"), ignoreOddDelimiters = FALSE, encoding = "UTF-8", storeDecisionGraphSvg = TRUE, silent = TRUE ) load_justifications_dir( path, recursive = TRUE, extension = "jmd", regex = NULL, justificationContainer = c("justifier", "justification", "decision", "assertion", "source"), delimiterRegEx = "^---$", ignoreOddDelimiters = FALSE, encoding = "UTF-8", silent = TRUE )
load_justifications( text = NULL, file = NULL, delimiterRegEx = "^---$", justificationContainer = c("justifier", "justification", "decision", "assertion", "source"), ignoreOddDelimiters = FALSE, encoding = "UTF-8", storeDecisionGraphSvg = TRUE, silent = TRUE ) load_justifications_dir( path, recursive = TRUE, extension = "jmd", regex = NULL, justificationContainer = c("justifier", "justification", "decision", "assertion", "source"), delimiterRegEx = "^---$", ignoreOddDelimiters = FALSE, encoding = "UTF-8", silent = TRUE )
text , file
|
As |
delimiterRegEx |
The regular expression used to locate YAML fragments |
justificationContainer |
The container of the justifications in the YAML fragments. Because only justifications are read that are stored in this container, the files can contain YAML fragments with other data, too, without interfering with the parsing of the justifications. |
ignoreOddDelimiters |
Whether to throw an error (FALSE) or delete the last delimiter (TRUE) if an odd number of delimiters is encountered. |
encoding |
The encoding to use when calling |
storeDecisionGraphSvg |
Whether to also produce (and return) the SVG for the decision graph. |
silent |
Whether to be silent (TRUE) or informative (FALSE). |
path |
The path containing the files to read. |
recursive |
Whether to also process subdirectories ( |
extension |
The extension of the files to read; files with other extensions will
be ignored. Multiple extensions can be separated by a pipe ( |
regex |
Instead of specifing an extension, it's also possible to specify a regular
expression; only files matching this regular expression are read. If specified, |
load_justifications_dir
simply identifies all files and then calls
load_justifications
for each of them. load_justifications
loads the
YAML fragments containing the justifications using
yum::load_yaml_fragments()
and then parses the justifications
into a visual representation as a
ggplot2::ggplot graph and Markdown documents with
overviews.
An object with the ggplot2::ggplot graph stored
in output$graph
and the overview in output$overview
.
exampleMinutes <- 'This is an example of minutes that include a source, an assertion, and a justification. For example, in the meeting, we can discuss the assertion that sleep deprivation affects decision making. We could quickly enter this assertion in a machine-readable way in this manner: --- assertion: - id: assertion_SD_decision label: Sleep deprivation affects the decision making proces. source: id: source_Harrison --- Because it is important to refer to sources, we cite a source as well. We have maybe specified that source elsewhere, for example in the minutes of our last meeting. That specification may have looked like this: --- source: - id: source_Harrison label: "Harrison & Horne (2000) The impact of sleep deprivation on decision making: A review." xdoi: "doi:10.1037/1076-898x.6.3.236" type: "Journal article" --- We can now refer to these two specifications later on, for example to justify decisions we take. '; justifier::load_justifications(text=exampleMinutes); ### To load a directory with justifications examplePath <- file.path(system.file(package="justifier"), 'extdata'); justifier::load_justifications_dir(path=examplePath);
exampleMinutes <- 'This is an example of minutes that include a source, an assertion, and a justification. For example, in the meeting, we can discuss the assertion that sleep deprivation affects decision making. We could quickly enter this assertion in a machine-readable way in this manner: --- assertion: - id: assertion_SD_decision label: Sleep deprivation affects the decision making proces. source: id: source_Harrison --- Because it is important to refer to sources, we cite a source as well. We have maybe specified that source elsewhere, for example in the minutes of our last meeting. That specification may have looked like this: --- source: - id: source_Harrison label: "Harrison & Horne (2000) The impact of sleep deprivation on decision making: A review." xdoi: "doi:10.1037/1076-898x.6.3.236" type: "Journal article" --- We can now refer to these two specifications later on, for example to justify decisions we take. '; justifier::load_justifications(text=exampleMinutes); ### To load a directory with justifications examplePath <- file.path(system.file(package="justifier"), 'extdata'); justifier::load_justifications_dir(path=examplePath);
Used to programmatically document decisions - note that you have to store them to a file to not lose them (i.e. if used interactively).
log_decision( label, description = "", alternatives = "", date = as.character(Sys.Date()), id = NULL, justification = "", silent = justifier::opts$get("silent"), ... )
log_decision( label, description = "", alternatives = "", date = as.character(Sys.Date()), id = NULL, justification = "", silent = justifier::opts$get("silent"), ... )
label |
A human-readable label for the |
description |
A human-readable description. |
alternatives |
The alternatives between which was chosen. |
date |
The date of the decision. |
id |
Optionally, a manually specified id (otherwise, randomly generated). |
justification |
A justification specified using |
silent |
Whether to print messages. |
... |
Any additional options will be stored in the decision. |
Invisibly, the decision as a justifier
object (generated by
dcsn()
).
clean_workspace(force = TRUE, silent=FALSE); log_decision("First we start using `justifier`.", silent=FALSE); log_decision(paste0("Then we start documenting our ", "decisions and justifications."), silent=FALSE); log_decision("Then we start learning from ourselves.", silent=FALSE); workspace();
clean_workspace(force = TRUE, silent=FALSE); log_decision("First we start using `justifier`.", silent=FALSE); log_decision(paste0("Then we start documenting our ", "decisions and justifications."), silent=FALSE); log_decision("Then we start learning from ourselves.", silent=FALSE); workspace();
Merging to justifier specification lists
merge_specLists(x, y)
merge_specLists(x, y)
x , y
|
The two justifier specification lists |
A merged justifier specification list.
### Add example
### Add example
The justifier::opts
object contains three functions to set, get, and reset
options used by the escalc package. Use justifier::opts$set
to set options,
justifier::opts$get
to get options, or justifier::opts$reset
to reset specific or
all options to their default values.
opts
opts
An object of class list
of length 4.
If you use justifier to programmatically document your decisions in an
R file, there is one option that you common use: workspace_id
and
workspace_option_name
It is normally not necessary to get or set justifier
options.
The following arguments can be passed:
For justifier::opts$set
, the dots can be used to specify the options
to set, in the format option = value
, for example,
EFFECTSIZE_POINTESTIMATE_NAME_IN_DF = "\n"
. For
justifier::opts$reset
, a list of options to be reset can be passed.
For justifier::opts$set
, the name of the option to set.
For justifier::opts$get
, the default value to return if the
option has not been manually specified.
The following options can be set:
Default regex replacements when sanitizing for DiagrammeR
When creating the diagram showing the justification for a decision, the name of the field with the weight.
When creating the diagram showing the justification for a decision, the colour to use for edges with negative weights
When creating the diagram showing the justification for a decision, the colour to use for edges with positive weights
When creating the diagram showing the justification for a decision, the color for nodes
When creating the diagram showing the justification for a decision, the color for edges
When creating the diagram showing the justification for a decision, the pen widht
The default identifier for the workspace (when nothing else is specified)
The name of the default workspace
Whether to be chatty or silent
### Get the default 'silent' setting justifier::opts$get('silent'); ### Set to FALSE justifier::opts$set(silent = FALSE); ### Check that it worked justifier::opts$get('silent'); ### Reset this option to its default value justifier::opts$reset('silent'); ### Check that the reset worked, too justifier::opts$get('silent');
### Get the default 'silent' setting justifier::opts$get('silent'); ### Set to FALSE justifier::opts$set(silent = FALSE); ### Check that it worked justifier::opts$get('silent'); ### Reset this option to its default value justifier::opts$reset('silent'); ### Check that the reset worked, too justifier::opts$get('silent');
This function is normally called by load_justifications()
; however,
sometimes it may be desirable to parse justifications embedded in more
complex objects, for example as provided by yum::load_and_simplify()
.
Therefore, this function can also be called directly.
parse_justifications( x, justifierFields = "^date$|^framework$", fromFile = NULL, path = NULL, storeDecisionGraphSvg = FALSE, silent = TRUE ) ## S3 method for class 'justifierDecisionGraph' print(x, ...) ## S3 method for class 'justifierDecisionGraph' plot(x, ...)
parse_justifications( x, justifierFields = "^date$|^framework$", fromFile = NULL, path = NULL, storeDecisionGraphSvg = FALSE, silent = TRUE ) ## S3 method for class 'justifierDecisionGraph' print(x, ...) ## S3 method for class 'justifierDecisionGraph' plot(x, ...)
x |
An object resulting from a call to |
justifierFields |
Which fields to copy from |
fromFile |
The file from which the |
path |
The path holding these |
storeDecisionGraphSvg |
Whether to also produce (and return) the SVG for the decision graph. |
silent |
Whether to be chatty or quiet. |
... |
Additional arguments are passed on to |
While there is some flexibility in how justifications can be specified, they are most easily processed further if they all follow the same conventions. This function ensures this. The convention is as follows:
all specifications are provided in four 'flat' lists, named after the types of elements they contain;
all elements have a unique identifier
all references to other elements are indeed only references to the other elements' id's in these 'flat lists'
The parsed justifier
object.
### Specify an example text exampleFile <- system.file("extdata", "simple-example.jmd", package="justifier"); ### Show contents cat(readLines(exampleFile), sep="\n"); ### Load it with yum::load_and_simplify() loadedMinutes <- yum::load_and_simplify(exampleFile); ### Show contents names(loadedMinutes); ### Parse 'manually' parsedJustifications <- justifier::parse_justifications(loadedMinutes); ### Show contents names(parsedJustifications);
### Specify an example text exampleFile <- system.file("extdata", "simple-example.jmd", package="justifier"); ### Show contents cat(readLines(exampleFile), sep="\n"); ### Load it with yum::load_and_simplify() loadedMinutes <- yum::load_and_simplify(exampleFile); ### Show contents names(loadedMinutes); ### Parse 'manually' parsedJustifications <- justifier::parse_justifications(loadedMinutes); ### Show contents names(parsedJustifications);
idSlug is a convenience function with swapped argument order.
randomSlug(x = 10, id = NULL, chars = c(letters, LETTERS, 0:9)) idSlug(id = NULL, x = 10, chars = c(letters, LETTERS, 0:9))
randomSlug(x = 10, id = NULL, chars = c(letters, LETTERS, 0:9)) idSlug(id = NULL, x = 10, chars = c(letters, LETTERS, 0:9))
x |
Length of slug |
id |
If not NULL, prepended to slug (separated with a dash) as id; in that case, it's also braces and a hash is added. |
chars |
Characters to sample from |
A character value.
randomSlug(); idSlug("identifier");
randomSlug(); idSlug("identifier");
Repeat a string a number of times
repeatStr(n = 1, str = " ")
repeatStr(n = 1, str = " ")
n , str
|
Normally, respectively the frequency with which to repeat the string and the string to repeat; but the order of the inputs can be switched as well. |
A character vector of length 1.
### 10 spaces: repStr(10); ### Three euro symbols: repStr("\u20ac", 3);
### 10 spaces: repStr(10); ### Three euro symbols: repStr("\u20ac", 3);
Basically a wrapper for gsub()
to sanitize a string for
DiagrammeR
sanitize_for_DiagrammeR( x, regExReplacements = justifier::opts$get("regExReplacements") )
sanitize_for_DiagrammeR( x, regExReplacements = justifier::opts$get("regExReplacements") )
x |
The string or vector |
regExReplacements |
A list of two-element character vectors; first element should be the element to search, and the second element, the replacement. |
The sanitized character vector
justifier::sanitize_for_DiagrammeR("This is or isn't problematic");
justifier::sanitize_for_DiagrammeR("This is or isn't problematic");
Save your workspace
save_workspace( file = NULL, encoding = "UTF-8", append = FALSE, preventOverwriting = TRUE, silent = justifier::opts$get("silent") )
save_workspace( file = NULL, encoding = "UTF-8", append = FALSE, preventOverwriting = TRUE, silent = justifier::opts$get("silent") )
file |
If specified, the file to export the justification to. |
encoding |
The encoding to use when writing the file. |
append |
Whether to append to the file, or replace its contents. |
preventOverwriting |
Whether to prevent overwriting an existing file. |
silent |
Whether to be silent or chatty. |
The result of a call to export_justification()
.
clean_workspace(force = TRUE, silent=FALSE); log_decision("First we start using `justifier`.", silent=FALSE); log_decision(paste0("Then we start documenting our ", "decisions and justifications."), silent=FALSE); log_decision("Then we start learning from ourselves.", silent=FALSE); save_workspace();
clean_workspace(force = TRUE, silent=FALSE); log_decision("First we start using `justifier`.", silent=FALSE); log_decision(paste0("Then we start documenting our ", "decisions and justifications."), silent=FALSE); log_decision("Then we start learning from ourselves.", silent=FALSE); save_workspace();
This is used to be able to log decisions programmatically.
set_workspace_id(id, silent = justifier::opts$get("silent"))
set_workspace_id(id, silent = justifier::opts$get("silent"))
id |
The workspace identifier |
silent |
Whether to be suppress messages. |
Invisibly, the passed id
.
set_workspace_id("my_workspace");
set_workspace_id("my_workspace");
This function is for internal use, but has been exported in case it's useful for people working 'manually' with lists of justifications.
to_specList(x, types, type, idsRequired = TRUE, silent = TRUE)
to_specList(x, types, type, idsRequired = TRUE, silent = TRUE)
x |
The list to parse. |
types |
The class to assign to the specification
list (the |
type |
The class to assign to each specification
(in addition to |
idsRequired |
Whether to require identifiers. |
silent |
Whether to be chatty or silent. |
A list of classes c("justifierSpecList", types)
where
each element is a specification of class
c("justifierSpec", type)
.
### Specify an example text exampleFile <- system.file("extdata", "simple-example.jmd", package="justifier"); ### Show contents cat(readLines(exampleFile), sep="\n"); ### Load it with yum::load_and_simplify() loadedMinutes <- yum::load_and_simplify(exampleFile); ### Show contents names(loadedMinutes); ### Show classes class(loadedMinutes["assertion"]); ### Convert to specification list res <- to_specList(loadedMinutes["assertion"], type="assertion", types="assertions"); ### Show classes class(res); ### Show original and parsed objects loadedMinutes["assertion"]; res;
### Specify an example text exampleFile <- system.file("extdata", "simple-example.jmd", package="justifier"); ### Show contents cat(readLines(exampleFile), sep="\n"); ### Load it with yum::load_and_simplify() loadedMinutes <- yum::load_and_simplify(exampleFile); ### Show contents names(loadedMinutes); ### Show classes class(loadedMinutes["assertion"]); ### Convert to specification list res <- to_specList(loadedMinutes["assertion"], type="assertion", types="assertions"); ### Show classes class(res); ### Show original and parsed objects loadedMinutes["assertion"]; res;
Easily parse a vector into a character value
vecTxt( vector, delimiter = ", ", useQuote = "", firstDelimiter = NULL, lastDelimiter = " & ", firstElements = 0, lastElements = 1, lastHasPrecedence = TRUE ) vecTxtQ(vector, useQuote = "'", ...)
vecTxt( vector, delimiter = ", ", useQuote = "", firstDelimiter = NULL, lastDelimiter = " & ", firstElements = 0, lastElements = 1, lastHasPrecedence = TRUE ) vecTxtQ(vector, useQuote = "'", ...)
vector |
The vector to process. |
delimiter , firstDelimiter , lastDelimiter
|
The delimiters
to use for respectively the middle, first
|
useQuote |
This character string is pre- and appended to all elements;
so use this to quote all elements ( |
firstElements , lastElements
|
The number of elements for which to use the first respective last delimiters |
lastHasPrecedence |
If the vector is very short, it's possible that the
sum of firstElements and lastElements is larger than the vector length. In
that case, downwardly adjust the number of elements to separate with the
first delimiter ( |
... |
Any addition arguments to |
A character vector of length 1.
vecTxtQ(names(mtcars));
vecTxtQ(names(mtcars));
Show your workspace contents
workspace(silent = justifier::opts$get("silent"))
workspace(silent = justifier::opts$get("silent"))
silent |
Whether to be chatty or silent. |
The workspace contents.
justifier::clean_workspace(force = TRUE, silent=FALSE); justifier::log_decision( "First we start using `justifier`.", silent=FALSE ); justifier::log_decision( paste0("Then we start documenting our ", "decisions and justifications."), silent=FALSE ); justifier::log_decision( "Then we start learning from ourselves.", silent=FALSE ); justifier::workspace();
justifier::clean_workspace(force = TRUE, silent=FALSE); justifier::log_decision( "First we start using `justifier`.", silent=FALSE ); justifier::log_decision( paste0("Then we start documenting our ", "decisions and justifications."), silent=FALSE ); justifier::log_decision( "Then we start learning from ourselves.", silent=FALSE ); justifier::workspace();
Wrap all elements in a vector
wrapVector(x, width = 0.9 * getOption("width"), sep = "\n", ...)
wrapVector(x, width = 0.9 * getOption("width"), sep = "\n", ...)
x |
The character vector |
width |
The number of |
sep |
The glue with which to combine the new lines |
... |
Other arguments are passed to |
A character vector
res <- wrapVector( c( "This is a sentence ready for wrapping", "So is this one, although it's a bit longer" ), width = 10 ); print(res); cat(res, sep="\n");
res <- wrapVector( c( "This is a sentence ready for wrapping", "So is this one, although it's a bit longer" ), width = 10 ); print(res); cat(res, sep="\n");