Skip to content

Commit

Permalink
Removed suggesting magrittr, remotes, and glue
Browse files Browse the repository at this point in the history
  • Loading branch information
dipterix committed Dec 17, 2024
1 parent be14bce commit 29dde14
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 56 deletions.
7 changes: 2 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: dipsaus
Type: Package
Title: A Dipping Sauce for Data Analysis and Visualizations
Version: 0.3.0
Version: 0.2.9.9004
Authors@R: c(
person("Zhengjia", "Wang", email = "[email protected]", role = c("aut", "cre")),
person("John", "Magnotti", email = "[email protected]", role = c("ctb"),
Expand Down Expand Up @@ -55,11 +55,8 @@ Suggests:
rmarkdown,
testthat,
microbenchmark,
magrittr,
yaml,
future.callr,
remotes,
glue
future.callr
Roxygen: list(r6 = FALSE)
RoxygenNote: 7.3.2
LinkingTo:
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ dipsaus 0.3.0
=======

* Improved `lapply_async` and tries to automatically set global variable sizes when large environment and variables need to be serialized
* Removed `magrittr`, `remotes`, and `glue` from 'Suggests'

## Changes

Expand Down
3 changes: 1 addition & 2 deletions R/apply.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ iapply <- function(X, FUN, ..., .method = c('sapply', 'lapply', 'vapply')) {
#' @return Results from \code{\link[stats]{aggregate}}
#' @examples
#'
#' library(magrittr)
#' data(ToothGrowth)
#'
#' ToothGrowth %>%
#' ToothGrowth |>
#' do_aggregate(len ~ ., mean)
#'
#' @export
Expand Down
14 changes: 6 additions & 8 deletions R/language.R
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,6 @@ eval_dirty <- function(expr, env = parent.frame(), data = NULL, quoted = TRUE){
#'
#' @examples
#'
#' library(magrittr)
#'
#' ## 1. Basic usage
#'
Expand All @@ -443,19 +442,18 @@ eval_dirty <- function(expr, env = parent.frame(), data = NULL, quoted = TRUE){
#'
#' # hist and plot share the same input `rnorm(100)`
#'
#' x %>%
#' y <- x |>
#' # .expr is a function, all ... are passed as other arguments
#' no_op( hist, nclass = 10 ) %>%
#' no_op( plot, x = seq(0,1,length.out = 100) ) %>%
#' no_op( hist, nclass = 10 ) |>
#' no_op( plot, x = seq(0,1,length.out = 100) ) |>
#'
#' # Repeat the previous two plots, but with different syntax
#' no_op({ hist(., nclass = 10) }) %>%
#' no_op({ plot(x = seq(0,1,length.out = 100), y = .) }) %>%
#' no_op({ hist(., nclass = 10) }) |>
#' no_op({ plot(x = seq(0,1,length.out = 100), y = .) }) |>
#'
#' # The return statement is ignored
#'
#' no_op({ return(x + 1)}) ->
#' y
#' no_op({ return(x + 1)})
#'
#' # x is returned at the end
#'
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!-- badges: start -->
[![CRAN-version](https://www.r-pkg.org/badges/version/dipsaus)](https://CRAN.R-project.org/package=dipsaus)
[![Develop](https://dipterix.r-universe.dev/badges/dipsaus)](https://dipterix.r-universe.dev/ui#builds)
[![Develop](https://dipterix.r-universe.dev/badges/dipsaus)](https://dipterix.r-universe.dev/)
[![CRAN-version](http://cranlogs.r-pkg.org/badges/grand-total/dipsaus)](https://CRAN.R-project.org/package=dipsaus)
[![R-check](https://github.com/dipterix/dipsaus/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/dipterix/dipsaus/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
Expand Down
3 changes: 1 addition & 2 deletions man/do_aggregate.Rd

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

14 changes: 6 additions & 8 deletions man/no_op.Rd

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

51 changes: 21 additions & 30 deletions vignettes/r_expr_addons.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ knitr::opts_chunk$set(
```{r setup, echo=FALSE}
library(shiny)
library(dipsaus)
gl <- glue::glue
`%>%` <- magrittr::`%>%`
data(ToothGrowth)
```

Expand Down Expand Up @@ -75,23 +73,20 @@ li.map((el, ii) => {
});
```

`dipsaus` provides functions `iapply`, and `%=>%`, together with `glue` package, we can apply elements like this:
`dipsaus` provides functions `iapply`, and `%=>%`, for example:

```{r}
# gl <- glue::glue
# `%>%` <- magrittr::`%>%`
li <- c('A', 'T', 'G', 'C')
li %>% iapply(c(el, ii) %=>% {
gl('The index for {el} is {ii}')
li |> iapply(alist(el, ii) %=>% {
sprintf('The index for %s is %s', el, ii)
})
```

`%=>%` collect the left-hand side elements as arguments and right-hand side expression as body and create function:

```{r}
c(a, b=a^2, ...) %=>% {
alist(a, b=a^2, ...) %=>% {
print(c(a , b,...))
}
```
Expand Down Expand Up @@ -148,32 +143,29 @@ match_calls(call = tagList(

### 4. Pipe-friendly functions

Pipe functions can simplify the workflow and make R code more readable. The most popular pipe `%>%` allows the left-hand elements to be the first input of the right-hand side functions. `dipsaus` provides several pipe-friendly functions.
Pipe functions can simplify the workflow and make R code more readable. The popular pipe operator `%>%` (or `|>` after R 4.0) allows the left-hand elements to be the first input of the right-hand side functions. `dipsaus` provides several pipe-friendly functions.

#### No-operations `no_op`

`no_op` takes whatever input in, and returns the input, with side effects. For example, we want to plot the results from the pipe and continue the analysis, usually this is what happens:

```{r, eval=FALSE}
x %>%
do_something(...) ->
x_tmp
x_tmp <- x |>
do_something(...)
plot(x_tmp)
x_tmp %>%
do_others(...) ->
final_results
final_results <- x_tmp |>
do_others(...)
```

With `no_op`, the pipe becomes:

```{r, eval=FALSE}
x %>%
do_something(...) %>%
no_op(plot, ylim = c(0,100)) %>%
do_others(...) ->
final_results
final_results <- x |>
do_something(...) |>
no_op(plot, ylim = c(0,100)) |>
do_others(...)
```

Here's an example
Expand All @@ -182,25 +174,24 @@ Here's an example
par(mfrow = c(1,2))
(1:10) %>%
iapply(c(el, ii) %=>% {
result <- (1:10) |>
iapply(alist(el, ii) %=>% {
rnorm(20, el, ii)
}, simplify = FALSE) %>%
unlist %>%
}, simplify = FALSE) |>
unlist() |>
# Begin no-ops, result will not change
no_op({
# Use expression and "." to refer the data
print(summary(.))
}) %>%
}) |>
no_op(
# Use function and pass ... to function
plot, x = seq(0,1,length.out = 200),
type = 'p', ylim = c(-20,20), pch = 16,
xlab = 'Time', ylab = 'Value', las = 1
) %>%
no_op(hist, xlab = 'Values', main = 'Histogram') ->
result
) |>
no_op(hist, xlab = 'Values', main = 'Histogram')
str(result)
```
Expand All @@ -217,7 +208,7 @@ aggregate(formula, data, FUN, ..., subset, na.action = na.omit)
`do_aggregate` allows the first element to be data frames while using formula:

```{r}
ToothGrowth %>%
ToothGrowth |>
do_aggregate(len ~ ., mean)
```

Expand Down

0 comments on commit 29dde14

Please sign in to comment.