selkamand / fmt

R package: simple wrappers for colorising commandline output

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

fmt

The goal of fmt 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 fmt from GitHub with:

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

Usage

Preformatted messages

library(fmt)

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)
#> [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)
#> [1] "1e-04"

About

R package: simple wrappers for colorising commandline output

License:Other


Languages

Language:R 100.0%