R/extr_values_fct.r

Defines functions extr_values

#' extr_values function
#'
#' @description Internal function used to extract the timestamps from Excel files generated by a 
#' Li-Cor LI-6800 system. It can be used to extract any value from a specific cell in a Excel file
#' 
#'
#' @param lst A vector of file addresses ("character")
#' @param column Excel column (in letters)from which to extract data
#' @param row Excel row number from which to extract data
#'
#' @return Values as read in Excel files produced by the LI-Cor portable photosynthesis
#'   systems LI-6800 (only).


extr_values <- function(lst, column, row) {

  values <- vector("character", length(lst))
  
  x <- expand.grid(LETTERS, c("", LETTERS[1:6])) %>% transmute(x = paste0(Var2, Var1)) %>% pull(x)
  cell <- paste0(x[column], row)
  
  for(i in 1:length(lst)) {
    suppressMessages(
      values[i] <- 
        ifelse(length(readxl::read_excel(lst[i], range = cell[i], col_names = FALSE)) != 0,
               readxl::read_excel(lst[i], range = cell[i], col_names = FALSE), NA)
    )
  }

  output <- unlist(values)
  output[output == ""] <- NA
  
  return(output)
}
ManuelLamothe/RapidACi documentation built on Sept. 16, 2020, 9:53 p.m.