fractional (version 0.1.3)

fractional: Representation of a numeric vector in vulgar fractional form

Description

The object is flagged so that if it is coerced to character, or printed, the numerical quantities are represented by a rational approximation. In other respects the numerical object behaves as normally.

Usage

fractional(x, eps = 1e-06, maxConv = 20, sync = FALSE)
"as.character"(x, eps = attr(x, "eps"), maxConv = attr(x, "maxConv"), ...)
"print"(x, ...)
"print"(x, ...)

Arguments

x
A numeric object
eps
An absolute error tolerance
maxConv
An upper limit on the number of convergents to use in the continued fractions.
sync
A logical value. Should the numerical value be changed to match the rational approximation, as closely as possible with floating point, (TRUE)? Or, should it be left and used in its original state (FALSE)?
...
Currently ignored.

Value

A numeric object of class "fractional".

Methods (by generic)

  • as.character: S3 method for coercion to character, producing an object inheriting from class "charFrac"
  • print: Print method for class "charFrac" objects, unquoted.
  • print: Print method for "fractional" objects

See Also

fractions for a similar functionality.

Examples

Run this code
(M <- solve(cbind(1, contr.helmert(5))))
(Mf <- fractional(M))     ## print method right justifies
(Mc <- as.character(Mf))  ## print method left justifies
(Mn <- numerical(Mc))
set.seed(123)
u <- matrix(runif(10), 2, 5)
(uf <- fractional(u))
(us <- fractional(u, sync = TRUE))  ## may look different!
unfractional(uf) - unfractional(us)  ## rational approximation errors

Run the code above in your browser using DataCamp Workspace