File tree Expand file tree Collapse file tree
Master RMarkdown Document & Render Code Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -48,19 +48,13 @@ palette <- phsstyles::phs_colours(c(
4848# # Function for formatting a value for R Markdown text
4949# First determines how many dps the value should have
5050# Then adds a comma for numbers over 1000 (becomes "1,000")
51-
52- format_number_for_text <- function (x ) {
53- x <- ifelse(
54- abs(x ) < 1 ,
55- round_half_up(x , 2 ), # if x < 1 then show 2dp
56- ifelse(
57- abs(x ) < 100 ,
58- round_half_up(x , 1 ), # if 1 =< x < 100 then 1dp
59- round_half_up(x )
60- )
61- ) # if 10 =< x then no decimal places
62-
63- format(x , big.mark = " ," )
51+ format_number_for_text <- function (number ) {
52+ case_when(
53+ abs(number ) < 1 ~ round_half_up(number , 2 ),
54+ abs(number ) < 100 ~ round_half_up(number , 1 ),
55+ .default = round_half_up(number , 0 )
56+ ) | >
57+ format(big.mark = " ," )
6458}
6559
6660# This will return the correct article depending on the (max 2-digit) number supplied
You can’t perform that action at this time.
0 commit comments