selkamand / utilitybeltfmt

Easy text formatting in R

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

utilitybeltfmt

Lifecycle: superseded


This package has been superseded by fmt

The goal of utilitybeltfmt is to colorise R console output with minimal effort. Preconfigured colorisations/symbol prefixes are provided for errors, warnings, and info messages.

Installation

You can install the development version of utilitybeltfmt from GitHub with:

# install.packages("devtools")
devtools::install_github("selkamand/utilitybeltfmt")

Usage

Preformatted messages

library(utilitybeltfmt)

Formatting options

Format Strings

You can also fmttype functions to produce formatted (colorised) strings. These functions are useful for assertion messages.

# Example assertion
if(condition == true){
  stop(fmterror("This is an error"))
}

# There are also options for warnings, info & bold text
message(fmterror("This is an error"))
message(fmtwarning("This is a warning"))
message(fmtinfo("This text is informative"))
message(fmtbold("This text is bold"))

Format Numbers

Convert to percentage with fmtpercent or scientific notation fmtscientific. Note these functions return characters (NOT numerics!).

fmtpercent(97.8, decimal_places = 2)
#> Warning: `fmtpercent()` was deprecated in utilitybeltfmt 0.0.0.9000.
#> Please use `fmt::fmtpercent()` instead.
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated.
#> [1] "97.80%"
fmtpercent(97.8, decimal_places = 0)
#> [1] "98%"
fmtpercent(0.12, decimal_places = 1, proportion = TRUE)
#> [1] "12.0%"

fmtscientific(0.0001)
#> Warning: `fmtscientific()` was deprecated in utilitybeltfmt 0.0.0.9000.
#> Please use `fmt::fmtscientific()` instead.
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated.
#> [1] "1e-04"

About

Easy text formatting in R

License:Other


Languages

Language:R 100.0%