tests/testthat/references/operators.R

# ------------------------------------------------------------------------------
# relational

a == b
a > b
a < b
a >= b
a <= b
a != b

a ==
  b

# ------------------------------------------------------------------------------
# arithmetic

a + b
a - b
a * b
a / b
a ^ b
a ** b

a +
  b

a *
  b

# ------------------------------------------------------------------------------
# unary

!a
+a
-a
foo(!a, +b)
foo(-a, bar)

!
  a
-  b

# ------------------------------------------------------------------------------
# precedence

2+a*2
2+a+2
!a + !b
a <= 2 && 2 >= d
a[1] <- foo || bar
a && b(c) && d
val <- foo %>% bar(1) %>% baz()

# ------------------------------------------------------------------------------
# specials

x %% y
x %/% y
x %+% y
x %>% y
x %>% 2 %>% z
x %some text% y
x %//% y

# ------------------------------------------------------------------------------
# pipe

x |> print()

x |> foo() %>% bar() |> baz()

x |> foo() |> bar() + baz()

x |> {function(x) x}()

# ------------------------------------------------------------------------------
# pipe placeholder

foo |> bar(x, y = _)
foo |> bar() |> baz(data = _)


# ------------------------------------------------------------------------------
# assignment

x <- 1
x = 1
x := 1
x <<- 1
1 ->> x
1 -> x
x <- y(1)
y(1) -> x

# ------------------------------------------------------------------------------
# colon

1:2
(1 + 1):-5

# ------------------------------------------------------------------------------
# formulas

~x
y~x

# ------------------------------------------------------------------------------
# help

a ? b
a ? b <- 1
?a

Try the treesitter.r package in your browser

Any scripts or data that you put into this service are public.

treesitter.r documentation built on Sept. 12, 2024, 7:06 a.m.