README.md

Fast Analytics

The Fast Analytics packages is a tool for creating skeleton reports of standard formatted plots. Instead of functions that output plots, this package write the code to generate the listed plots, and necessary data transformations, to a file that can then be edited and run. Often we want the same plot as previous analysis but with some slight adjustments, with single-purpose plotting functions it is difficult to adjust for the specific use cases without altering the function itself. By writing the plotting code to an analysis script the plot can be tweaked, run, and source controlled for each specific analysis.

If latexmk and texlive-full are available on the system the flag tex = TRUE can be set to render the auto-generated figures into a Beamer slide deck. It will default to using the RootTeX if installed and should fall back to the Beamer default template if it is not available.

Install

There is a dependency on my utilities package. To install both:

require(devtools)
devtools::install_git("http://gitlab.prod.rm/michael.hutchins/utilities.git")
devtools::install_git("http://gitlab.prod.rm/michael.hutchins/fast-analytics.git")

Example call:

skeleton("whales.R", 2588,
         list(downloadTimeSeries, uploadTimeSeries,
              downloadBoxPlot, uploadBoxPlot,
              twilioFailureMap, m2mFailureMap),
         username = 'michael.hutchins', run = TRUE)

Output

You can view the R script, whales.R, and the TeX file, auto_whales2588.tex, in the sample folders. The resulting images and PDF report are available on fileshare01:Analytics/AnalyticsTeam/Michael/fastAnalyticsSample/. Both the sample and the PDF may or may not be up to date with the latest version of the package, I will try to keep them in sync as new features and adjustments are made.

Beamer

For more on using LaTeX/Beamer take a look at my Beamer Tutorial.

Writing New Plots

New plots need to have no input variables and output a list of names strings with at least one of the fields:

  1. data - The data pull function required to get the data
  2. process - Any additional processing functions or commands
  3. plot - The text used to make the plotting function
  4. save - The basename of the save file (no path, .png or appended csid value)

Here is a template that can be used for making new plots:

#' Name of the Plot
#'
#' Plot description
#'
#' @return Returns standard fast-analysis structured list
#' @family skeletonPlots
#' @export
boxPlot <- function() {

    save <- 'box_plot'
    data <- pullTestSummary()

    plot <- "
#### Plot Title

plt <- ggplot(data, aes(x = carrier,
                        y = dsd_effective_download_test_speed,
                        fill = carrier)) +
    geom_boxplot(notch = TRUE) +
    scale_fill_root() +
    theme_root() +
    xlab('')
print(plt)
"
    ## Append a line for saving the plot in the standard format
    plot <- paste(plot,
                  saveLine(save),
                  sep = "")
    output <- list(data = data,
                   plot = plot,
                   save = save)
    return(output)

}


mlhutchins/fast-analytics documentation built on May 23, 2019, 2:10 a.m.