-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
21a7b38
commit 381608d
Showing
3 changed files
with
96 additions
and
0 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,56 @@ | ||
#' Get overlapping sample depths | ||
#' | ||
#' This function makes it easy to see which samples in the input file have | ||
#' overlapping sample depths. It may be used if the | ||
#' \code{tapas::check_pretreat()} function flags a warning for the presence of | ||
#' overlapping sample depths. | ||
#' | ||
#' @details | ||
#' The function checks if any \code{CmBot[i] > CmTop[i+1]}. If \code{TRUE}, | ||
#' a data.frame with the overalpping samples is returned. | ||
#' | ||
#' @param series The input data frame. A matrix with the following columns: | ||
#' \code{CmTop, CmBot, AgeTop, AgeBot, Volume}, | ||
#' and one or more columns with the data | ||
#' that is being analysed (variables). | ||
#' | ||
#' @return A data frame including only the rows of the overlapping samples | ||
#' sorted in ascending order by depth. The rownames are inherited from the | ||
#' input data.frame, and mya thus help finding the flagged samples in raw data | ||
#' files. | ||
#' | ||
#' @seealso [check_pretreat()] | ||
#' | ||
#' @importFrom dplyr distinct arrange pick | ||
#' | ||
#' @export | ||
#' | ||
#' @author Walter Finsinger | ||
#' | ||
get_overlap_depths <- function(series) { | ||
|
||
|
||
## Gather data -------------------------------------------------------------- | ||
A <- series | ||
cm <- A[ ,1] | ||
cmB <- A[ ,2] | ||
|
||
|
||
## Check if the depth scale is continuous (cmBot[i] > cmTop[i+1]) ---------- | ||
|
||
## Get difference between cmBot of sample[i] and cmTop of sample[i+1]. | ||
overlaps_index <- cmB[1:length(cmB) - 1] - cm[2:length(cm)] | ||
|
||
# Get indices for overlapping samples | ||
overlaps <- which(overlaps_index > 0) | ||
|
||
# Get overlapping samples from input data.frame: | ||
all_overlap_samples <- rbind(A[overlaps, ], A[overlaps + 1, ]) | ||
|
||
# Remove duplicates and sort in ascending order by top depth | ||
overlap_samples <- dplyr::distinct(all_overlap_samples) %>% | ||
dplyr::arrange(dplyr::pick(1)) | ||
|
||
# Return output | ||
return(overlap_samples) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.