R: Utility Functions for Preferences

general_pref {rPref} | R Documentation

## Utility Functions for Preferences

### Description

Collection of some useful functions which are applicable to all preference objects.

### Usage

    empty()

    is.empty_pref(x)

    ## S4 method for signature 'preference'
    length(x)

    is.preference(x)

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

    ## S4 method for signature 'preference'
    assoc.df(x)

    ## S4 replacement method for signature 'preference'
    assoc.df(x) <- value

### Arguments

`x` | A preference, or, for `is.preference`, an object to be tested if it is an (empty) preference.
`...` | Optional arguments passed to `as.expression`.
`value` | A data frame to associate with a preference object.

### Details

The empty preference `empty()` is a neutral element for the complex preference compositions `{*, &, +}`. It holds that `empty() * p` and `empty() & p` is equal to `p` for all preferences `p`.

The function `length(p)` returns the term length of the preference term `p` which is defined as the number of base preferences in a complex preference term. The empty preference `empty()` has length 0, and all base preferences have length 1.

With `as.expression(p)` for a preference `p` the call to the preference is constructed. This means, `eval(as.expression(p))` returns the preference `p`, evaluated in the current environment.

The function `is.empty_pref` returns `TRUE` if `x` is the empty preference object `empty()` and `FALSE` otherwise.

With `assoc.df` the associated data frame of a preference can be retrieved or set. Setting the associated data frame means that a partial evaluation based on this data frame is done. See `show.pref` for details on partial evaluation of preferences. Next, the preference is linked to that data frame, such that `peval(p)` can be used instead of `psel(df, p)`. It returns `NULL` if no data frame is associated. Use `set.assoc.df(NULL)` to delete an associated data frame.

### See Also

See `base_pref` for the construction of base preferences, and `complex_pref` for the construction of complex preferences. See `show.pref` for string output and partial evaluation of preference terms.

### Examples

    # Same as low(a) * low(b)
    p <- low(a) * low(b) * empty()

    # returns 2, as empty() does not count
    length(p)

    # the preference expression (without empty())
    as.expression(p)

[Package rPref version 1.3 Index]