Title: | Advanced R Pipes |
---|---|
Description: | Provides convenience functions for programming with 'magrittr' pipes. Conditional pipes, a string prefixer and a function to pipe the given object into a specific argument given by character name are currently supported. It is named after the dadaist Hans Arp, a friend of Rene Magritte. |
Authors: | Jirka Lewandowski [aut], Sébastien Rochette [aut, cre] |
Maintainer: | Sébastien Rochette <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.1.2 |
Built: | 2024-11-20 03:03:56 UTC |
Source: | https://github.com/ThinkR-open/arpr |
browser() in a magrittr pipe
browse_r(x, ...)
browse_r(x, ...)
x |
input |
... |
passed on to browser() |
Used for side effect. Open a browser inside the pipe workflow.
Create a constant function
const(val = NULL)
const(val = NULL)
val |
return value of constant function (defaults to NULL) |
A function always returning val
accepting arbitrary arguments (dots)
iff
returns output of the function if and only if test is TRUE
.
iffn
returns output of the function if and only if test is FALSE
.
They return the original value otherwise.
iffelse
returns output of the first function if test is TRUE
,
output of the second function otherwise.
iff(obj, test, fun, ...) iffn(obj, test, fun, ...) iffelse(obj, test, true_fun, false_fun, ...)
iff(obj, test, fun, ...) iffn(obj, test, fun, ...) iffelse(obj, test, true_fun, false_fun, ...)
obj |
object to apply test and fun to |
test |
logical or function to apply to test |
fun |
function to apply |
... |
passed on to test |
true_fun |
function to apply when test is true |
false_fun |
function to apply when test is false |
Output of function fun
applied to the original value or the
original value, depending on the test.
x <- 1 x %>% iff(is.na, const(0)) x <- NA x %>% iff(is.na, const(0)) x <- 1 x %>% iff(x <= 0, function(x) { x - 2 }) x <- -1 x %>% iff(x <= 0, function(x) { x - 2 }) x <- NA x %>% iffn(is.na, exp) x <- 10 x %>% iffn(is.na, exp)
x <- 1 x %>% iff(is.na, const(0)) x <- NA x %>% iff(is.na, const(0)) x <- 1 x %>% iff(x <= 0, function(x) { x - 2 }) x <- -1 x %>% iff(x <= 0, function(x) { x - 2 }) x <- NA x %>% iffn(is.na, exp) x <- 10 x %>% iffn(is.na, exp)
This rotates the order of the arguments such that the one named
in param_name
comes first and then calls the function.
pipe_into(x, param_name, fun, ...)
pipe_into(x, param_name, fun, ...)
x |
value to be piped into fun |
param_name |
name of the argument that x should be assigned to |
fun |
function |
... |
further arguments for fun |
Output of fun
.
require(magrittr) 5L %>% pipe_into("digits", format, 2.731234567)
require(magrittr) 5L %>% pipe_into("digits", format, 2.731234567)
Convenience function to use with magrittr
wraps paste0()
, hence vectorised as paste0()
prefix(text, ...)
prefix(text, ...)
text |
goes to the end, rest |
... |
goes to the front. |
Character. Character chain with the prefix added.
require(magrittr) "xyz" %>% prefix("abc")
require(magrittr) "xyz" %>% prefix("abc")
file.path with arguments reversed
prefix_path(path, prefix, ...)
prefix_path(path, prefix, ...)
path |
path to be prefixed |
prefix |
path to be appended before |
... |
passed on to file.path |
file.path(prefix, path, ...)
Remove names of an object
remove_names(x)
remove_names(x)
x |
object to unname |
x without names.