Extract.Rd
Extract or replace parts of a hyper2 object
# S3 method for class 'hyper2'
x[...]
# S3 method for class 'hyper2'
x[index, ...] <- value
assign_lowlevel(x,index,value)
overwrite_lowlevel(x,value)
These methods should work as expected, although the off-by-one issue might be a gotcha.
For the extract method, H[L]
, a hyper2
object is
returned. The replace method, H[L] <- value
, the index
specifies the brackets whose powers are to be overwritten; standard
disordR
protocol is used.
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.
The extractor method returns a hyper2
object, restricted to the
elements specified
Use powers()
and brackets()
to extract a numeric vector of
powers or a list of integer vectors respectively.
Replacement idiom H[x] <- val
cannot use non-trivial recycling.
This is because the elements of H
are stored in an arbitrary
order, but the elements of val
are stored in a particular order.
Also see function hyper2_sum_numeric()
.
data(chess)
chess["Topalov"]
#> Warning: powers have nonzero sum
#> log(Topalov^30)
chess[c("Topalov","Anand")]
#> Warning: powers have nonzero sum
#> log((Anand + Topalov)^-35)
chess[c("Anand","Topalov")]
#> Warning: powers have nonzero sum
#> log((Anand + Topalov)^-35)
# 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"] <- chess["Topalov"] + 1
chess[c("Topalov","Kasparov")] <- chess[c("Topalov","Kasparov")] -1
# magrittr idiom:
# chess["Topalov"] %<>% inc
# chess[c("Topalov","Kasparov")] %<>% dec
# overwriting idiom:
H <- hyper2(list("Topalov","X"),6)
chess[] <- H
H <- icons