ltx_round_numbers: Round Numbers in LaTeX Tables

View source: R/ltx_round_numbers.R

ltx_round_numbersR Documentation

Round Numbers in LaTeX Tables

Description

This function takes a LaTeX table with numerical data and rounds numbers based on a specified threshold. Numbers greater than or equal to the threshold will be rounded to a specified number of decimal places (big_dec), while numbers below the threshold will be rounded to a different number of decimal places (small_dec).

Usage

ltx_round_numbers(
  latex_table,
  threshold = 10,
  big_dec = 0,
  small_dec = 2,
  print_tbl = FALSE
)

Arguments

latex_table

A character vector, data frame, or matrix representing a LaTeX table. The function will round numerical values within the LaTeX code.

threshold

A numeric value that determines the cutoff for rounding. Numbers greater than or equal to this value will be rounded to big_dec decimal places, while those below will be rounded to small_dec decimal places.

big_dec

An integer indicating the number of decimal places to round to for numbers greater than or equal to the threshold. Default is 0.

small_dec

An integer indicating the number of decimal places to round to for numbers below the threshold. Default is 2.

print_tbl

A logical flag indicating whether the modified table should be printed to the console and copied to the clipboard. Defaults to FALSE.

Value

A character vector representing the modified LaTeX table with rounded numbers.

Examples

## Not run: 
latex_table <- c(
  "\\begin{tabular}{|c|c|c|}",
  "\\hline",
  "Value A & Value B & Value C \\\\",
  "\\hline",
  "1.234 & 10.5678 & 12345.6789 \\\\",
  "2.345 & 9.8765 & 6789.0123 \\\\",
  "\\hline",
  "\\end{tabular}"
)

rounded_table <- ltx_round_numbers(latex_table, threshold = 10)
print(rounded_table)

## End(Not run)

AndreSjuve/texaid documentation built on Oct. 20, 2024, 6:17 a.m.