R/processGEEraw.r

Defines functions processGEEraw

Documented in processGEEraw

#' High-level function that processes raw GEE results.
#' Converts to wide format (one variable per column).
#' Converts units if necessary.
#' Joins to an existing file (file must have anno_id).
#'
#' @param datAnnoPF \code{character} Path and filename of the file that the anno data should be joined to. Should have anno_id field.
#' @param outPF \code{character} Path and filename of output file. Will write over datAnnoPF if null
#' @param rawP \code{character} Path to raw GEE result files. If NULL, assumes ./raw
#' @export
#'
processGEEraw <- function(datAnnoPF,outPF=NULL,rawP=NULL) {

  if(is.null(rawP)) {
    rawP <- getOption('anno.rawP')
  }

  geeAnno <- annoRawToWide(rawP) %>%
    convertUnits()

  message("Joining annotated data...")

  #need to increase default number of guessed rows in cases where there are a lot of nulls
  datAnno <- readr::read_csv(datAnnoPF,col_type=readr::cols(),guess_max=as.integer(nrow(geeAnno)/5))

  # join annotated variables to the original dataset (must have anno_id)
  datAnno <- datAnno %>%
    dplyr::left_join(geeAnno, by='anno_id')

  if(is.null(outPF)) {
    outPF <- datAnnoPF
  }

  message(glue::glue('Writing dataset...'))
  readr::write_csv(datAnno,outPF)

}
benscarlson/anno documentation built on Nov. 26, 2020, 10:17 p.m.