R/pull.recent.R

Defines functions pull.recent

Documented in pull.recent

#' Load the most recent data from Collector
#'
#' This function allows you to pull most recent data file if date logic used (e.g Collector).
#' @param folder Folder with data files
#' @param prefix Prefix of data files



pull.recent <- function(folder, prefix = "Data_*"){
  if(missing(folder)){
    try(setwd("~/Downloads"),silent = T)
    try(setwd("C:/Users/kitd/Downloads"), silent = T)
  }
  try(setwd(folder), silent = T)
  temp = list.files(pattern=prefix)


  if(length(temp) == 1){
    df <- read.csv(temp[1])
    print(temp[1])
  }
  if(length(temp) > 1 && length(temp) < 11){
    df <- read.csv(temp[length(temp) - 1])
    print(temp[length(temp) - 1])}

  if(length(temp) > 10){
    df <- read.csv(temp[length(temp) - 9])
    print(temp[length(temp) - 9])}

  return(df)
}
kitdouble/Rkit documentation built on Aug. 29, 2020, 12:45 p.m.