Skip to content

Commit

Permalink
fix use of match.arg output and be consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
itcarroll committed Nov 30, 2020
1 parent b0904a7 commit 43290af
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
8 changes: 8 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Version 2.0.5
-------------

BUG FIXES

* Resolved silent error (no longer silent in R 4.1) from failure to use output
of `match.arg` (#122).

Version 2.0.4
-------------

Expand Down
6 changes: 3 additions & 3 deletions R/community_diversity.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ community_diversity <- function(df,
metric = c("Shannon", "InverseSimpson")) {

# verify measure choice
measure <- match.arg(metric)
metric <- match.arg(metric)

# check no NAs in abundance column
if (any(is.na(df[[abundance.var]]))) stop("Abundance column contains missing values")
Expand All @@ -81,9 +81,9 @@ community_diversity <- function(df,
}

# get function for chosen measure, and calculate output
diversity <- get(measure)
diversity <- get(metric)
comdiv <- aggregate.data.frame(df[abundance.var], df[by], FUN = diversity)
names(comdiv) <- c(by, measure)
names(comdiv) <- c(by, metric)

return(comdiv)
}
Expand Down
4 changes: 2 additions & 2 deletions R/community_structure.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ community_structure <- function(df,
metric = c("Evar", "SimpsonEvenness", "EQ")) {

# verify measure choice
measure <- match.arg(metric)
metric <- match.arg(metric)

# check no NAs in abundance column
if(any(is.na(df[[abundance.var]]))) stop("Abundance column contains missing values")
Expand All @@ -95,7 +95,7 @@ community_structure <- function(df,
warning("Evenness values contain NAs because there are plots with only one species")
}

names(comstruct) <- c(by, 'richness', measure)
names(comstruct) <- c(by, 'richness', metric)

return(comstruct)
}
Expand Down
4 changes: 2 additions & 2 deletions R/synchrony.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ synchrony <- function(df, time.var,
# @return output The degree of species synchrony. If "Loreau", 1 is perfect synchrony and 0 is perfect asynchrony.
# If "Gross", 1 is perfect synchrony and -1 is perfect asynchrony.
synch_onerep <- function(df, time.var, species.var, abundance.var,
metric = "Loreau") {
metric = match.arg(metric, choices = c("Loreau", "Gross")) # for partial argument matching
metric = c("Loreau", "Gross")) {
metric = match.arg(metric) # for partial argument matching

#remove any species that were never present.
df <- subset(df, abundance.var > 0)
Expand Down

0 comments on commit 43290af

Please sign in to comment.