languageserver icon indicating copy to clipboard operation
languageserver copied to clipboard

The pipe-bind operator =>

Open renkun-ken opened this issue 4 years ago • 2 comments
trafficstars

Currently, the pipe-bind operator => is disabled by default. It could be enabled by

Sys.setenv("_R_USE_PIPEBIND_" = "true")

It seems that the documentation does not mention it? Just to put a note here. Not suggesting that we should do anything about it at the moment.

mtcars |>
  transform(kmL = mpg / 2.35) |>
  d => lm(kmL ~ hp, data = d)

The XML parse tree of the third line is:

<expr line1="3" col1="3" line2="3" col2="29" start="102" end="128">
  <expr line1="3" col1="3" line2="3" col2="3" start="102" end="102">
    <SYMBOL line1="3" col1="3" line2="3" col2="3" start="102" end="102">d</SYMBOL>
  </expr>
  <PIPEBIND line1="3" col1="5" line2="3" col2="6" start="104" end="105">=&gt;</PIPEBIND>
  <expr line1="3" col1="8" line2="3" col2="29" start="107" end="128">
    <expr line1="3" col1="8" line2="3" col2="9" start="107" end="108">
      <SYMBOL_FUNCTION_CALL line1="3" col1="8" line2="3" col2="9" start="107" end="108">lm</SYMBOL_FUNCTION_CALL>
    </expr>
    <OP-LEFT-PAREN line1="3" col1="10" line2="3" col2="10" start="109" end="109">(</OP-LEFT-PAREN>
    <expr line1="3" col1="11" line2="3" col2="18" start="110" end="117">
      <expr line1="3" col1="11" line2="3" col2="13" start="110" end="112">
        <SYMBOL line1="3" col1="11" line2="3" col2="13" start="110" end="112">kmL</SYMBOL>
      </expr>
      <OP-TILDE line1="3" col1="15" line2="3" col2="15" start="114" end="114">~</OP-TILDE>
      <expr line1="3" col1="17" line2="3" col2="18" start="116" end="117">
        <SYMBOL line1="3" col1="17" line2="3" col2="18" start="116" end="117">hp</SYMBOL>
      </expr>
    </expr>
    <OP-COMMA line1="3" col1="19" line2="3" col2="19" start="118" end="118">,</OP-COMMA>
    <SYMBOL_SUB line1="3" col1="21" line2="3" col2="24" start="120" end="123">data</SYMBOL_SUB>
    <EQ_SUB line1="3" col1="26" line2="3" col2="26" start="125" end="125">=</EQ_SUB>
    <expr line1="3" col1="28" line2="3" col2="28" start="127" end="127">
      <SYMBOL line1="3" col1="28" line2="3" col2="28" start="127" end="127">d</SYMBOL>
    </expr>
    <OP-RIGHT-PAREN line1="3" col1="29" line2="3" col2="29" start="128" end="128">)</OP-RIGHT-PAREN>
  </expr>
</expr>

If the => operator is enabled and supported by default, we could make it behave like another kind of function and support scope completion, definition, hover, etc.

renkun-ken avatar May 29 '21 14:05 renkun-ken

I didn't even know such an operator exists.

randy3k avatar May 29 '21 21:05 randy3k

The pipe bind operator seems to have been disabled in late March, just before the R4.1.0 release, when a bug was discovered. https://github.com/wch/r-source/commit/057b599a36aaeda67a3a1dacf7cb7f6d8952ec0a https://stat.ethz.ch/pipermail/r-devel/2021-April/080646.html

eitsupi avatar May 30 '21 00:05 eitsupi