getByPath: Get By Path (generic)

Description Usage Arguments Author(s) References See Also Examples

Description

Retrieves actual values based on their path.

Usage

1
2
getByPath(input, value, outer = FALSE, resolve = FALSE, strict = c(0, 1,
  2), ...)

Arguments

input

Signature argument. Object containing structure information.

value

character. Path as found in return value of getStructure.

outer

logical. TRUE: use oindex instead of index to retrieve the outer element values (i.e., outer list structure is preserved); FALSE: use index to retrieve the inner element values (i.e. outer list structure is not preserved).

resolve

logical. TRUE: resolve path to basename component as names for return value; FALSE: use path as names for return value.

strict

numeric.

  • 0: ignore without warning

  • 1: ignore with Warning

  • 2: stop with error

...

Further arguments to be passed to subsequent functions/methods.

Author(s)

Janko Thyson janko.thyson@rappster.de

References

http://github.com/rappster/listr

See Also

getByPath-list-method, getStructure

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: 

input <- list(
  x1 = list(x11 = list(x111 = 1, x112 = 1), x12 = list(x121 = 1, x122 = 1)),
  x2 = list(x21 = "x21"),
  x3 = list("x31"),
  x4 = "x4",
  x5 = list(1:3),
  list(list(1, 2), list(3, 4)),
  list(1:3),
  "char 1",
  "char 2",
  letters[1:3],
  c(1,3,5),
  TRUE,
  new.env(),
  data.frame(x = 1:3, y = 1:3)
)

## Inspect structure //
(struc <- getStructure(input))

## Name-based path //
getByPath(input, value = "x1")

getByPath(input, value = "x1/x11")
getByPath(input, value = "x1/x11", resolve = TRUE)
getByPath(input, value = "x1/x11", resolve = TRUE, resolve_by = "ppath")

getByPath(input, value = "x2/x21")
getByPath(input, value = "x2/x21", resolve = TRUE)
getByPath(input, value = "x2/x21", resolve = TRUE, resolve_by = "index")

## Position-based path //
getByPath(input, value = "6/1")
getByPath(input, value = "6/1", resolve = TRUE)
getByPath(input, value = "6/1", resolve = TRUE, resolve_by = "ppath")

## Multiple //
getByPath(input, value = c("x1/x11", "x2/x21"))
getByPath(input, value = c("x1/x11", "x2/x21"), resolve = TRUE)
getByPath(input, value = c("x1/x11", "x2/x21"), resolve = TRUE, resolve_by = "ppath")

getByPath(input, value = c("x1/x11", "x2/x21", "6/1"))
getByPath(input, value = c("x1/x11", "x2/x21", "6/1"), resolve = TRUE)
getByPath(input, value = c("x1/x11", "x2/x21", "6/1"), resolve = TRUE, 
  resolve_by = "index")

## Condition handling //
getByPath(input, value = "x1/99")
try(getByPath(input, value = "x1/99", strict = 1))
try(getByPath(input, value = "x1/99", strict = 2))


## End(Not run)

rappster/listr documentation built on May 26, 2019, 11:21 p.m.