Hacker News new | past | comments | ask | show | jobs | submit login

One of the stranger behaviours for me is that R allows you to combine infix operators with assignments, even thou there are no implemented instances of it in R itself. For example:

  `%in%<-` <- function(x, y, value) { x[x %in% y] <- value; x}

  x <- c("a", "b", "c", "d")
  x %in% c("a", "c") <- "o"
  x
  [1] "o" "b" "o" "d"
Or slightly crazier:

  `<-<-` <- function(x, y, value) paste0(y, "_", value)

  "a" -> x <- "b"
  x
  [1] "a_b"
We with Antoine Fabri created a package that uses this behaviour for some clever replacement operators [1], but beyond that I don't see where this could be useful in real practice.

[1]: https://github.com/moodymudskipper/inops




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: