Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unification of pipe and fastpipe #1

Closed
moodymudskipper opened this issue Sep 30, 2019 · 7 comments
Closed

Unification of pipe and fastpipe #1

moodymudskipper opened this issue Sep 30, 2019 · 7 comments

Comments

@moodymudskipper
Copy link
Owner

We could incorporate the fast pipe in pipe.

It could be named %>>% and would have a special class and a good disclaimer.

We'd remove the code handling functional sequences and compound operator (and thus the awkward option), so it'd be easy, we'd just use %>>% for programming and when we'd need robust behavior for lazy evaluation.

We'd also add fast pipes %T>>%, %$>>%, and %S>>%.

It's almost as easy to type, and no risk of confusion regarding functional sequences and compound ops.

And when we actually want to pipe . we can use %>>% so an equivalent to functional sequences will be to use ~ . %>>% fun() in purrr style formulas.

@moodymudskipper
Copy link
Owner Author

It should be as easy as :

`%>>%` <- function(lhs, rhs) {
  rhs <- insert_dot(substitute(rhs))
  eval(rhs, envir = list(`.` = lhs), enclos = parent.frame())
}
`%T>>%` <-  function(lhs, rhs) {
  rhs <- insert_dot(substitute(rhs))
  eval(rhs, envir = list(`.` = lhs), enclos = parent.frame())
  lhs
}

`%$>>%` <- function(lhs, rhs) {
  rhs <- substitute(with(.,rhs))
  eval(rhs, envir = list(`.` = lhs), enclos = parent.frame())
 }

`%S>>%` <- function(lhs, rhs) {
  rhs <- insert_dot(substitute(rhs))
  # splice
  rhs <- substitute(rlang::expr(rhs),list(rhs=rhs))
  rhs <- eval(rhs, envir = list(`.` = lhs), enclos = parent.frame())
  # eval
  eval(rhs, envir = list(`.` = lhs), enclos = parent.frame())
}

And maybe an alias %$>% for %$% as it is always confusing.

@moodymudskipper
Copy link
Owner Author

It also need a fast_pipe class, and I guess we could incorporate a way to create a fast pipe with new_pipe() too but I don't see a nice way to do it.

Maybe discard new_pipe() and have new_standard_pipe(), new_compound_pipe() and new_fast_pipe() ?

That wouldn't be bad, because the compound_fun = NULL arg is a bit confusing and the user will most probably only need new_standard_pipe() and it's better not to confuse them with other arguments.

And this way new_compound_pipe() can have a default compound_fun = function(lhs, res) {} instead of NULL?

@moodymudskipper
Copy link
Owner Author

One problem is that I wanted a lightweight package with only one simple pipe, and here I have a lot, so we'll have to decide if we really move most to a pipes package, and which we keep here.

I'm thinking maybe it's not that bad to have all here as long as we trim down the list of the pipes that exist in current pipes package.

@moodymudskipper
Copy link
Owner Author

current list :

%D>% : Debug the pipe chain at the relevant step
%V>% : Use View() on the output
%L>% : Log the relevant call and execution time to the console
%P>% : Use print() on the output
%summary>% : Print the summary() off the output
%glimpse>% : Use tibble::glimpse() on the output
%skim>% : Use skimr::skim() on the output
%ae>% : Use all.equal on the input and output
%compare>% : Use arsenal::compare() and open the report of the differences in the default browser window
%gg>% : Apply the rhs to the data of a gg object and return the modified gg object
%nowarn>% : Silence warnings
%nomsg>% : Silence messages
%strict>% : Fail on warning
%try>% : Try, and in case of failure prints error and returns input
%quietly>% : Use purrr::quietly() to capture outputs of all kind and print them
%D>% : remove as we have `%B>%` which is better
%V>% : keep ?
%L>% : keep
%P>% : keep ? A bit redundant with `%L>%`
%summary>% : remove, show as example
%glimpse>% : remove
%skim>% : remove
%ae>% : remove as it's not good enough so far, but a comparing pipe would be really good.
%compare>% : remove but can take as inspiration for comparing pipe
%gg>% : keep ? note that we don't need to import ggplot
%nowarn>% : keep ?
%nomsg>% : keep ?
%strict>% : keep ?
%try>% : remove
%quietly>% : remove

So that's only %L>% for sure, but %gg>% would be nice, and %nowarn>% is useful too,

@moodymudskipper
Copy link
Owner Author

Will need also to copy and paste most of the tests with %>>%, would be good to clean them up and complete them a bit first.

@moodymudskipper
Copy link
Owner Author

maybe get inspiration from %D>% for a %B>>% pipe so we can browse with this one too ? But We can use %B>% in fast pipe chains too... It just will show only one step.

@moodymudskipper
Copy link
Owner Author

not sure about this in the end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant