prepare_expression: Prepare expression

View source: R/expression.R

prepare_expressionR Documentation

Prepare expression

Description

Prepare expression for evaluation in context

Usage

prepare_expression(expr, envir, db, function_value = NULL)

Arguments

expr

A quoted expression consisting of a single function call.

envir

An environment to find variables local to the expression

db

A database to store locals

function_value

Optionally, the value of a function where the expression should involve an anonymous function. In this case the function in expr will be replaced.

Details

The function_value argument here is used where expr is going to take a function that is not addressable by name; in that case we take a function itself (as "function_value"), serialise it and replace the function call with the hash. The function will be serialised into the calling environment on deserialisation.

This includes the remote possibility of a collision, but with the size of the keyspace used for hashes hopefully it's negligible.

Because of the approach used here, expr can contain anything; I'd suggest not saving the contents of the function itself, but something like NULL will work just fine:

  as.call(list(NULL, quote(a)))
  # NULL(a)

mrc-ide/context documentation built on June 4, 2023, 5:36 a.m.