R/parseOutFile.R

#' Parse a data.frame imported from a SORTIE-ND OUT File.
#'
#' This function takes the data.frame generated by \code{\link{getOutFile}} and
#' reformats it so that Step, Subplot, and Species are the first 3 columns,
#' followed by values for Absolute Densities and Basal Areas. By default, this
#' function removes any columns labeled "NR" or "Total".
#' @param df The data.frame generated by \code{\link{getOutFile}}.
#' @param removeSpp Optional, already set to remove "NR" and "Total" columns
#'   from reformatting, so you can deal with those separately or regenerate them
#'   yourself.
#' @note This function cannot handle the relative density or basal areas
#'   statistics provided by SORTIE-ND, possibly because "rel" or some form of it
#'   is a protected word for the \code{\link{grep}} family of functions that I
#'   use.
#' @examples
#' #dat <- getOutFile("test.out")
#' #head(parseOutFile(dat))
#'   @export

parseOutFile <- function(df, removeSpp=c("Total")){
  #return(df)
  repeatcols <- df[, 1:2]

  for(i in 1:length(removeSpp)){
    df <- df[, -grep(removeSpp[i], colnames(df), value=F)]
  }


  SdlAbsDen <- changeColsBySpp(df, "Sdl.Abs.Den..")
  SaplAbsDen <- changeColsBySpp(df, "Sapl.Abs.Den..")
  AdultAbsDen <- changeColsBySpp(df, "Adult.Abs.Den..")
  SaplAbsBA <- changeColsBySpp(df, "Sapl.Abs.BA..")
  AdultAbsBA <- changeColsBySpp(df, "Adult.Abs.BA..")
  newdf <- data.frame(Step=repeatcols[, 1],
                      Subplot=repeatcols[, 2],
                      Species=SdlAbsDen[,1],
                      SdlAbsDen=SdlAbsDen[,2],
                      SaplAbsDen=SaplAbsDen[,2],
                      AdultAbsDen=AdultAbsDen[,2],
                      SaplAbsBA=SaplAbsBA[,2],
                      AdultAbsBA=AdultAbsBA[,2]
  )

  return(newdf)
}
ecology-rocks/SortieIO documentation built on May 15, 2019, 7:57 p.m.