Операторы сравнения

Перегрузка операторов

new_point <- function(x, y) {
  structure(list(x = x, y = y), class = "Point")
}

# Both coordinates are smaller
"<.Point" <- function(e1, e2) {
  e1$x < e2$x && e1$y < e2$y
}

# p1 > p2 is p2 < p1
">.Point" <- function(e1, e2) e2 < e1

p1 <- new_point(1, 2)
p2 <- new_point(2, 3)

b1 <- p1 > p2
# b1 = FALSE
b2 <- p1 < p2
# b2 = TRUE

cat("b1 =", b1, "\n")
cat("b2 =", b2, "\n")