functionMap (version 1.0.0)

func_from_expr: Get funcion(s) from a single expression. Usually a single function, but not necessarily.

Description

Get funcion(s) from a single expression. Usually a single function, but not necessarily.

Usage

func_from_expr(expr, rfile, env)

Arguments

expr
Expression to evaluate.
rfile
Name of the R file being parsed, to be able to use it in a warning message.
env
Environment to store the parsed objects in.

Value

A named list of length one. (It is easy to concatenate these lists in the caller, hence the format. A list with a name and an expression is less convenient.)

Details

If the expression has a function token and at least one assignment, then we assume that it is a function definition and evaluate it to get the function name. This is the current algorithm:
  • We evaluate the expression in env.
  • Then we check if there is anything new in env.
  • If there is a single new function, then we assume that the expression is the definition of this function, and use the function's name as expression name.
  • Otherwise (zero or more than one new functions), we assume that the expression is not a function defition and we assign it to the function body (_).

    Othewise we assume it is not a function definition.