parse_fraction: Parse a String as a Fraction

Description Usage Arguments Value Note Examples

View source: R/fractions.R

Description

When provided a string representing a fraction, parse_fraction will parse the provided string to create a list with the class fraction applied to it. This will allow the parsed fraction to be used in subsequent calculations.

Usage

1
parse_fraction(string, improper = TRUE, reduce = TRUE)

Arguments

string

The input character to be parsed.

improper

Logical. Should the result be kept as an improper fraction? Defaults to TRUE.

reduce

Logical. Should unreduced fractions be simplified? Defaults to TRUE.

Value

A formatted list printed with print.fraction(). The list includes four elements:

Note

The string can be entered either as an improper fraction (for example, "5/2") or as a simplified fraction (for example, "2 1/2"). Depending on how it is entered, the resulting list will have a value in "whole" or "whole" will be NULL.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
parse_fraction("4/4")
parse_fraction("4/4", reduce = FALSE)

parse_fraction("32/4")
parse_fraction("34/4", reduce = FALSE)
parse_fraction("34/4", reduce = TRUE)
parse_fraction("34/4", improper = FALSE)

parse_fraction("4 2/4")
parse_fraction("4 2/4", TRUE, FALSE)
parse_fraction("4 2/4", FALSE)

mrdwab/mathrrr documentation built on July 20, 2020, 11:14 p.m.