as_result: Results with Rounding

View source: R/result.R

as_resultR Documentation

Results with Rounding

Description

Rounds x according to digits and the rounding function FUN, and sets a tolerance for the result. If tol is not provided, it defaults to 2*10^(-digits).

Usage

as_result(x, digits, tol = NA, FUN = round2)

tol(x)

rounded(x)

val(x)

digits(x)

as_res(x, digits, tol = NA, FUN = round2)

tolerance(x)

Arguments

x

numeric: value to round

digits

integer or character: Number of digits to use for rounding, see Details.

tol

numeric: tolerance for the result (defaults to 2*10^(-digits) if NA)

FUN

function: rounding function (default: internal round2())

Details

Results with Rounding

Creates a structured result with a numeric value rounded according to specified digits, an optional tolerance, and a rounding function.

By default, rounding is performed using an internal function round2(), which is similar to exams::round2(), but users should not call it directly. You can also supply a custom rounding function via the FUN argument.

If digits is a character, the following abbreviations are recognized:

"integer"

digits = 0

"%"

digits = 2

"probability"

digits = 4

Partial matching of these names is allowed.

Value

A list of class result containing:

x

Original value

r

Rounded value

digits

Digits used for rounding

tol

Tolerance for the result

Examples

x <- as_result(1/3, "probability")
tol(x)
rounded(x)
digits(x)

exams.forge documentation built on Aug. 21, 2025, 5:41 p.m.