Learn R Programming

rPref (version 0.6)

show.pref: Partial Evaluation and String 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 output of preferences.

Usage

show.pref(p, df = NULL)

pref.str(p, df = NULL)

eval.pref(p, df = NULL)

## S3 method for class 'preference': as.character(x, ...)

Arguments

p,x
The preference to be shown or partially evaluated.
df
(optional) A dataframe on which the preference operates.
...
Optional arguments passed to as.character.

Partial Evaluation Before String Output

The functions show.pref and pref.str have the optional paramter df. If this paramter 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 asshow.pref(p, df)

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.

The function eval.pref (with given dataframe 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 dataframe df does not matter; only names(df) is used to get the "free variables" in p.

Examples

Run this code
f <- function(x) 2*x
p <- true(cyl == f(1))

# prints 'cyl == f(x)'
p

# prints 'cyl == 2'
show.pref(p, mtcars)
eval.pref(p, mtcars)

Run the code above in your browser using DataLab