Learn R Programming

rPref (version 0.7)

general_pref: General Preferences

Description

Collection of some useful functions applicable to base preferences as well as complex preferences.

Usage

empty()

is.empty_pref(x)

## S3 method for class 'preference': length(x)

is.preference(x)

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

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

Arguments

x
A preference, or, for is.preference, an object to be tested if it is an (empty) preference.
...
Optional arguments passed to as.character and as.expression.

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.

See Also

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

Examples

Run this code
# 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)

Run the code above in your browser using DataLab