R: Partial Evaluation and String/Expression Output of...
show.pref
R Documentation
Partial Evaluation and String/Expression Output of Preferences
Description
Functions to substitute variables and functions in preferences
which can be calculated before the preference is evaluated on a data frame.
This is especially used for the string/expression output of preferences.
The preference to be shown or partially evaluated.
df
(optional) A data frame on which the preference operates.
Details
The function pref.str (or as.character(p) for a preference p) returns the preference string
while show.pref outputs it directly to the console, preceded by '[Preference]'.
If df is specified, then a partial evaluation of the preference is done before converting it to a string.
With as.expression(p) the R code for constructing a given preference is given.
The function eval.pref (with given data frame df) partially evaluates the internal preference expression and
returns again a preference object. All expressions in p are evaluated in the environment
where p was defined, except the the column names in df (which are potential attributes in p)
and except the special variable df__, which accesses the entire data set (see psel).
The content of the data frame df does not matter; only names(df) is used to get the "free variables" in p.
Partial Evaluation Before String Output
The functions show.pref and pref.str have the optional parameter df.
If this parameter is given, these functions call eval.pref before they output or return the preference string.
The following equalities hold:
as.character(eval.pref(p, df)) == pref.str(p, df)
show(eval.pref(p, df)) produces the same console output as show.pref(p, df)
See Also
See general_pref for more utility functions for preferences.
Examples
f <- function(x) 2*x
p <- true(cyl == f(1))
# prints 'true(cyl == f(1))'
p
# prints 'true(cyl == 2)'
show.pref(p, mtcars)
eval.pref(p, mtcars)