BenWilliams-NOAA / safe

rmd files for creating safe document to word...
4 stars 1 forks source link

Add main_table fxn to satf package? #4

Closed Schiano-NOAA closed 6 hours ago

Schiano-NOAA commented 2 months ago

Could we add the R/main_table.R function to the satf package we are developing? I would be making adjustments so it works with the standard converted model results, but use your main flextable code in the function.

BenWilliams-NOAA commented 2 months ago

yeah - pretty straightforward, though I've added a couple of tweaks.

  1. a comma() function to facilitate formatting

    #' function to format numbers to text with 1,000s comma
    #'
    #' @param number value to format
    #'
    #' @export comma
    #'
    comma <- function( number ) {
    format(round(as.numeric( number ), digits = 0), big.mark = ",")
    } 
  2. I use comma() on each of the exec_summ cells, then use main_table().

    
    # have to muck with the data formats...
    for(i in 2:5){
    for(j in c(3:7, 11:13)){
    exec_summ[j,i] = comma(exec_summ[j,i])
    }
    }

safe::main_table(exec_summ, year, tier=3, c1, c2, c3)



Note that `exec_summ` is a .csv of data outputs, so it is akin to your standard converted model results.
Schiano-NOAA commented 2 months ago

Awesome! The comma function you included will also be very helpful for other plots and tables as well. I will tag you once it is committed to the repo.