existsMetaValue: Check Existence of Meta Value (generic)

Description Usage Arguments Path-like identifiers Author(s) References See Also Examples

Description

Checks if a meta object exists inside of the respective environment for such information within an option container based on a path-like id with the last ID component being the actual object name that the function looks for. See getOptionContainer.

Usage

1
2
3
existsMetaValue(id, where = tryCatch(devtools::as.package(".")$package, error
  = function(cond) {     stop("Invalid default value for `where`") }),
  sub_id = character(), default = NULL, strict = c(0, 1, 2), ...)

Arguments

id

Signature argument. Object containing path-like name/ID information.

where

Signature argument. Object containing information about the location of the option container that is to be used. Typically, this either corresponds to the name/ID of a package/package project or an instance of a custom class for which suitable methods in the context of managing options are defined (see other methods of this package that have signature arguments id or where).

sub_id

character. Optional ID for a sub layer. Useful for a hub-like option container structure.

default

ANY. Value to be returned if option does not exist. See getOption and getNested.

strict

logical. Controls what happens when id points to a non-existing meta object:

  • 0: ignore and return FALSE to signal that the assignment process was not successful or fail_value depending on the value of return_status

  • 1: ignore and with warning and return FALSE

  • 2: ignore and with error

...

Further arguments to be passed to subsequent functions/methods.

Path-like identifiers

Values for id are expected to be of structure a/b/c/.../z, i.e. path-like identifiers using a slash as separator. The identifier is transformed to a$b$c$...$z and then in turn to a valid get or assign expression (i.e. something similar to getOptionContainer(...)$a$b$c$...$z and getOptionContainer(...)$a$b$c$...$z <- value). Of course, "atomic" paths (e.g. only a) are also valid.

Author(s)

Janko Thyson janko.thyson@gmail.com

References

http://github.com/Rappster/optionr

See Also

existsMetaValue-char-char-method, setMetaValue, getMetaValue, rmMetaValue

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
## Not run: 

##------------------------------------------------------------------------------
## Basics //
##------------------------------------------------------------------------------

setMetaValue(id = "test", value = TRUE)
existsMetaValue(id = "test")

setMetaValue(id = "a/b/c", value = 10)
existsMetaValue(id = "a")
existsMetaValue(id = "a/b")
existsMetaValue(id = "a/b/c")
existsMetaValue(id = "a/b/c/d")

existsMetaValue(id = "c")
existsMetaValue(id = "c/d/e")
  
##------------------------------------------------------------------------------
## Strictness levels //
##------------------------------------------------------------------------------

## Empty ID //
existsMetaValue(id = character())
try(existsMetaValue(id = character(), strict = 1))
try(existsMetaValue(id = character(), strict = 2))

## Not-existing //  
existsMetaValue(id = "c/d/e")
try(existsMetaValue(id = "c/d/e", strict = 1))
try(existsMetaValue(id = "c/d/e", strict = 2))

##------------------------------------------------------------------------------
## Explicit `where` //
##------------------------------------------------------------------------------

where <- new.env()
setMetaValue(id = "a/b/c", value = 10, where = where)
existsMetaValue(id = "a/b/c", where = where)
existsMetaValue(id = "a/b/c/d", where = where)
existsMetaValue(id = "c/d/e", where = where)

##------------------------------------------------------------------------------
## Sub ID //
##------------------------------------------------------------------------------

where <- new.env()
setMetaValue(id = "a/b/c", value = 10, where = where, sub_id = "sub")
ls(where)
existsMetaValue(id = "a/b/c", where = where, sub_id = "sub")
existsMetaValue(id = "a/b/c/d", where = where, sub_id = "sub")
existsMetaValue(id = "c/d/e", where = where, sub_id = "sub")


## End(Not run)

rappster/optionr documentation built on May 26, 2019, 11:23 p.m.