R/data-docs.R

Defines functions fecalTableDoc

Documented in fecalTableDoc

#' Poop-link table
#'
#' This table acts a linker between the fecal database and the trapping database
#' @format a dataframe with 28597 rows and 8 variables
#' \describe{
#'  \item{squirrel_id}{integer id of squirrel owner of trapping id}
#'  \item{trapping_id}{integer id of trap id. NOTE: This is housed as "id" in the primary trapping database}
#'  \item{year}{integer year of trapping record}
#'  \item{vial_number}{integer id indicates whether a given trapping record contained more than one poop vial. Poop vial "1" correpsonds to primary poop vial}
#'  \item{poop_id}{character value of poop vial. Used to link to fecal data tables}
#'  \item{poop_time}{numeric value of time of fecal collection in the field. When this was not documented, an estimate is given as "time_guess"}
#'  \item{problem_duplicate}{0/1 Identifies whether poop_id appears for more than one trapping record}
#'  \item{time_guess}{numeric value of time estimate if fecal collection time was not present in trapping record}
#' }




#' Access table descriptions
#' @description Rather than house table descriptions in the SQL database or house them in an excel file somewhere,
#'     this is a handy function to get table documentation.
#' @param table character; which table to document
#' @export
fecalTableDoc = function(con= NULL, table = NULL){
  if(is.null(con)){
    stop("Database connection is missing")
  }
  if(!is.character(table)&!is.null(table)){
    stop("Argument table must be a character")
    return(NULL)
  }
  if(is.null(table)){
    message(
      "You can access help documentation for current tables by entering the name of a table in the database.

If you are not sure of the current tables, you can use the following:
          fecalTables(con,...)
          DBI::dbListTables(con,...)
          RMySQL::dbListTables(con,...)")
    return(NULL)
  }
  if(!table %in% fecalTables(con)){
    stop("Table not found in database")
  } else if(table == "poop_link"){

    cat(
"This table acts a linker between the fecal database and the trapping database \n
        item       |                 Description
____________________________________________________________
squirrel_id        | {integer}   id of squirrel owner of trapping id
trapping_id        | {integer}   id of trap id. NOTE: This is housed as 'id' in the primary trapping database
year               | {integer}   year of trapping record
vial_number        | {integer}   id indicates whether a given trapping record contained more than one poop vial.
                   |                 Poop vial '1' correpsonds to primary poop vial
poop_id            | {character} value of poop vial. Used to link to fecal data tables
poop_time          | {numeric}   value of time of fecal collection in the field. When this was not documented,
                   |                  an estimate is given as 'time_guess'
problem_duplicate  | {logical}   Identifies whether poop_id appears for more than one trapping record
time_guess         | {numeric}   value of time estimate if fecal collection time was not present in trapping record
")
  } else if(table == "extracts"){
    cat(
"This table contains extract information for extract database
        item       |                 Description
____________________________________________________________
poop_id                                  | {character} value of poop vial. Used to link to fecal data tables
field_poop_vial_id                       | {numeric} poop_id of vial used for data collection in the field. When discrepancies arise between poop_id and field poop_id
                                                         the field_poop_id field is favored
weight_observer                          | {character} name or initials of individual who weighed raw fecal samples
sample_extracted_if_two_samples          | {character} if multiple poop vials are associated with a single trapping record, this sample is the one analyzed
date_weighed                             | {character} date in Y-m-d format. Date raw fecal was weighed
mass_extracted_g                         | {numeric} mass of raw fecal sample weighed for extraction
mass_estimated                           | {logical} I don't know what this means
hair_in_feces                            | {logical} was hair present in raw fecal sample
extraction_notes_contaminants_removed    | {character} additional extraction notes on contaminents removed
other_extraction_notes                   | {character} additional extraction notes
extra_fecal_sample                       | {logical} was additional fecal matter saved after extraction for future extraction
duplicate_sample                         | {logical} indicates sample is a duplicate extraction. May arise from extracting extra sample from a previous
                                                         or may be a result of duplicating the extraction. Check dates for more context
extracted                                | {logical} Indicates whether the extraction was fully completed (I think?)
date_of_extraction                       | {character} date in Y-m-d format. Date extraction was completed
extraction_observer                      | {character} initials or name of individual who completed extraction
extraction_vial_number                   | {integer} indicates whether sample is from primary, secondary, or tertiary poop vial id
"
    )
  } else if(table == "cort"){
    cat(
"This table contains information for all samples assayed for cortisol levels"
    )
  } else if(table == "androgen"){
    cat(
"This table contains information for all samples assayed for androgen levels"
    )
  }
}
mwhalen18/krspfecals documentation built on Dec. 21, 2021, 11:05 p.m.