vetr (version 0.2.6)

vetr_settings: Generate Control Settings For vetr and alike

Description

Utility function to generate setting values. We strongly recommend that you generate the settings outside of function calls so that setting generation does not become part of the vet/vetr/alike evaluation as that could add noticeable overhead to the function evaluation.

Usage

vetr_settings(type.mode = 0L, attr.mode = 0L, lang.mode = 0L,
  fun.mode = 0L, rec.mode = 0L, suppress.warnings = FALSE,
  fuzzy.int.max.len = 100L, width = -1L, env.depth.max = 65535L,
  symb.sub.depth.max = 65535L, symb.size.max = 15000L, nchar.max = 65535L,
  track.hash.content.size = 63L, env = NULL, result.list.size.init = 64L,
  result.list.size.max = 1024L)

Arguments

type.mode

integer(1L) in 0:2, defaults to 0, determines how object types (as in typeof) are compared:

  • 0: integer like numerics (e.g. 1.0) can match against integer templates, and integers always match real templates; all function types are considered of the same type

  • 1: integers always match against numeric templates, but not vice versa, and integer-like numerics are treated only as numerics; functions only match same function type (i.e. closures only match closures, builtins builtins, and specials specials)

  • 2: types must be equal for all objects types (for functions, this is unchanged from 1)

attr.mode

integer(1L) in 0:2, defaults to 0, determines strictness of attribute comparison:

  • 0 only checks attributes that are present in target, and uses special comparisons for the special attributes (class, dim, dimnames, names, row.names, levels, srcref, and tsp) while requiring other attributes to be alike

  • 1 is like 0, except all atributes must be alike

  • 2 requires all attributes to be present in target and current and to be alike

lang.mode

integer(1L) in 0:1, defaults to 0, controls language matching, set to 1 to turn off use of match.call()

fun.mode

NOT IMPLEMENTED, controls how functions are compared

rec.mode

integer(1L) 0 currently unused, intended to control how recursive structures (other than language objects) are compared

suppress.warnings

logical(1L) suppress warnings if TRUE

fuzzy.int.max.len

max length of numeric vectors to consider for integer likeness (e.g. c(1, 2) can be considered "integer", even though it is numeric); currently we limit this check to vectors shorter than 100 to avoid a potentially expensive computation on large vectors, set to -1 to apply to all vectors irrespective of length

width

to use when deparsing expressions; default -1 equivalent to getOption("width")

env.depth.max

integer(1L) maximum number of nested environments to recurse through, defaults to 65535L; these are tracked to make sure we do not get into an infinite recursion loop, but because they are tracked we keep a limit on how many we will go through, set to -1 to allow unlimited recursion depth. You should not need to change this unless you are running into the recursion limit.

symb.sub.depth.max

integer(1L) maximum recursion depth when recursively substituting symbols in vetting expression, defaults to 65535L

symb.size.max

integer(1L) maximum number of characters that a symbol is allowed to have in vetting expressions, defaults to 15000L.

nchar.max

integer(1L) defaults to 65535L, threshold after which strings encountered in C code are truncated. This is the read limit. In theory vetr can produce strings longer than that by combining multiple shorter pieces.

track.hash.content.size

integer(1L) (advanced) used to set the initial size of the symbol tracking vector used with the hash table that detects recursive symbol substitution. If the tracking vector fills up it will be grown by 2x. This parameter is exposed mostly for developer use.

env

what environment to use to match calls and evaluate vetting expressions, although typically you would specify this with the env argument to vet; if NULL will use the calling frame to vet/vetr/alike.

result.list.size.init

initial value for token tracking. This will be grown by a factor of two each time it fills up until we reach result.list.size.max.

result.list.size.max

maximum number of tokens we keep track of, intended mostly as a safeguard in case a logic error causes us to keep allocating memory. Set to 1024 as a default value since it should be exceedingly rare to have vetting expressions with such a large number of tokens, enough so that if we reach that number it is more likely something went wrong.

Value

list with all the setting values

Details

Settings after fuzzy.int.max.len are fairly low level and exposed mostly for testing purposes. You should generally not need to use them.

Note that a successful evaluation of this function does not guarantee a correct settings list. Those checks are carried out internally by vet/vetr/alike.

See Also

type_alike, alike, vetr

Examples

Run this code
# NOT RUN {
type_alike(1L, 1.0, settings=vetr_settings(type.mode=2))
## better if you are going to re-use settings to reduce overhead
set <- vetr_settings(type.mode=2)
type_alike(1L, 1.0, settings=set)
# }

Run the code above in your browser using DataCamp Workspace