https://github.com/ThinkR-open/arpr
Advanced R Pipes
https://github.com/ThinkR-open/arpr
Last synced: 3 months ago
JSON representation
Advanced R Pipes
- Host: GitHub
- URL: https://github.com/ThinkR-open/arpr
- Owner: ThinkR-open
- Created: 2021-07-31T16:12:25.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-08-01T12:18:14.000Z (over 3 years ago)
- Last Synced: 2024-12-03T16:14:48.633Z (3 months ago)
- Language: R
- Size: 53.7 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
Awesome Lists containing this project
- jimsghstars - ThinkR-open/arpr - Advanced R Pipes (R)
README
---
output: github_document
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# arpr[](https://github.com/statnmap/arpr/actions)
The goal of arpr is to provide 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.
_Note that the {arpr} package was originally created by [Jirka Lewandowski](https://github.com/jirkalewandowski). The present repository is a fork to be able to continue development of this package, required for [{gitlabr}](https://github.com/statnmap/gitlabr)._
## Installation
You can install the released version of arpr from [CRAN](https://CRAN.R-project.org) with:
``` r
install.packages("arpr")
```And the development version from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("statnmap/arpr")
```## Examples
```{r}
library(arpr)
```- Prefix a string of text
```{r}
"xyz" %>%
prefix("abc")
```- `iff()` applies a function if and only if test is TRUE
+ otherwise return input value unchanged
+ `iffn()` is if and only if test is FALSE```{r}
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
```{r}
5L %>%
pipe_into("digits", format, 2.731234567)
```