项目作者: ebeneditos

项目描述 :
Basic Infix Binary Operators
高级语言: R
项目地址: git://github.com/ebeneditos/infix.git
创建时间: 2018-12-07T19:01:17Z
项目社区:https://github.com/ebeneditos/infix

开源协议:GNU General Public License v3.0

下载


infix

Basic Infix Binary Operators

CRAN
Downloads
Travis CI Status
AppVeyor build status
Codecov
License

Contains a number of infix binary operators that may be useful in day to day practices.

Installation

You can install infix from CRAN:

  1. install.packages("infix")

Or the development version from GitHub:

  1. # install.packages("devtools")
  2. devtools::install_github("ebeneditos/infix")

Usage

You can find a full list of operators running ?infix, but here there are a few examples:

  1. library(infix)
  2. # tryExcept (%except%)
  3. {foo <- "foo"} %except% {foo <- "foo bar"}
  4. print(foo) # "foo"
  5. { foo <- "foo"
  6. stop()
  7. } %except% {
  8. foo <- "foo bar"
  9. }
  10. print(foo) # "foo bar"
  11. # paste0 (%+%)
  12. "01" %+% "jan" %+% "1970" # returns "01jan1970"
  13. # file.path (%//%)
  14. "home" %//% "dir" # returns "home/dir"
  15. # nomatch (%!in%)
  16. 4 %!in% 1:3 # returns TRUE
  17. # nil (%||%)
  18. 1 %||% 2 # returns 1
  19. NULL %||% 2 # returns 2
  20. # functions logic (%&%, %|% and %xor%)
  21. is.null.na <- is.null %|% is.na
  22. all(is.null.na(NA), is.null.na(NULL)) # returns TRUE

Also, magrittr pipe-operators (such as %>%) are imported.