ConditionKeeper: ConditionKeeper

ConditionKeeperR Documentation

ConditionKeeper

Description

R6 class with methods for handling conditions

Public fields

bucket

list holding conditions

times

number of times

condition

(character) type of condition, message or warning

Methods

Public methods


Method new()

Create a new ConditionKeeper object

Usage
ConditionKeeper$new(times = 1, condition = "message")
Arguments
times

(integer) number of times to throw condition. required. default: 1

condition

(character) which condition, one of "message" (default) or "warning"

Returns

A new ConditionKeeper object


Method print()

print method for the ConditionKeeper class

Usage
ConditionKeeper$print(x, ...)
Arguments
x

self

...

ignored


Method add()

add a condition to internal storage

Usage
ConditionKeeper$add(x)
Arguments
x

a condition

Returns

self


Method remove()

remove the first condition from internal storage; returns that condition so you know what you removed

Usage
ConditionKeeper$remove()
Returns

the condition removed


Method purge()

removes all conditions

Usage
ConditionKeeper$purge()
Returns

NULL


Method thrown_already()

has the condition been thrown already?

Usage
ConditionKeeper$thrown_already(x)
Arguments
x

a condition

Returns

logical


Method not_thrown_yet()

has the condition NOT been thrown yet?

Usage
ConditionKeeper$not_thrown_yet(x)
Arguments
x

a condition

Returns

logical


Method thrown_times()

number of times the condition has been thrown

Usage
ConditionKeeper$thrown_times(x)
Arguments
x

a condition

Returns

numeric


Method thrown_enough()

has the condition been thrown enough? "enough" being: thrown number of times equal to what you specified in the times parameter

Usage
ConditionKeeper$thrown_enough(x)
Arguments
x

a condition

Returns

logical


Method get_id()

get the internal ID for the ConditionKeeper object

Usage
ConditionKeeper$get_id()
Returns

a UUID (character)


Method handle_conditions()

pass a code block or function and handle conditions within it

Usage
ConditionKeeper$handle_conditions(expr)
Arguments
expr

an expression

Returns

the result of calling the expression


Method clone()

The objects of this class are cloneable with this method.

Usage
ConditionKeeper$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

handle_conditions()

Examples

x <- ConditionKeeper$new(times = 4)
x
x$get_id()
x$add("one")
x$add("two")
x
x$thrown_already("one")
x$thrown_already("bears")
x$not_thrown_yet("bears")

x$add("two")
x$add("two")
x$add("two")
x$thrown_times("two")
x$thrown_enough("two")
x$thrown_enough("one")

foo <- function(x) {
  message("you gave: ", x)
  return(x)
}
foo('a')
x$handle_conditions(foo('a'))

x <- ConditionKeeper$new(times = 4, condition = "warning")
x
x$add("one")
x$add("two")
x

ropenscilabs/conditionz documentation built on Sept. 9, 2022, 11:56 p.m.