Description Usage Arguments Details Value Author(s) References See Also Examples
Default method of createCrudExpression
.
1 2 3 4 5 6 7 | ## Default S3 method:
createCrudExpression(inst, id = character(), value = NULL,
name_obj = "inst", name_value = "value", as_name_obj = TRUE,
as_name_value = FALSE, evaluate = FALSE, sugar = c("[[", "$"),
in_parent = FALSE, return_conventional = TRUE, strict = 0:3,
fail_safe = FALSE, use_tree = FALSE, allow_null = FALSE,
affect_branch = FALSE, ...)
|
inst |
|
id |
|
value |
|
name_obj |
|
name_value |
|
as_name_obj |
|
as_name_value |
|
evaluate |
|
sugar |
|
in_parent |
|
return_conventional |
|
strict |
|
fail_safe |
|
use_tree |
|
allow_null |
|
affect_branch |
|
... |
Further arguments to be passed to subsequent functions/methods. |
TODO
expression
or evaluated CRUD expression
if evaluate = TRUE
. Exact value also depends on
return_conventional
(in interaction with value
and in_parent
)
Janko Thyson janko.thyson@rappster.de
http://github.com/rappster/crudr
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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | # Example object ----------------------------------------------------------
inst <- list(a = list(b = list(c = 10)))
# Extract -----------------------------------------------------------------
createCrudExpression(inst, c("a", "b"))
createCrudExpression(inst, c("a", "b"), evaluate = TRUE)
## --> evaluated inside the function
createCrudExpression(inst, c("a", "b"), evaluate = TRUE, in_parent = TRUE)
## --> evaluated in the frame of `inst`
# Assign ------------------------------------------------------------------
createCrudExpression(inst, c("a", "b", "c"), 100)
createCrudExpression(inst, c("a", "b", "c"), 100, evaluate = TRUE)
## --> evaluated inside the function
inst
## --> `inst$a$b$c` still is `10`
createCrudExpression(inst, c("a", "b", "c"), 100, evaluate = TRUE,
in_parent = TRUE)
## --> evaluated in the frame of `inst`
inst
## --> `inst$a$b$c` is now `100`
# Return values -----------------------------------------------------------
inst <- list(a = list(b = list(c = 10)))
createCrudExpression(inst, c("a", "b", "c"), 100, evaluate = TRUE,
return_conventional = FALSE)
## --> evaluated inside the function and entire "updated" object `inst`returned
inst
## --> `inst$a$b$c` still is `10`
createCrudExpression(inst, c("a", "b", "c"), 1, evaluate = TRUE,
in_parent = TRUE, return_conventional = FALSE)
## --> evaluated in the frame of `inst`. In this case, `NULL` is returned
## in order to stress the point that the actual object being altered
## has nothing to do with the return value
inst
## --> `inst$a$b$c` is now `1`
# Sugar = $ ---------------------------------------------------------------
## For the sake of completeness the function also allows you to use the
## syntactic sugar `$` instead of `[[`. While this might be usefull in
## certain usage scenarios, it needs to be noted that comes with additional
## computiational costs (see benchmark)
inst <- list(a = list(b = list(c = 10)))
createCrudExpression(inst, c("a", "b"), sugar = "$")
createCrudExpression(inst, c("a", "b"), value = 1, sugar = "$")
library(microbenchmark)
res <- microbenchmark(
"extract_1" = createCrudExpression(inst, c("a", "b"), sugar = "[["),
"extract_2" = createCrudExpression(inst, c("a", "b"), sugar = "$"),
"assign_1" = createCrudExpression(inst, c("a", "b"), 1, sugar = "[["),
"assign_2" = createCrudExpression(inst, c("a", "b"), 1, sugar = "$")
)
res
# Comparison to plain method ----------------------------------------------
## While `createCrudExpression` offers more features,
## `createCrudExpressionPlain` is substantially faster.
library(microbenchmark)
res <- microbenchmark(
"extract_1" = createCrudExpression(inst, c("a", "b")),
"extract_2" = createCrudExpressionPlain(inst, c("a", "b")),
"assign_1" = createCrudExpression(inst, c("a", "b"), 1),
"assign_2" = createCrudExpressionPlain(inst, c("a", "b"), 1)
)
res
# Bridging ----------------------------------------------------------------
inst <- list(a = list(b = 1))
createCrudExpression(inst, c("a", "b", "c", "d"), value = 1, evaluate = TRUE,
return_conventional = FALSE)
createCrudExpression(inst, c("a", "b", "c", "d"), value = 1, evaluate = TRUE,
return_conventional = FALSE, strict = 1)
try(
createCrudExpression(inst, c("a", "b", "c", "d"), value = 1, evaluate = TRUE,
return_conventional = FALSE, strict = 2)
)
try(
createCrudExpression(inst, c("a", "b", "c", "d"), value = 1, evaluate = TRUE,
return_conventional = FALSE, strict = 3)
)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.