Type: | Package |
Title: | Advanced R Pipes |
Version: | 0.1.2 |
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. |
License: | GPL (≥ 3) |
URL: | https://github.com/statnmap/arpr |
BugReports: | https://github.com/statnmap/arpr/issues |
Imports: | magrittr, rlang |
Suggests: | testthat (≥ 3.0.0) |
Config/testthat/edition: | 3 |
Encoding: | UTF-8 |
RoxygenNote: | 7.1.1 |
NeedsCompilation: | no |
Packaged: | 2021-08-01 12:12:23 UTC; srochett |
Author: | Jirka Lewandowski [aut],
Sébastien Rochette
|
Maintainer: | Sébastien Rochette <sebastien@thinkr.fr> |
Repository: | CRAN |
Date/Publication: | 2021-08-02 15:50:05 UTC |
arpr: 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.
Author(s)
Maintainer: Sébastien Rochette sebastien@thinkr.fr (ORCID)
Authors:
Jirka Lewandowski jirka.lewandowski@wzb.eu
See Also
Useful links:
Pipe operator
Description
See magrittr::%>%
for details.
Usage
lhs %>% rhs
Arguments
lhs |
A value or the magrittr placeholder. |
rhs |
A function call using the magrittr semantics. |
Value
The result of calling rhs(lhs)
.
browser() in a magrittr pipe
Description
browser() in a magrittr pipe
Usage
browse_r(x, ...)
Arguments
x |
input |
... |
passed on to browser() |
Value
Used for side effect. Open a browser inside the pipe workflow.
Create a constant function
Description
Create a constant function
Usage
const(val = NULL)
Arguments
val |
return value of constant function (defaults to NULL) |
Value
A function always returning val
accepting arbitrary arguments (dots)
Apply a function depending on test output
Description
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.
Usage
iff(obj, test, fun, ...)
iffn(obj, test, fun, ...)
iffelse(obj, test, true_fun, false_fun, ...)
Arguments
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 |
Value
Output of function fun
applied to the original value or the
original value, depending on the test.
Examples
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)
Pipe into specific formal argument
Description
This rotates the order of the arguments such that the one named
in param_name
comes first and then calls the function.
Usage
pipe_into(x, param_name, fun, ...)
Arguments
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 |
Value
Output of fun
.
Examples
require(magrittr)
5L %>%
pipe_into("digits", format, 2.731234567)
Prefix a string of text
Description
Convenience function to use with magrittr
wraps paste0()
, hence vectorised as paste0()
Usage
prefix(text, ...)
Arguments
text |
goes to the end, rest |
... |
goes to the front. |
Value
Character. Character chain with the prefix added.
Examples
require(magrittr)
"xyz" %>%
prefix("abc")
Prefix a path
Description
file.path with arguments reversed
Usage
prefix_path(path, prefix, ...)
Arguments
path |
path to be prefixed |
prefix |
path to be appended before |
... |
passed on to file.path |
Value
file.path(prefix, path, ...)
Remove names of an object
Description
Remove names of an object
Usage
remove_names(x)
Arguments
x |
object to unname |
Value
x without names.