diff --git a/Examples/Substitution/Substitution.Rmd b/Examples/Substitution/Substitution.Rmd index 22be97b6..be183de7 100644 --- a/Examples/Substitution/Substitution.Rmd +++ b/Examples/Substitution/Substitution.Rmd @@ -35,12 +35,15 @@ ops <- local_td(d) %.>% cat(format(ops)) ``` +And we can execute the operations as follows. + ```{r} d %.>% ops %.>% knitr::kable(.) ``` + This also works in the `wrap`/`ex` pattern. ```{r} @@ -68,25 +71,28 @@ d %.>% ``` - -Note: `rquery` `1.3.9` has an issue with `bquote`/`.()` substitution in "imediate mode". We have fixed that in later versions. +We want to avoid using strings instead of names, as strings don't always give us the expected result. `rquery` tries to work around and catch many of these cases. For example: ```{r} -d %.>% +condition_name <- 'x' + +ops2 <- local_td(d) %.>% select_rows(., - .(condition_variable) == 1) %.>% - extend(., - .(new_value_variable) := .(old_value_variable) + 1) %.>% - knitr::kable(.) + .(condition_name) == 1) + +cat(format(ops2)) ``` +New to `rquery` `1.4.3` we have a new "`-` to strip off quotes" feature. What this is: `.(-v)` converts `v` from a character type to a name. Meaning we don't have to use the `as.name()` calls if we don't want to. + ```{r} -d %.>% +condition_name <- 'x' + +ops3 <- local_td(d) %.>% select_rows(., - .(condition_variable) == 1) %.>% - project(., - .(new_value_variable) := max(.(old_value_variable))) %.>% - knitr::kable(.) + .(-condition_name) == 1) + +cat(format(ops3)) ``` diff --git a/Examples/Substitution/Substitution.md b/Examples/Substitution/Substitution.md index b053fc65..d08f7c67 100644 --- a/Examples/Substitution/Substitution.md +++ b/Examples/Substitution/Substitution.md @@ -34,7 +34,11 @@ knitr::kable(d) ``` r library("rquery") +``` + + ## Loading required package: wrapr +``` r condition_variable <- as.name('x') new_value_variable <- as.name('y') old_value_variable <- as.name('z') @@ -57,6 +61,8 @@ cat(format(ops)) ## extend(., ## y := z + 1) +And we can execute the operations as follows. + ``` r d %.>% ops %.>% @@ -103,32 +109,49 @@ d %.>% | -: | | 7 | -Note: `rquery` `1.3.9` has an issue with `bquote`/`.()` substitution in -“imediate mode”. We have fixed that in later versions. +We want to avoid using strings instead of names, as strings don’t always +give us the expected result. `rquery` tries to work around and catch +many of these cases. For example: ``` r -d %.>% +condition_name <- 'x' + +ops2 <- local_td(d) %.>% select_rows(., - .(condition_variable) == 1) %.>% - extend(., - .(new_value_variable) := .(old_value_variable) + 1) %.>% - knitr::kable(.) + .(condition_name) == 1) ``` -| x | y | z | -| -: | -: | -: | -| 1 | 7 | 6 | -| 1 | 8 | 7 | + ## Warning in warn_about_filter_conditions(parsed): rquery::select_rows: expression + ## "x" == 1 refers to no columns (so is a constant) ``` r -d %.>% +cat(format(ops2)) +``` + + ## mk_td("d", c( + ## "x", + ## "y", + ## "z")) %.>% + ## select_rows(., + ## "x" == 1) + +New to `rquery` `1.4.3` we have a new “`-` to strip off quotes” feature. +What this is: `.(-v)` converts `v` from a character type to a name. +Meaning we don’t have to use the `as.name()` calls if we don’t want to. + +``` r +condition_name <- 'x' + +ops3 <- local_td(d) %.>% select_rows(., - .(condition_variable) == 1) %.>% - project(., - .(new_value_variable) := max(.(old_value_variable))) %.>% - knitr::kable(.) + .(-condition_name) == 1) + +cat(format(ops3)) ``` -| y | -| -: | -| 7 | + ## mk_td("d", c( + ## "x", + ## "y", + ## "z")) %.>% + ## select_rows(., + ## x == 1)