Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/b-rodrigues/loud
https://github.com/b-rodrigues/loud
Last synced: 8 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/b-rodrigues/loud
- Owner: b-rodrigues
- License: gpl-3.0
- Created: 2022-02-18T12:36:53.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-04-01T09:16:53.000Z (over 2 years ago)
- Last Synced: 2024-08-13T07:11:48.872Z (4 months ago)
- Language: R
- Homepage: https://b-rodrigues.github.io/loud/
- Size: 3.8 MB
- Stars: 6
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE.md
Awesome Lists containing this project
- jimsghstars - b-rodrigues/loud - (R)
README
---
output: github_document
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```# loud
Easily add logs to your functions.
## Installation
You can install the development version of loud from [GitHub](https://github.com/) with:
```{r, eval = FALSE}
# install.packages("devtools")
devtools::install_github("b-rodrigues/loud@release_0.1.1")
```## Example
This is a basic example which shows you how to solve a common problem:
```{r example}
library(loud)loud_sqrt <- loudly(sqrt)
loud_sqrt(1:5)
```You can also use the native R pipe:
```{r}
loud_sqrt <- loudly(sqrt)
loud_exp <- loudly(exp)
loud_mean <- loudly(mean)1:10 |>
loud_sqrt() |>
bind_loudly(loud_exp) |>
bind_loudly(loud_mean)```
`bind_loudly()` is used to pass the output from one decorated function to the next.
`loudly()` works with any function:
```{r}
library(dplyr)loud_group_by <- loudly(group_by)
loud_select <- loudly(select)
loud_summarise <- loudly(summarise)
loud_filter <- loudly(filter)starwars %>%
loud_select(height, mass, species, sex) %>%
bind_loudly(loud_group_by, species, sex) %>%
bind_loudly(loud_filter, sex != "male") %>%
bind_loudly(loud_summarise,
mass = mean(mass, na.rm = TRUE)
)```
You could also use the `%>=%` pipe instead of `bind_loudly()`:
```{r}
starwars %>%
loud_value() %>=%
loud_select(height, mass, species, sex) %>=%
loud_group_by(species, sex) %>=%
loud_filter(sex != "male") %>=%
loud_summarise(mass = mean(mass, na.rm = TRUE))```
Errors, warnings, and messages also get caught and composed in the log:
```{r}
starwars %>%
loud_value() %>=%
loud_select(height, mass, species, sex) %>=%
loud_group_by(species, sx) %>=% # type, "sx" instead of "sex"
loud_filter(sex != "male") %>=%
loud_summarise(mass = mean(mass, na.rm = TRUE))```
## Caution
This packages is in early development and basically is held together with string and j*zz. Use at
your own peril, but it has some tests now that pass, so it shouldn't be too bad. That being said,
if you used it for serious work and it turns out that you house caught on fire, that's on you.## Thanks
I’d like to thank [armcn](https://github.com/armcn), [Kupac](https://github.com/Kupac) for their
blog posts ([here](https://kupac.gitlab.io/biofunctor/2019/05/25/maybe-monad-in-r/)) and
packages ([maybe](https://armcn.github.io/maybe/)) which inspired me to build this package.