R: Partial Evaluation and String Output of Preferences

show.pref {rPref} | R Documentation

## 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 and character output of preferences.

### Usage

    show.pref(p, df = NULL)

    ## S4 method for signature 'preference'
    as.character(x, ...)

    pref.str(p, df = NULL)

    partial.eval.pref(p, df = NULL)

### Arguments

`p, x` | The preference to be shown or partially evaluated.
`df` | (optional) A data frame on which the preference operates. Used for partial evaluation.
`...` | Optional arguments passed to `as.character`.

### 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 `partial.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`.

If `p` has already an associated data frame (see `assoc.df`), then a partial evaluation was already done when the data frame was associated. In this case, the `df` parameter should not be used. The association will not be changed if one of these function are called with a given data frame on a preference object having an associated data frame.

### 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 `partial.eval.pref` before they output or return the preference string. The following equalities hold:

- `as.character(partial.eval.pref(p, df)) == pref.str(p, df)`

- `show(partial.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)
    partial.eval.pref(p, mtcars)

[Package rPref version 1.3 Index]