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

Ligature request: %>% pipe operator in R #473

Open
saralilyb opened this issue Aug 10, 2017 · 87 comments
Open

Ligature request: %>% pipe operator in R #473

saralilyb opened this issue Aug 10, 2017 · 87 comments
Milestone

Comments

@saralilyb
Copy link

We use the pipe operator %>% a lot in the Tidyverse set of packages in the R programming language. It's a way of stringing together many functions, converting them from prefix to infix. It would be really nice to have a pipe ligature.

screen shot 2017-08-10 at 12 24 36 pm

@tonsky
Copy link
Owner

tonsky commented Aug 11, 2017

There was a couple of request for getting better coverage for R. I’m not against it, but can’t think of a way to improve the rendering of those

@saralilyb
Copy link
Author

I'll give a design a shot in a day or so.

@msberends
Copy link

@jtth Want to share your design idea? Would be awesome to have this in R.

@bcollier
Copy link

I would second this, and third this for colleagues who have commented on how ugly the pipe symbol is. Has anyone made progress on this?

@msberends
Copy link

Maybe something like this?
image
It's a horizontal invert of the arrow that is shown for <-, with the zeroes of the percent mark.

Better question is: does R (or RStudio that is) provide ligatures for more than 2 characters?
When typing ===, I get: image. I don't know if it will understand something in place for %>%.

@tonsky
Copy link
Owner

tonsky commented Oct 9, 2017

I don’t think R authors had anything in mind when they chose %>%. Probably it’s just a random sequence of characters. I also think it’s unfixable, visually I mean

@MadcapJake
Copy link

You could rotate the two % and connect them to form a line with a > through it. That way you would still have three-character width too.

@yeedle
Copy link

yeedle commented Oct 17, 2017

I would propose to just use F# pipe ligature for %>%. In R, custom operators are defined between percent signs, so anyone can define an operator like so %whatever% <- function(){ ...}. R's pipe operator was actually inspired by F#'s pipe and is supposed to have similar behavior. However, since arbitrary-character operators have to be wrapped in %...%, the pipe ended up looking like %>%

@yeedle
Copy link

yeedle commented Oct 17, 2017

There are several other popular R operators mentioned in #39. Not sure what can be done with them though.

@bcollier
Copy link

I would second the proposal to use the F# ligature for the R pipe %>% . With respect to the #39 issue, it would be nice to have some of the other symbols changed, but I think most R developers would tell you they use the %>% in maybe 1/4 of their lines of code, it is everywhere. I think it should have the highest priority.

There was an earlier comment that RStudio does not support three-character ligatures. I am not sure about RStudio 1.0, but in RStudio 1.1 the double headed arrow <<- correctly changes to the ligature for that symbol with Fira Code.

@j-f1
Copy link
Contributor

j-f1 commented Oct 19, 2017

The % characters should be preserved — one of the rules of Fira Code AFAIK is that all of the characters stay. What about rendering %>% like %|>%?

@msberends
Copy link

msberends commented Oct 19, 2017 via email

@bcollier
Copy link

j-f1, could you elaborate on rule about all of the characters staying?

@traversc
Copy link

traversc commented Oct 30, 2017

Would like this as well. How about removing the slashes and extra dots in the percent symbols, something like:

𐩑<𐩑

(Except maybe the dots being on the same level as the bracket, and also nicer etc)

@tonsky
Copy link
Owner

tonsky commented Nov 2, 2017

I want the ligatures to resemble original characters combination

@j-f1
Copy link
Contributor

j-f1 commented Nov 2, 2017

@bcollier

j-f1, could you elaborate on rule about all of the characters staying?

See above ⬆️ 🙂

@timgoodman
Copy link

I agree with the suggestion of something like the F# pipe ligature (right-pointing triangle). The percent signs (which are really just there because of R's requirements for custom binary operators) could be reduced to individual small circles.

Something like this:
∘▷∘
except I would stretch the triangle so it touches the circles.

@msberends
Copy link

msberends commented Dec 10, 2017 via email

@saralilyb
Copy link
Author

saralilyb commented Dec 10, 2017

@timgoodman that's a lot better than what I had in mind. As long as the midline of the ∘ aligns with the centerline of the ▷ that's great!

Kind of like
screen shot 2017-12-10 at 12 17 29 pm

(Fun design note: this induces a size illusion such that the left circle appears smaller than the right. Dunno whether it'd be better to increase the size of the leftmost circle, or just leave it.)

@dholstius
Copy link

  1. Pilcrow
  2. Manicule

@saralilyb
Copy link
Author

@holstius You want a paragraph marker and a hand? What?

@dholstius
Copy link

dholstius commented Dec 16, 2017 via email

@bwiernik
Copy link

One idea for all of these would be to drop the second o on the first % and the first o on the second %, then elongate the center operator character.

@msberends
Copy link

@tonsky Any good arguments against
image
??

Else I think most of us would say: please implement 😉

@epspi
Copy link

epspi commented Mar 28, 2018

@tonsky and others:
Any interest in some variants inspired by the ligature for $>?
screenshot 2

I thought that a compromise between no resemblance to the original characters (as in the o |> o) and a full representation of the two % signs might be to turn the / in the percent sign into an arrow. That sort of nests the arrow "within" a percent.
pipe2
pipe3

Even the compound pipe could be represented with uneven <>

@saralilyb
Copy link
Author

@epspi I like yours better than mine. Very nice! That's more clear and visually unpacks a lot better.

@epspi
Copy link

epspi commented Mar 28, 2018

Thanks @jtth
Adding better compound pipe
file-1d

@epspi
Copy link

epspi commented Mar 28, 2018

Alternative based on arrows instead of > <
dd

@tonsky
Copy link
Owner

tonsky commented Jul 3, 2019

@jzadra I’m afraid not. You’re on your own

@msberends
Copy link

as Fira already has ligatures for those symbols inside % such as %->% it seems to be a wasting of time trying to come up with new symbols every time.

Ever since tidyverse, the %>% is really something else, that could use a lot more dedication than what you’re suggesting. I think that’s clear from this (way too long) thread and the ones of #41 and #195.

@msberends
Copy link

I want the ligatures to resemble original characters combination (@tonsky)

Then maybe it’s time for an R specific fork...

@msberends
Copy link

The relevance of this discussion will perish, since we now know base R will come up with a pipe in their next version as a drop-in replacement for the magrittr/dplyr pipe.

The pipe will probably be |>.

@bwiernik
Copy link

bwiernik commented Dec 4, 2020

The pipe is only one of many inline operators in R. Anything between two % would be better with a ligature.

(Last I read, the base R pipe was not planned to have the same behavior as the magrittr pipe unfortunately)

Edit: see here for the major incompatibility https://twitter.com/bmwiernik/status/1334853345966780421?s=21

@msberends
Copy link

Whatever you like. This is the actual implementation and it looks like perfect drop-in to me: wch/r-source@a1425ad

(off-topic mode off)

@timgoodman
Copy link

@bwiernik It looks like instead of writing y %>% f(x, .), you'll be able to write y |> \(.) f(x, .) (or choose a different argument name instead of .)

@kklot
Copy link

kklot commented Jan 28, 2021

the new pipe look so nice aligned
Screenshot 2021-01-28 at 12 14 31
with ligature
Screenshot 2021-01-28 at 12 17 44

@strazto
Copy link

strazto commented May 20, 2021

The new pipe doesn't replace magrittr's pipe - pls don't forget about this

@strazto
Copy link

strazto commented May 26, 2021

Hi - I made something like @kelleyvanevert 's suggestion for "whacky" percents in my own fork -

Yes, @timgoodman, that's an excellent suggestion, I think it looks good because it's very clean :) And widening the > does seem like the Fira Code think to do, and it looks good:

fira_r_3

My implementation:

image

The actual glyphs, spacing & size certainly need work - These things look great blown up but get teensy when viewed at 12pts it turns out, and the spacing on the pipes needs to be increased.

Personally, @kelleyvanevert 's suggestion for "whacky" percents (i personally think of them as "bookend" percents) has been my favourite so far.

Discussion of approach of bookending in general

I like the idea of "bookending" the enclosed operator in general, but whatever is done at least needs to suggest the underlying character.

In the vein of @andrewcstewart 's comment:

Considering that %...% frames every type of custom operator, I wonder if they could be rendered as standard bookends to any such customer operator... something more akin to [>], except as a complete box (or something) framing the actual operator symbol. The left and right % would always render into the same framing characters, and the internal operator symbols would include both a _ floor and ceiling.

List of proposed sketches by andrewcstewart

So in the case of %>% this could render to something like [ ▷ ] (though within a full rectangle).
image

image

image

image

image

image

image

image

image

Alternatively, the standard framing characters could resemble something like an ellipses ⋯▷⋯
image

I like the principle of the suggestion, but none of the proposed ligatures do a lot to suggest the underlying characters. For me, that's a problem,

Proposed bookend that's evocative of % sign

I propose:

image

To describe it:

  • De-empathize the whole % glyph with lighter stroke width
  • Downplay the functional significance of % by shifting the "dots" to the extremities & scaling them down
  • Mirror the rightmost % glyph to invoke the idea of "closure"
  • Potential add a fine upper or lower "border" to further suggest the idea of "closure"

The above shows two alternatives, either a fully vertical stem on the % , or a diagonal stem with a steeper gradient on the % .

Personally, I think a diagonal stem tracks better as its more suggestive of the underlying character.

To extend this:

image

Alternatively, mirroring the rigthmost % might not be necessary- Much of the focus pulling of the % can be addressed by the changes to it

@strazto
Copy link

strazto commented May 26, 2021

Here it is if you want to try it out:

https://drive.google.com/drive/folders/1NAqWx8QT2KS-MrwRyFCUuaFvGpq4mP-b?usp=sharing

A few iterations of this concept:

image

image

With pipes aligned

image

%in% ligature vs in

image

@RubenVerg
Copy link

sample 1

This should be the ligature for [▷], I think.

@kalaschnik
Copy link

kalaschnik commented Nov 20, 2021

R finally got a native pipe: https://www.r-bloggers.com/2021/05/the-new-r-pipe/
Which is: |> and Fira Code renders this as:

image

Due to the character sequence |>, I would propose that magrittr implementation (%>%) should render a similar ligature, so that a user can identify "pipes", but is also able to tell if it’s the base R implementation the tidyverse one.
So maybe the proposal from @BStudent makes the most sense now: #473 (comment)

@adRn-s
Copy link

adRn-s commented Feb 15, 2022

I'm really looking forward to these ligatures. Even if they would make my R coding look like an alien sci-fi movie, they're better than nothing and surely any other R programmer will agree with me that even the worst-looking of all of these (whichever that is) is better than not having the ligature at all... any lack of aesthetics is more on R side (having to implement custom operators with 3 characters, etc.).

Sorry for necrobumping the issue, @tonsky, but since your last comment seems to be years old... Can you update/ expand your considerations on this? Thanks!

@jzadra
Copy link

jzadra commented Feb 15, 2022

Yes, I too am still hoping for a pipe ligature! This is my vote:

This preserves the % and the directionality, but also the concept of "pipe" in that it has an opening for the data to flow through.

image

@kalaschnik
Copy link

Not a fan of this one... once you see the dick, you cannot unsee it...
Moreover, it is visually far away from the native pipe ligature. Since both pipes achieve the same thing (at some point), it makes sense to both pipes share visual features. And since the native pipe (|>) was there first and is fixed in its design (see #473 (comment)), magrittr’s pipe must submit to it. Just my thoughts on that.

@msberends

This comment was marked as off-topic.

@tonsky
Copy link
Owner

tonsky commented Feb 16, 2022

I guess I can make a stylistic set for smaller percentage. Rest of the suggestions change the glyph too much, and I want it to remain recognizable. Would that make everyone happy?

Screenshot 2022-02-16 at 15 04 24

@tonsky tonsky added this to the 7 milestone Feb 16, 2022
@jzadra
Copy link

jzadra commented Feb 16, 2022

I like a connected glyph so that it looks like a single character vs 3 characters. But I'll be happy with anything, thanks for your work on this!

@kalaschnik
Copy link

kalaschnik commented Feb 16, 2022

I know this does not represent three characters in one glyph, but having the native pipe in mind, with the idea that magrittr’s pipe should be visually similar to the native one; yet, distinct; maybe this:
image
(that is the native pipe rendered in Fira Code retina with scaled-down percentage sign circles)

feel free to hate it, I am not sure what my feelings are about it anyway... but I got @jzadra point, that I would be nice to have something more ligature-like. Three disjunct characters making a glyph feels wrong somehow, yet better than nothing...

@msberends
Copy link

This has been a discussion for almost 5 years now, with numerous suggestions, ideas and opinions.

Can we please agree on the suggestion of the font designer @tonsky of today? Would help us all to actually get somewhere 🙂

@jzadra
Copy link

jzadra commented Feb 16, 2022

This has been a discussion for almost 5 years now, with numerous suggestions, ideas and opinions.

Can we please agree on the suggestion of the font designer @tonsky #473 (comment)? Would help us all to actually get somewhere 🙂

Agreed. Like I said, I'll be thrilled to have anything, and I love Firacode so I support whatever @tonsky feels is best!

@kalaschnik
Copy link

kalaschnik commented Feb 16, 2022

Absolutely agree. Ignore my shit. @tonsky thanks for adding this to a milestone!

@ryandward
Copy link

ryandward commented Feb 27, 2024

I wonder if it would be possible to write some kind of theme, in the interim, just to hide the %s on valid syntactic markers and just bold/capitalize the intervening symbol or something.

I wonder how hard this could be for vs-code or r-studio?

dataframe %>% filter(value %in% array)

could be rendered as

dataframe > filter(value in array)

@strazto
Copy link

strazto commented Feb 29, 2024

@ryandward

I wonder if it would be possible to write some kind of theme, in the interim, just to hide the %s on valid syntactic markers and just bold/capitalize the intervening symbol or something.

I wonder how hard this could be for vs-code or r-studio?

Probably not that hard, but does hiding characters with syntactical significance actually improve your code readability?

Personally I don't think hiding the glyph altogether is a particularly good idea, however, my experience is that it wasn't that hard to implement a new ligature, I think I just used the trial version of the Glyphs (Mac only) app to make my variation of this ligature.

Just to reiterate, I've implemented a version of this ligature that you can download and install:
#473 (comment)

I'm not saying it's the canonical version, or even good, but I think it's better than nothing, and certainly better than hiding characters that change your code's meaning.

@bwu62
Copy link

bwu62 commented Aug 19, 2024

Commenting here to subscribe to updates, and also to suggest this as a possibility:

image

The exact proportions should obviously be fine tuned more but I think this might be a good starting point. The ligature is both identifiable as %>% but also cohesive as a single unit.

Other iterations that could be considered if people think the ligature isn't clear enough:

  1. The circles in the percent symbols can be slightly horizontally offset from each other if desired.
  2. The bars in the percent symbols (i.e. just the first and last third of the long line) can be slightly sloped.
  3. Both of the above?

This is my draft idea, so feedback is welcome, thanks.

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

No branches or pull requests