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.
You can install the development version of fmt from GitHub with:
# install.packages("devtools")
devtools::install_github("selkamand/fmt")
library(fmt)
You can also fmt
type
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"))
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"