R/lib.R

Defines functions import_lib lib install_scriptR

Documented in install_scriptR lib lib

#' Load Library Functions
#'
#' Functions to load libraries
#'
#' @details
#' install_scriptR() installs the scriptR package \cr
#'
#' lib() imports libraries depending on args: \cr
#'  data: (data wrangling) tidyverse, data.table, etc \cr
#'  develop: (development) argparse, logging, parallel \cr
#'  viz: (data visualization) ggplot2 and extensions \cr
#'
#' @name lib
NULL

#' @rdname lib
#' @export
install_scriptR <- function() devtools::install_github("jennguyen1/scriptR")

#' @rdname lib
#' @export
lib <- function(...){
  "Imports libraries"
  
  args <- as.character(substitute(list(...))[-1])
  lib_opts <- dplyr::mutate_at(data.frame(data = TRUE, develop = TRUE, viz = FALSE), dplyr::vars(dplyr::one_of(args)), function(x) TRUE)
  suppressWarnings( suppressPackageStartupMessages( import_lib(lib_opts) ) )
}

import_lib <- function(lib_opts){
  if(lib_opts$data){
    # data wrangling
    library(magrittr)
    library(glue)
    library(stringr)
    library(tidyverse)
    library(purrrlyr)
    library(data.table)
  }

  if(lib_opts$viz){
    # data visualization
    library(knitr)
    library(ggplot2)
    library(grid)
    library(gridExtra)
    library(GGally)
    library(gtable)

    # set ggplot2 theme
    theme_set(theme_bw())
  }

  if(lib_opts$develop){
    # development
    library(argparse)
    library(futile.logger)
    library(assertthat)
    library(parallel)
  }
}
jennguyen1/scriptR documentation built on Aug. 6, 2018, 6:38 p.m.