| Title: | Neat Data for Presentation |
|---|---|
| Description: | Utilities for unambiguous, neat and legible representation of data (date, time stamp, numbers, percentages and strings) for presentation of analysis , aiming for elegance and consistency. The purpose of this package is to format data, that is better for presentation and any automation jobs that reports numbers. |
| Authors: | Shivaprakash Suresh [aut, cre, cph] |
| Maintainer: | Shivaprakash Suresh <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.3.0 |
| Built: | 2026-05-31 07:30:35 UTC |
| Source: | https://github.com/dswithai/neatr |
Smart format function that infers type and applies neatR formatting.
f(x, format_type = NULL, ...)f(x, format_type = NULL, ...)
x |
Input data to format. |
format_type |
Explicit format type: 'day', 'date', 'ts', 'number', 'percent', 'string'. If NULL, type is inferred. |
... |
Additional parameters passed to the underlying formatting functions. |
Formatted string or vector of strings.
neat representation of dates
ndate( date, show_weekday = TRUE, show_month_year = FALSE, display_weekday = NULL, is_month = NULL )ndate( date, show_weekday = TRUE, show_month_year = FALSE, display_weekday = NULL, is_month = NULL )
date |
a Date or POSIX time stamp |
show_weekday |
a Boolean. Whether the weekday of the date to be included. |
show_month_year |
a Boolean variable representing if the date represents month. If this set to TRUE, the function returns 'MMMM'YY' as the output which is a neater representation of month. |
display_weekday |
Deprecated. Use 'show_weekday' instead. |
is_month |
Deprecated. Use 'show_month_year' instead. |
String representation of the date
# Neat representation of current date x <- Sys.Date() ndate(x) # Neat representation of current date with day of week. ndate(x, show_weekday = FALSE) # Neat representation of current date with only month and year ndate(x, show_weekday = FALSE, show_month_year = TRUE)# Neat representation of current date x <- Sys.Date() ndate(x) # Neat representation of current date with day of week. ndate(x, show_weekday = FALSE) # Neat representation of current date with only month and year ndate(x, show_weekday = FALSE, show_month_year = TRUE)
neat alias of the week day with reference based on current date
nday(date, show_relative_day = FALSE, reference_alias = NULL)nday(date, show_relative_day = FALSE, reference_alias = NULL)
date |
a Date or POSIX time stamp |
show_relative_day |
a Boolean. If set to TRUE, a reference alias of week day is shown based on current date such as Today/Yesterday/Tomorrow/Last/Coming. |
reference_alias |
Deprecated. Use 'show_relative_day' instead. |
week day of the date in a readable format with reference alias based on current date
# Get day of the week of current date without reference alias x <- Sys.Date() nday(x, show_relative_day = FALSE) # Get day of the week with reference alias nday(x, show_relative_day = TRUE)# Get day of the week of current date without reference alias x <- Sys.Date() nday(x, show_relative_day = FALSE) # Get day of the week with reference alias nday(x, show_relative_day = TRUE)
neat representation of numbers
nnumber( number, digits = 1, unit = "custom", unit_labels = list(thousand = "K", million = "Mn", billion = "Bn", trillion = "Tn"), prefix = "", suffix = "", thousand_separator = "," )nnumber( number, digits = 1, unit = "custom", unit_labels = list(thousand = "K", million = "Mn", billion = "Bn", trillion = "Tn"), prefix = "", suffix = "", thousand_separator = "," )
number |
an integer or double. |
digits |
number of digits to round-off. Default value is 1. |
unit |
unit to which the number to be converted. See examples below. |
unit_labels |
a vector of strings (optional) that gives the unit label for thousand, million, billion and trillion. |
prefix |
a string (optional) that can be prepended to the formatted number. |
suffix |
a string (optional) that can be appended at the end of the formatted number. |
thousand_separator |
a character (optional) that can be used to chunk thousands to display large numbers. Default is set as comma, dot, comma or underscore can be used. |
String representation of numbers with suffix denoting K for thousands,Mn for millions, Bn for billions, Tn for trillions. A number lower than thousand is represented as it is.
x <- c( 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 ) nnumber(x) nnumber(123456789.123456, digits = 1) nnumber(123456789.123456, digits = 1, unit = "Mn", prefix = "$")x <- c( 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 ) nnumber(x) nnumber(123456789.123456, digits = 1) nnumber(123456789.123456, digits = 1, unit = "Mn", prefix = "$")
neat representation of percentage
npercent( percent, is_ratio = TRUE, digits = 1, show_plus_sign = TRUE, show_growth_factor = FALSE, show_bps = FALSE, is_decimal = NULL, plus_sign = NULL, factor_out = NULL, basis_points_out = NULL )npercent( percent, is_ratio = TRUE, digits = 1, show_plus_sign = TRUE, show_growth_factor = FALSE, show_bps = FALSE, is_decimal = NULL, plus_sign = NULL, factor_out = NULL, basis_points_out = NULL )
percent |
an integer or double representing percentage |
is_ratio |
a Boolean variable. If the percent is raw, the value to set as TRUE. See examples below. If the percent variable is already pre-multiplied by 100 then the value to be set as FALSE. |
digits |
number of digits to round-off |
show_plus_sign |
a Boolean variable. If the percent is positive then setting show_plus_sign = TRUE, includes an explicit + sign before the percent |
show_growth_factor |
an optional Boolean variable. |
show_bps |
an optional parameter to get the percentage as basis points If the percent exceeds |100 readable factors. See examples below. |
is_decimal |
Deprecated. Use 'is_ratio' instead. |
plus_sign |
Deprecated. Use 'show_plus_sign' instead. |
factor_out |
Deprecated. Use 'show_growth_factor' instead. |
basis_points_out |
Deprecated. Use 'show_bps' instead. |
String representation of the percentages.
# Formatting 22.3% npercent(0.223, is_ratio = TRUE, digits = 1) npercent(22.3, is_ratio = FALSE, digits = 1) # Formatting percentages with growth factors npercent(c(-4.01, 2.56), is_ratio = TRUE, show_growth_factor = TRUE) # Formatting percentages as basis points npercent( c(-1, -0.5, -0.1, -0.01, 0, 0.01, 0.1, 0.5, 1), is_ratio = TRUE, show_bps = TRUE )# Formatting 22.3% npercent(0.223, is_ratio = TRUE, digits = 1) npercent(22.3, is_ratio = FALSE, digits = 1) # Formatting percentages with growth factors npercent(c(-4.01, 2.56), is_ratio = TRUE, show_growth_factor = TRUE) # Formatting percentages as basis points npercent( c(-1, -0.5, -0.1, -0.01, 0, 0.01, 0.1, 0.5, 1), is_ratio = TRUE, show_bps = TRUE )
neat representation of string
nstring( text, case = NULL, remove_specials = FALSE, keep_chars = "", ascii_only = FALSE, string = NULL, whitelist_specials = NULL, en_only = NULL )nstring( text, case = NULL, remove_specials = FALSE, keep_chars = "", ascii_only = FALSE, string = NULL, whitelist_specials = NULL, en_only = NULL )
text |
a string / character |
case |
a string, It specifies how the string should be formatted. Current options are 'lower', 'upper', 'title', 'start' and 'initcap'. |
remove_specials |
a Boolean. If TRUE, special characters are removed from the string. |
keep_chars |
a vector of characters that are kept even if remove_specials is TRUE. |
ascii_only |
a Boolean. If TRUE, only ASCII characters are kept. |
string |
Deprecated. Use 'text' instead. |
whitelist_specials |
Deprecated. Use 'keep_chars' instead. |
en_only |
Deprecated. Use 'ascii_only' instead. |
White space cleaned and optionally formatted by case conversion and removal of special characters of the input string.
nstring(" All MOdels are wrong. some ARE useful!!! ", case = "title", remove_specials = TRUE ) nstring("all Models are Wrong some are Useful", case = "start", remove_specials = TRUE ) nstring("variable_123!!", remove_specials = TRUE, keep_chars = c("_"))nstring(" All MOdels are wrong. some ARE useful!!! ", case = "title", remove_specials = TRUE ) nstring("all Models are Wrong some are Useful", case = "start", remove_specials = TRUE ) nstring("variable_123!!", remove_specials = TRUE, keep_chars = c("_"))
neat representation of time stamp
ntimestamp( timestamp, show_weekday = TRUE, show_date = TRUE, show_hours = TRUE, show_minutes = TRUE, show_seconds = TRUE, show_timezone = TRUE, display_weekday = NULL, include_date = NULL, include_hours = NULL, include_minutes = NULL, include_seconds = NULL, include_timezone = NULL )ntimestamp( timestamp, show_weekday = TRUE, show_date = TRUE, show_hours = TRUE, show_minutes = TRUE, show_seconds = TRUE, show_timezone = TRUE, display_weekday = NULL, include_date = NULL, include_hours = NULL, include_minutes = NULL, include_seconds = NULL, include_timezone = NULL )
timestamp |
a POSIX time stamp |
show_weekday |
a Boolean representing if the weekday of the timestamp to be included. By default it is set to TRUE |
show_date |
a Boolean representing if the date of time stamp to be included. By default it is set to TRUE. |
show_hours |
a Boolean representing if the hours to be included. By default it is set to TRUE |
show_minutes |
a Boolean representing if the minutes to be included. By default it is set to TRUE |
show_seconds |
a Boolean representing if the seconds to be included. By default it is set to TRUE |
show_timezone |
a Boolean variable representing if the timezone of the date variable to be included. By default it is set to TRUE. |
display_weekday |
Deprecated. Use 'show_weekday' instead. |
include_date |
Deprecated. Use 'show_date' instead. |
include_hours |
Deprecated. Use 'show_hours' instead. |
include_minutes |
Deprecated. Use 'show_minutes' instead. |
include_seconds |
Deprecated. Use 'show_seconds' instead. |
include_timezone |
Deprecated. Use 'show_timezone' instead. |
String representation of time stamp
# Neat representation of time stamp x <- Sys.time() ntimestamp(x) # Neat representation of time from a time stamp ntimestamp(x, show_date = FALSE, show_seconds = FALSE, show_timezone = FALSE )# Neat representation of time stamp x <- Sys.time() ntimestamp(x) # Neat representation of time from a time stamp ntimestamp(x, show_date = FALSE, show_seconds = FALSE, show_timezone = FALSE )