R/z_dep_k1_tf_knitr.R

Defines functions maxdate.f htmlcheck.f htmlopen.f

Documented in htmlcheck.f htmlopen.f maxdate.f

#' maxdate.f
#'
#' return max date from a M+ directory
#' 
#' Dependencies: library0("plyr", "dplyr", "function0")
#' Return: df
#' 
#' @param data.dir 
#' @keywords max date from M+
#' @export
maxdate.f <- function(data.dir = "C:/Users/User/Desktop/tempmplus/"){
      .Deprecated("Not useful anymore")
      data.dir <- formatdir.f(data.dir)
      
      flist <- list.files(path = data.dir, pattern = "^201.*.csv")
      
      if(length(flist)==0){
            stop("N = 0, no M+ data!")     
      }
      
      date.v <- sapply(1:length(flist), FUN = function(x){
            fname2 <- strsplit(flist[x], split = "\\.")[[1]][1]
      })
      maxdate <- max(as.numeric(date.v))
      
      return(maxdate)
}

#' htmlcheck.f
#'
#' if ^(maxdate).html exist based on maxdate from a M+ directory, return FALSE
#' 
#' Return: logical value
#' 
#' @param maxdate generated from maxdate.f
#' @param report.dir output directory of html report
#' @keywords max date from M+ html report
#' @export
htmlcheck.f <- function(maxdate, report.dir = "C:/_tFolder/daily_report/"){
      .Deprecated("htmlcheck_f")
      report.dir <- formatdir.f(report.dir)
      flist2 <- list.files(path = report.dir, pattern = "^201.*html")
      
      htmlname <- grep(pattern = maxdate, x = flist2, value = T)  
      if(length(htmlname)==0){
            return(FALSE)
      }else{
            return(TRUE)
      }
}


#' htmlopen.f
#'
#' open the html file
#' 
#' @param maxdate generated from maxdate.f
#' @param report.dir output directory of html report
#' @keywords open html file from maxdate
#' @export
htmlopen.f <- function(maxdate, report.dir = "C:/_tFolder/daily_report/"){
      .Deprecated("htmlopen_f")
      report.dir <- formatdir.f(report.dir)
      flist2 <- list.files(path = report.dir, pattern = "^201.*html")
      
      htmlname <- grep(pattern = maxdate, x = flist2, value = T) 
      L <- length(htmlname)
      shell.exec(paste0(report.dir,htmlname[L])) #if exist, open html
      
}
junyitt/tfunction documentation built on May 4, 2019, 4:23 p.m.