Learn R Programming

hyper2 (version 2.0-1)

Extract: Extract or replace parts of a hyper2 object

Description

Extract or replace parts of a hyper2 object

Usage

# S3 method for hyper2
[(x, …)
# S3 method for hyper2
[(x, index, …) <- value
assign_lowlevel(x,index,value)
overwrite_lowlevel(x,value)

Arguments

x

An object of class hyper2

Further arguments, currently ignored

index

A list with integer vector elements corresponding to the brackets whose power is to be replaced

value

Numeric vector of powers

Value

The extractor method returns a hyper2 object, restricted to the elements specified

Details

These methods should work as expected, although the off-by-one issue might be a gotcha.

For the extract method, a numeric vector is returned but the elements may be in any order (the brackets and indeed the powers are not stored in any particular order).

The replace method, H[L] <- value, the index L is a list specifying the brackets to be overwritten; argument value is not recycled unless it is of length 1.

If the index argument is missing, viz H1[] <- H2, this is a special case. Argument H1 must be a hyper2 object, and the idiom effectively executes H1[brackets(H2)] <- powers(H2), but more efficiently (note that this operation is well-defined even though the order of the brackets is arbitrary). This special case is included in the package because it has a very natural C++ expression [function overwrite() in the src/ directory] that was too neat to omit.

Altering (incrementing or decrementing) the power of a single bracket is possible using idiom like H[x] <- H[x] + 1; this is documented at Ops.hyper2, specifically hyper2_sum_numeric() and a discussion is given at increment.Rd.

Functions assign_lowlevel() and overwrite_lowlevel() are low-level helper functions and not really intended for the end-user.

See Also

hyper2,Ops.hyper2

Examples

Run this code
# NOT RUN {
data(chess)

chess["Topalov"]
chess[c("Topalov","Anand")]
chess[c("Anand","Topalov")]

# Topalov plays Anand and wins:

chess["Topalov"] <- chess["Topalov"]+1 
chess[c("Topalov","Anand")] <- chess[c("Topalov","Anand")]-1


# Topalov plays *Kasparov* and wins:
chess["Topalov"] %<>% inc
chess[c("Topalov","Kasparov")] %<>% dec


# overwriting idiom:
H <- hyper2(list("Topalov","X"),6)
chess[] <- H

# }

Run the code above in your browser using DataLab