rmNested: Remove Nested (generic)

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

Description

Removes a component from a nested object structure based on a path-like id with the last ID component being the name of the actual object being removed.

Usage

1
rmNested(id, where = parent.frame(), strict = c(0, 1, 2), ...)

Arguments

id

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

where

Signature argument. Object containing location information.

strict

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

  • 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. a$b$c$...$z and a$b$c$...$z <- value). Of course, "atomic" paths (e.g. only a) are also valid.

Author(s)

Janko Thyson janko.thyson@rappster.de

References

http://github.com/Rappster/nestr

See Also

rmNested-char-env-method, setNested, getNested

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

##------------------------------------------------------------------------------
## Default `where` //
##------------------------------------------------------------------------------

setNested(id = "a", value = TRUE)
exists("a", environment(), inherits = FALSE)
rmNested(id = "a")
exists("a", environment(), inherits = FALSE)

setNested(id = "a/b/c", value = 10, gap = TRUE)
exists("c", environment()$a$b, inherits = FALSE)
rmNested(id = "a/b/c")
exists("c", environment()$a$b, inherits = FALSE)

## Clean up //
rm(a)

##------------------------------------------------------------------------------
## Different `where` // 
##------------------------------------------------------------------------------

where <- new.env()
setNested(id = "a/b/c", value = 10, where = where, gap = TRUE)
rmNested(id = "a/b/c", where = where)
exists("c", where$a$b, inherits = FALSE)

## Clean up //
rm(where)
  
##------------------------------------------------------------------------------
## Strictness //
##------------------------------------------------------------------------------

rmNested(id = "a")
try(rmNested(id = "a", strict = 1))
try(rmNested(id = "a", strict = 2))

rmNested(id = "a/b/c")
try(rmNested(id = "a/b/c", strict = 1))
try(rmNested(id = "a/b/c", strict = 2))

rmNested(id = character()))
try(rmNested(id = character(), strict = 1))
try(rmNested(id = character(), strict = 2))
    

## End(Not run)

rappster/nestr documentation built on May 26, 2019, 11:22 p.m.