FiraCode icon indicating copy to clipboard operation
FiraCode copied to clipboard

Ligature request: %>% pipe operator in R

Open saralilyb opened this issue 6 years ago • 86 comments

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

saralilyb avatar Aug 10 '17 16:08 saralilyb

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

tonsky avatar Aug 11 '17 10:08 tonsky

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

saralilyb avatar Aug 12 '17 02:08 saralilyb

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

msberends avatar Sep 18 '17 06:09 msberends

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?

bcollier avatar Sep 20 '17 13:09 bcollier

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 %>%.

msberends avatar Oct 09 '17 08:10 msberends

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

tonsky avatar Oct 09 '17 09:10 tonsky

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.

MadcapJake avatar Oct 10 '17 23:10 MadcapJake

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 avatar Oct 17 '17 01:10 yeedle

There are several other popular R operators mentioned in https://github.com/tonsky/FiraCode/issues/39. Not sure what can be done with them though.

yeedle avatar Oct 17 '17 01:10 yeedle

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.

bcollier avatar Oct 19 '17 18:10 bcollier

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

j-f1 avatar Oct 19 '17 18:10 j-f1

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.

True!

I think most R developers would tell you they use the %>% in maybe 1/4 of their lines of code, it is everywhere

True!!!!

msberends avatar Oct 19 '17 18:10 msberends

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

bcollier avatar Oct 19 '17 18:10 bcollier

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)

traversc avatar Oct 30 '17 19:10 traversc

I want the ligatures to resemble original characters combination

tonsky avatar Nov 02 '17 13:11 tonsky

@bcollier

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

See above ⬆️ 🙂

j-f1 avatar Nov 02 '17 18:11 j-f1

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.

timgoodman avatar Dec 10 '17 05:12 timgoodman

Yeah, that’s beautiful! And I agree about the percentages :+1:

msberends avatar Dec 10 '17 08:12 msberends

@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.)

saralilyb avatar Dec 10 '17 17:12 saralilyb

  1. Pilcrow
  2. Manicule

dholstius avatar Dec 11 '17 15:12 dholstius

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

saralilyb avatar Dec 11 '17 17:12 saralilyb

Either seemed appropriate to me.

%>% is read “and then”; it does the same thing pseudo-linguistically as a paragraph break (that is, it separates “sentences”).

The “hand” is more of a visual analogy. There’s a rightward momentum.

On first read, I missed the point about preserving the elements of the original characters. In that case, both my suggestions are way off the mark.

On Mon, Dec 11, 2017 at 9:14 AM Jordan T. Thevenow-Harrison < [email protected]> wrote:

@holstius https://github.com/holstius You want a paragraph marker and a hand? What?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/tonsky/FiraCode/issues/473#issuecomment-350791628, or mute the thread https://github.com/notifications/unsubscribe-auth/AAyaakESgjaXanj4yI5LiNmllWKtSyb8ks5s_WLjgaJpZM4OzrQB .

dholstius avatar Dec 16 '17 16:12 dholstius

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.

bwiernik avatar Mar 22 '18 23:03 bwiernik

@tonsky Any good arguments against image ??

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

msberends avatar Mar 23 '18 19:03 msberends

@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 <>

epspi avatar Mar 28 '18 15:03 epspi

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

saralilyb avatar Mar 28 '18 15:03 saralilyb

Thanks @jtth Adding better compound pipe file-1d

epspi avatar Mar 28 '18 15:03 epspi

Alternative based on arrows instead of > < dd

epspi avatar Mar 28 '18 17:03 epspi

    1. Consistency with other languages is a good principle, so following F# is a sound choice
    1. Not to stray too far off-topic, but that would suggest that %in% follows the ancient lead of LaTeX \in which inserts the ∈ (isin) symbol, consistent with math in general.
    1. FWIW, I believe this represents some specialized type of op-amp in the EE world: image

BStudent avatar Apr 29 '18 06:04 BStudent

While some resemblance to the original characters is good (and we should follow the rule that each character in the original corresponds to some part of the ligature), I think it's more important that the meaning is conveyed (in the semantic sense, not the "what characters does it stand for" sense). For instance, != produces a ligature which doesn't bear much resemblance to an exclamation point, but that's OK because the ligature clearly represents the meaning "not equal". (Put another way, the ligature looks like the symbol that probably would have been used, if only that symbol existed as a key on the standard keyboard.)

For this reason, I still think the percentages should be de-emphasized, since they don't convey much meaning. They are just required for defining any custom binary operator in R. If not for this requirement of the R language, the author of magrittr might well have chosen |>, given that the magrittr pipe was actually inspired by F#'s pipe, |> (see here: https://www.r-statistics.com/2014/08/simpler-r-coding-with-pipes-the-present-and-future-of-the-magrittr-package/ ).

So, the magrittr pipe is not a random character sequence as suggested above; it's just an approximation of F#'s pipe that meets the rules of R. And F#'s pipe, it seems clear to me, is meant to have some resemblance to an arrow pointing in the direction of piping (and this is consistent with the fact that the reverse pipe resembles an arrow pointing the other way).

With all that said, I don't particularly care for the suggestion using diagonal arrows, because instead of using an arrow from x to f to represent "x piped into f", they use an arrow pointed off at an oblique angle, which seems less connected to the meaning. Moreover, while they increase the resemblance to the percent sign (the semantically-irrelevant part), they actually decrease the resemblance to the greater-than symbol (the semantically-important part). Even the suggestion before that, which is closer to resembling the greater-than sign, seems like it's favoring a resemblance to the percent sign a bit too much in my opinion.

So, I would still prefer the closed triangle with dots on either end, which:

  1. Resembles the greater-than sign, and more importantly resembles the meaning of the symbol: an arrow in the direction of piping

  2. Includes but deemphasizes the semantically-irrelevant percent signs

  3. Resembles the equivalent F# operator, which actually inspired the magrittr pipeline operator

timgoodman avatar May 02 '18 01:05 timgoodman