Skip to content

Commit

Permalink
Require branch lengths in 'tree' argument
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Claessens authored and Scott Claessens committed Sep 8, 2024
1 parent 3fe8158 commit 6421ba9
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 6 deletions.
3 changes: 2 additions & 1 deletion R/coev_fit.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
#' @param id A character of length one identifying the variable in the data that
#' links rows to tips on the phylogeny. Must refer to a valid column name in
#' the data. The id column must exactly match the tip labels in the phylogeny.
#' @param tree A phylogenetic tree object of class \code{phylo}.
#' @param tree A phylogenetic tree object of class \code{phylo}. The tree must
#' include branch lengths.
#' @param effects_mat (optional) A boolean matrix with row and column names
#' exactly matching the variables declared for the model. If not specified,
#' all cross-lagged effects will be estimated in the model. If specified, the
Expand Down
4 changes: 4 additions & 0 deletions R/coev_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ run_checks <- function(data, variables, id, tree, effects_mat,
if (!methods::is(tree, "phylo")) {
stop2("Argument 'tree' must be an phylogenetic tree object of class phylo.")
}
# stop if tree does not have branch length information
if (is.null(tree$edge.length)) {
stop2("Argument 'tree' does not include branch lengths.")
}
# stop if id in data does not match tree tip labels exactly
if (!identical(sort(unique(data[,id])), sort(tree$tip.label))) {
stop2("The id variable in the data does not match tree tip labels exactly.")
Expand Down
3 changes: 2 additions & 1 deletion R/coev_make_stancode.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
#' @param id A character of length one identifying the variable in the data that
#' links rows to tips on the phylogeny. Must refer to a valid column name in
#' the data. The id column must exactly match the tip labels in the phylogeny.
#' @param tree A phylogenetic tree object of class \code{phylo}.
#' @param tree A phylogenetic tree object of class \code{phylo}. The tree must
#' include branch lengths.
#' @param effects_mat (optional) A boolean matrix with row and column names
#' exactly matching the variables declared for the model. If not specified,
#' all cross-lagged effects will be estimated in the model. If specified, the
Expand Down
3 changes: 2 additions & 1 deletion R/coev_make_standata.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
#' @param id A character of length one identifying the variable in the data that
#' links rows to tips on the phylogeny. Must refer to a valid column name in
#' the data. The id column must exactly match the tip labels in the phylogeny.
#' @param tree A phylogenetic tree object of class \code{phylo}.
#' @param tree A phylogenetic tree object of class \code{phylo}. The tree must
#' include branch lengths.
#' @param effects_mat (optional) A boolean matrix with row and column names
#' exactly matching the variables declared for the model. If not specified,
#' all cross-lagged effects will be estimated in the model. If specified, the
Expand Down
3 changes: 2 additions & 1 deletion man/coev_fit.Rd

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

3 changes: 2 additions & 1 deletion man/coev_make_stancode.Rd

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

3 changes: 2 additions & 1 deletion man/coev_make_standata.Rd

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

12 changes: 12 additions & 0 deletions tests/testthat/test-coev_fit.R
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,18 @@ test_that("coev_fit() produces expected errors", {
),
"Argument 'tree' must be an phylogenetic tree object of class phylo."
)
expect_error(
coev_fit(
data = d,
variables = list(
x = "bernoulli_logit",
y = "ordered_logistic"
),
id = "id",
tree = ape::rtree(n, br = NULL)
),
"Argument 'tree' does not include branch lengths."
)
expect_error(
{
d2 <- d
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-coev_make_stancode.R
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,18 @@ test_that("coev_make_stancode() produces expected errors", {
),
"Argument 'tree' must be an phylogenetic tree object of class phylo."
)
expect_error(
coev_make_stancode(
data = d,
variables = list(
x = "bernoulli_logit",
y = "ordered_logistic"
),
id = "id",
tree = ape::rtree(n, br = NULL)
),
"Argument 'tree' does not include branch lengths."
)
expect_error(
{
d2 <- d
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-coev_make_standata.R
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,18 @@ test_that("coev_make_standata() produces expected errors", {
),
"Argument 'tree' must be an phylogenetic tree object of class phylo."
)
expect_error(
coev_make_standata(
data = d,
variables = list(
x = "bernoulli_logit",
y = "ordered_logistic"
),
id = "id",
tree = ape::rtree(n, br = NULL)
),
"Argument 'tree' does not include branch lengths."
)
expect_error(
{
d2 <- d
Expand Down

0 comments on commit 6421ba9

Please sign in to comment.