Skip to content

Commit

Permalink
Function ._() migrated from svMisc
Browse files Browse the repository at this point in the history
  • Loading branch information
phgrosjean committed Aug 24, 2022
1 parent 1309bce commit 651b22e
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 7 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ S3method(str,Flow)
export("!!")
export("%>.%")
export("%>_%")
export(._)
export(as.flow)
export(as.quosure)
export(as_flow)
Expand Down
14 changes: 7 additions & 7 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# svFlow News
# svFlow 1.2.0

## svFlow version 1.2.0
- The package is renamed svFlow because there is another flow package on CRAN.

The package is renamed svFlow because there is another flow package on CRAN.
- The function `._()` is moved from {svMisc} 1.3.1 into here. Now, it creates or overwrites `.` and `.call` objects in the calling environment to match the behavior of `%>.%`.

## flow version 1.1.0
# flow 1.1.0

Internal reworking, no change in R code.
- Internal reworking, no change in R code.

## flow version 1.0-0
# flow 1.0-0

First version of the package.
- First version of the package.
24 changes: 24 additions & 0 deletions R/dot.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#' Pass first argument as dot to run code in second argument for pipe operators that do not natively support dot-replacement scheme (base R pipe operator)
#'
#' @param x Object to pass to `expr` as dot (`.`).
#' @param expr Expression to execute, containing `.` as a placeholder.
#'
#' @return The result from executing `expr` in the parent environment.
#' @details The function has a side-effect to assign `x` as `.` and unevaluated `expr` as `.call` in the calling environment. Therefore, make sure you do not use `.` or `.call` there for something else. In case `expr` fails in the middle of a series of chained pipes, you can inspect `.` and `.call` or possibly rerun a modified version of the instruction that failed on it for easier debugging purpose.
#' @export
#' @examples
#' # The function is really supposed to be use in a pipe instruction
#' # This example only runs on R >= 4.1
#' \dontrun{
#' # lm has data = as second argument, which does not fit well with the pipe |>
#' # In R 4.1, one should write:
#' iris |> \(.)(lm(data = ., Sepal.Length ~ Petal.Length + Species))()
#' # which is not very elegant ! With ._() it is more concise and straighforward
#' iris |> ._(lm(data = ., Sepal.Length ~ Petal.Length + Species))
#' }
._ <- function(x, expr) {
env <- caller_env()
env[["."]] <- x
env[[".call"]] <- substitute(expr)
expr
}
2 changes: 2 additions & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Kun
lazyeval
magrittr
magrittr's
natively
NSE
performanceEstimation
pipeable
Expand All @@ -35,6 +36,7 @@ subclassed
svFlow
tidyeval
tidyverse
unevaluated
unflows
usepackage
utf
Expand Down
33 changes: 33 additions & 0 deletions man/dot-_.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 651b22e

Please sign in to comment.