R/general.R

#' Library0 Function
#'
#' This function allows you to load/install-and-load multiple packages
#' @param packages vector of packages that you want to load
#' @keywords R packages
#' @export
#' @examples
#' library0(c("plyr", "dplyr", "ggplot2"))
#'
library0 <- function(packages){

      suppressWarnings({suppressMessages({
            for(x in packages){
                  if(x %in% rownames(installed.packages())){
                        try({
                              library(x, character.only = T)
                              print(paste0("Successfully loaded: ", x))
                        })
                  }else{
                        try({
                              install.packages(x, dependencies = T);
                              library(x, character.only = T)
                        })
                  }

                  if(!(x %in% rownames(installed.packages()))){
                        print(paste0("Error installing: ", x))
                        stop("Packages not fully loaded!")
                  }
            }
      })})
}

#' pause function
#'
#' This function allows you to pause a Rexec script
#' @param option different option allows you to prompt different message
#' @keywords pause option
#' @export
#' @examples
#' pause()
#'
pause <- function(option = 99){

      if(option == 1){
            prompt1 <- "Input 1 to text file to SAVE, Otherwise Input 0 \n ...then Press <Enter> to continue...\n"

      }else if(option == 2){
            prompt1 <- "hi..."

      }else if(option == 3){
            prompt1 <- "Input correct date to move csv files...\n";
      }else{
            prompt1 <- "Press <Enter> to continue..."
      }

      if (interactive()) {
            invisible(readline(prompt = prompt1))
      }
      else {
            cat(prompt1)
            invisible(readLines(file("stdin"), 1))
      }
}
junyitt/generalFunction documentation built on May 20, 2019, 11:16 a.m.