Skip to content

Commit

Permalink
Merge pull request #90 from fishR-Core-Team/88-alkindivage-fails-ungr…
Browse files Browse the repository at this point in the history
…acefully-if-na-in-length-variable-of-length-sample

Added check for NA with error message in alkIndivAge(). This closes #88
  • Loading branch information
droglenc committed Mar 19, 2022
2 parents 2ac7f3c + e931350 commit ad2a65f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Updated sticker.
* Updated `pkgdown.yaml` GitHub action to [v2](https://github.com/r-lib/actions/tree/v2-branch/examples#build-pkgdown-site). Changed action to only run on a release (rather than a push) but it can be [run manually](https://docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow) as well.
* Updated `R-CMD-check.yaml` GitHub action to [v2](https://github.com/r-lib/actions/tree/v2-branch/examples#standard-ci-workflow). Note that I had to add the [extra code for dealing with graphics on the Mac version](https://github.com/r-lib/actions#common-questions).
* `alkIndivAge()`: Modified. Added a catch for `NA`s in the length sample. Also added a test. This addresses [#88](https://github.com/fishR-Core-Team/FSA/issues/88)).

# FSA 0.9.3 15-Feb-21
* Moved `dplyr` from `imports` to `suggests` (needed because functions were removed in last version; however it is still used in some examples; partially addresses [#87](https://github.com/fishR-Core-Team/FSA/issues/87)).
Expand Down
2 changes: 1 addition & 1 deletion R/ageComparisons.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' @title Compute measures of precision among sets of ages.
#'
#' @description Computes overall measures of precision for multiple age estimates made on the same individuals. Ages may be from two or more readers of the same structure, one reader at two or more times, or two or more structures (e.g., scales, spines, otoliths). Measures of precision include ACV (Average Coefficient of Variation), APE (Average Percent Error), AAD (Average Absolute Deviation), and ASD (Average Standard Devation), and various percentage difference values.
#' @description Computes overall measures of precision for multiple age estimates made on the same individuals. Ages may be from two or more readers of the same structure, one reader at two or more times, or two or more structures (e.g., scales, spines, otoliths). Measures of precision include ACV (Average Coefficient of Variation), APE (Average Percent Error), AAD (Average Absolute Deviation), and ASD (Average Standard Deviation), and various percentage difference values.
#'
#' @param formula A formula of the form \code{~var1+var2+var3+...} or, alternatively, \code{var1~var2+var3+...}, where the \code{varX} generically represent the variables that contain the age estimates. The alternative formula allows for similar code as used in \code{\link{ageBias}} and can have only one variable on the left-hand side.
#' @param data A data.frame that minimally contains the variables in \code{formula}.
Expand Down
5 changes: 4 additions & 1 deletion R/alkIndivAge.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ alkIndivAge <- function(key,formula,data,type=c("SR","CR"),
# handle differently depending on how many variables were in the formula
if (tmp$vnum==1) {
if (!tmp$vclass %in% c("numeric","integer"))
STOP("RHS ariable must be numeric.")
STOP("RHS variable must be numeric.")
ca <- "age"
cl <- tmp$vname
} else if (tmp$vnum==2) {
Expand All @@ -121,6 +121,9 @@ alkIndivAge <- function(key,formula,data,type=c("SR","CR"),
cl <- tmp$Enames
ca <- tmp$Rname
} else STOP("'formula' must have only one variable on LHS and RHS.")
#Check for NA's
if (any(is.na(data[,cl])))
STOP("Length variable contains 'NA's;\n Please remove these fish from the length sample before using 'alkIndivAge()'.")
## Set the random seed if asked to do so
if (!is.null(seed)) set.seed(seed)
## Begin process
Expand Down
2 changes: 1 addition & 1 deletion man/agePrecision.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions tests/testthat/testthat_AgeLengthKey.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ test_that("alkIndivAge() messages",{
"will be treated as all-inclusive")
expect_error(alkIndivAge(WR1.key[-c(1:5),],age~len,data=WR1.len),
"minimum observed length in the length")
## Length sample has some NAs
WR1.len.problem <- rbind(WR1.len,c(ID=999,len=NA,age=NA,LCat=NA))
expect_error(alkIndivAge(WR1.key,age~len,data=WR1.len.problem),
"Length variable contains 'NA's")
})

test_that("alkMeanVar() errors and warnings",{
Expand Down

0 comments on commit ad2a65f

Please sign in to comment.