-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new function for combining site and event data and cleanup of summari…
…zing sample data given some database changes since I last worked on this
- Loading branch information
Morgan Kain
authored and
Morgan Kain
committed
Apr 29, 2024
1 parent
1ae2ff4
commit fd2e583
Showing
5 changed files
with
165 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#' Summarize Event Data | ||
#' | ||
#' @param site_data Data frame. Site info | ||
#' @param event_data Data frame. Sampling occasions (events) | ||
#' @param site_characterization Data frame. Site characterization (as named on airtable) | ||
#' @param base base id | ||
#' | ||
#' @return List of two data frames (specimen data and sample data) | ||
#' @export | ||
summarize_event_data <- function(site_data, event_data, site_characterization, base) { | ||
|
||
## 1) SABRENet and BEEZ have a bit different info in "Site Data" and "Event Data" | ||
## 2) In SABRENet -- "Sample Data" column 'Site' links appropriately to "Site Data" | ||
## In BEEZ -- "Sample Data" column 'Site' is actually a link to "Event Data" | ||
|
||
## X - Site Data (Site) <<- Site Characterization (id) | ||
## Y - Event Data (Site Data) <<- X (id) | ||
|
||
event_data %<>% dplyr::select( | ||
base_id, id, `Date arrived`, `Date depart` | ||
) | ||
|
||
site_data %<>% dplyr::select( | ||
base_id, id, Site_ID, Site, Event, `Sample Data` | ||
) %>% dplyr::mutate( | ||
`Site` = lapply(`Site`, FUN = function(x) ifelse(is.null(x), NA, x)) %>% unlist() | ||
, `Event` = lapply(`Event`, FUN = function(x) ifelse(is.null(x), NA, x)) %>% unlist() | ||
) | ||
|
||
site_characterization %<>% dplyr::select( | ||
base_id, id, `Site name` | ||
) | ||
|
||
site_data.s <- site_data %>% dplyr::filter(base_id == base[[1]]) | ||
site_data.b <- site_data %>% dplyr::filter(base_id == base[[2]]) | ||
|
||
event_data.s <- event_data %>% dplyr::filter(base_id == base[[1]]) | ||
event_data.b <- event_data %>% dplyr::filter(base_id == base[[2]]) | ||
|
||
site_characterization.s <- site_characterization %>% dplyr::filter(base_id == base[[1]]) | ||
site_characterization.b <- site_characterization %>% dplyr::filter(base_id == base[[2]]) | ||
|
||
## X - Site Data (Site) <<- Site Characterization (id) | ||
## Y - Event Data (Site Data) <<- X (id) | ||
|
||
joined.s <- dplyr::left_join( | ||
site_data.s | ||
, site_characterization.s %>% dplyr::rename(Site = id) | ||
, by = c("base_id", "Site") | ||
) %>% dplyr::left_join( | ||
. | ||
, event_data.s %>% dplyr::rename(Event = id) | ||
, by = c("base_id", "Event") | ||
) %>% dplyr::select( | ||
base_id, id, Site_ID, `Site name`, `Date arrived`, `Date depart` | ||
) | ||
|
||
joined.b <- dplyr::left_join( | ||
site_data.b | ||
, site_characterization.b %>% dplyr::rename(Site = id) | ||
, by = c("base_id", "Site") | ||
) %>% dplyr::left_join( | ||
. | ||
, event_data.b %>% dplyr::rename(Event = id) | ||
, by = c("base_id", "Event") | ||
) %>% dplyr::select( | ||
base_id, Event, Site_ID, `Site name`, `Date arrived`, `Date depart` | ||
) %>% dplyr::rename(id = Event) | ||
|
||
return( | ||
rbind(joined.s, joined.b) %>% dplyr::rename(Site = id) | ||
) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.