R/ga.create.em.maxn.R

Defines functions ga.create.em.maxn

Documented in ga.create.em.maxn

##  ----
#' ga.create.em.maxn function
#'
#' The ga.create.em.maxn function finds all files ending in "Points.txt" and combines them into a maxn file, keeps filename, and periodtime DOES NOT include stage
#'
#' @param object file to be manipulated
#'
#' @return None
#'
#' @examples
#'
#' @export
ga.create.em.maxn<-function(dat){
points.files <-ga.list.files("_Points.txt") # list all files ending in "Lengths.txt"
points.files$lines<-sapply(points.files,countLines) # Count lines in files (to avoid empty files breaking the script)
points<-as.data.frame(points.files)%>%
  dplyr::mutate(campaign=row.names(.))%>%
  filter(lines>1)%>% # filter out all empty text files
  dplyr::select(campaign)%>%
  as_vector(.)%>% # remove all empty files
  purrr::map_df(~ga.read.files_em.txt(.))#%>%
#select(-c(project))

maxn<-points%>%
  dplyr::group_by(campaignid,sample,filename,period,periodtime,frame,family,genus,species,comment)%>%
  dplyr::mutate(number=as.numeric(number))%>%
  dplyr::summarise(maxn=sum(number))%>%
  dplyr::group_by(campaignid,sample,family,genus,species)%>%
  dplyr::slice(which.max(maxn))%>%
  dplyr::ungroup()%>%
  dplyr::filter(!is.na(maxn))%>%
  dplyr::select(-frame)%>%
  tidyr::replace_na(list(maxn=0))%>%
  dplyr::mutate(maxn=as.numeric(maxn))%>%
  dplyr::filter(maxn>0)
return(maxn)
}
UWAMEGFisheries/GlobalArchive documentation built on Dec. 2, 2019, 10:40 p.m.