Learn R Programming

spray (version 1.0-27)

print.spray: Print methods for spray objects

Description

Print methods for spray objects with options for printing in matrix form or multivariate polynomial form

Usage

# S3 method for spray
print(x, ...)
print_spray_matrixform(S)
print_spray_polyform(S,give=FALSE)
printedvalue(v)

Value

Returns its argument invisibly.

Arguments

x,S

spray object

give

Boolean, with default FALSE meaning to print the value of S, and TRUE meaning to return a string (without nice formatting); used in as.character.spray()

v

Numeric vector

...

Further arguments (currently ignored)

Author

Robin K. S. Hankin

Details

The print method, print.spray(), dispatches to helper functions print_spray_matrixform() and print_spray_polyform() depending on the value of option polyform; see the examples section.

Option sprayvars is a character vector with entries corresponding to the variable names for printing. The sprayvars option has no algebraic significance: all it does is affect the print method.

Function printedvalue() is a low-level helper function that takes a numeric argument and returns the value as printed (thus respecting options scipen and digits). It uses gsub() to remove the “[1]” produced by capture.output(). The code is not perfect and sometimes fails (for reasons that are not clear to me) when applied to large objects on the Rstudio console.

Note that printing a spray object (in either matrix form or polynomial form) generally takes much longer than calculating it.

Examples

Run this code

(a <- spray(diag(3)))


options(polyform = FALSE)
a^3

options(polyform = TRUE)
a^3


options(sprayvars=letters)
a <- diag(26)
spray(a)

## Following example from mpoly:
a[1 + cbind(0:25, 1:26) %% 26] <- 2
spray(a)

Run the code above in your browser using DataLab