rossellhayes / fracture
1
#' Style a fracture with superscripts and subscripts
2
#'
3
#' Uses Unicode superscripts and subscripts to format a fracture.
4
#'
5
#' @param fracture A [fracture] or a vector to be passed to [fracture()].
6
#' @param ... Additional arguments passed to [fracture()].
7
#'
8
#' @return `fracture` with numerators formatted with Unicode superscripts and
9
#'   denominators formatted with Unicode subscripts.
10
#' @export
11
#'
12
#' @example examples/frac_style.R
13

14
frac_style <- function(fracture, ...) {
15 1
  if (!is.fracture(fracture)) {fracture <- fracture(fracture, ...)}
16 1
  frac_style <- as.frac_mat(fracture)
17

18 1
  frac_style[] <- as.character(frac_style)
19 1
  frac_style["numerator", ] <- vapply(
20 1
    strsplit(frac_style["numerator", ], ""),
21 1
    function(x) paste(numerators[as.numeric(x) + 1], collapse = ""),
22 1
    character(1)
23
  )
24 1
  frac_style["denominator", ] <- vapply(
25 1
    strsplit(frac_style["denominator", ], ""),
26 1
    function(x) paste(denominators[as.numeric(x) + 1], collapse = ""),
27 1
    character(1)
28
  )
29

30 1
  as.fracture_paste(frac_style)
31
}

Read our documentation on viewing source code .

Loading