existsProjectOption-character-character-method: Check Existence of Project Option (char-char)

Description Usage Arguments Value Author(s) References See Also Examples

Description

See generic: existsProjectOption

Usage

1
2
3
4
5
## S4 method for signature 'character,character'
existsProjectOption(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

character.

where

character.

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 option 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.

Value

ANY. Component value or for invalid argument input and non-existing component the value of default unless strict == 1 in which case a warning is issued or strict == 2 in which case an error is thrown.

Author(s)

Janko Thyson janko.thyson@gmail.com

References

http://github.com/Rappster/optionr

See Also

existsProjectOption

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
## Not run: 

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

setProjectOption(id = "test", value = TRUE)
existsProjectOption(id = "test")

setProjectOption(id = "a/b/c", value = 10)
existsProjectOption(id = "a")
existsProjectOption(id = "a/b")
existsProjectOption(id = "a/b/c")
existsProjectOption(id = "a/b/c/d")

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

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

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

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

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

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

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


## End(Not run)

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