File: function_type.R

package info (click to toggle)
r-cran-promises 1.2.0.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,420 kB
  • sloc: cpp: 45; sh: 13; makefile: 2
file content (21 lines) | stat: -rw-r--r-- 586 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Determine whether an expression counts as a function in a magrittr chain.
#
# @param a non-evaluated expression.
# @return logical - TRUE if expr represents a function, FALSE otherwise.
is_function <- function(expr)
{
  is.symbol(expr) || is.function(expr)
}

# Prepare a magrittr rhs of funtion type
#
# @param a an expression which passes `is_function`
# @return an expression prepared for functional sequence construction.
prepare_function <- function(f)
{
  as.call(list(f, quote(.)))
}

is_lambda <- function(expr) {
  is.call(expr) && identical(expr[[1L]], quote(`function`))
}