Skip to content

Commit

Permalink
Made every instance of fossilsToDraw fossilsFormat. Also changed mino…
Browse files Browse the repository at this point in the history
…r things to pass CRAN checks (using is() instead of class()).
  • Loading branch information
brpetrucci committed Oct 17, 2023
1 parent ba76bcd commit 2165b43
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 26 deletions.
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ Suggests:
fitdistrplus,
knitr,
rmarkdown
Imports:
methods
License: GPL-3
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.2
VignetteBuilder: knitr
RoxygenNote: 7.2.3
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ importFrom(graphics,plot)
importFrom(graphics,points)
importFrom(graphics,segments)
importFrom(graphics,text)
importFrom(methods,is)
importFrom(utils,head)
importFrom(utils,tail)
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ BiSSE, MuSSE, and QuaSSE. See documentation for full reference.
time. Customization options include which colors to use for each
state, whether to plot fossils as true occurrence times or ranges
(already present in 1.0, but now with a dedicated argument for such,
`fossilsToDraw`), and where to place trait value legend. See
`fossilsFormat`), and where to place trait value legend. See
`?draw.sim`, `?bd.sim.traits`, `?sample.clade.traits`, and the
`overview` vignette for examples.

Expand Down
5 changes: 4 additions & 1 deletion R/bd.sim.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@
#' simulation will be set for one of the times where \code{N} species are
#' alive, chosen from all the times there were \code{N} species alive weighted
#' by how long the simulation was in that situation. Exactly one of \code{tMax}
#' and \code{N} must be non-\code{Inf}.
#' and \code{N} must be non-\code{Inf}. Note that if \code{N} is the chosen
#' condition, \code{mu} cannot be \code{0}, since paelobuddy's current
#' algorithm would mean only species 1 would have children. Future features
#' will hopefully remove this limitation.
#'
#' @param lShape Shape parameter defining the degree of age-dependency in
#' speciation rate. This will be equal to the shape parameter in a Weibull
Expand Down
5 changes: 3 additions & 2 deletions R/draw.sim.R
Original file line number Diff line number Diff line change
Expand Up @@ -401,11 +401,12 @@ draw.sim <- function (sim, traits = NULL, fossils = NULL, lineageColors = NULL,
}

# check sortBy
if (!class(sortBy) %in% c("character", "integer")) {
if (!(is(sortBy, "numeric") ||
(is(sortBy, "character") && length(sortBy) == 1))) {
stop("sortBy should be a character or a vector of integers.")
}

else if ((class(sortBy) == "integer") & !(all(1:length(sim$TE) %in%
else if ((is(sortBy, "numeric")) & !(all(1:length(sim$TE) %in%
unique(sortBy)))) {
stop("sortBy must skip no lineage, and all lineages
should have unique indices.")
Expand Down
4 changes: 3 additions & 1 deletion R/phylo.to.sim.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@
#' # testing if simulation and converted object are the same
#' all.equal(sim, res)
#'
#' @importFrom methods is
#'
#' @name phylo.to.sim
#' @rdname phylo.to.sim
#' @export
Expand Down Expand Up @@ -382,7 +384,7 @@ phylo.to.sim <- function(phy, mothers, extant, dateFromPresent = TRUE,
}

# one simple transformation if all lineages are extant:
if (class(res$TE) == "logical") {
if (is(res$TE, "logical")) {
res$TE <- as.numeric(res$TE)
}

Expand Down
14 changes: 7 additions & 7 deletions R/sample.clade.R
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
#' bins = bins, returnTrue = FALSE)
#'
#' # draw simulation with fossil occurrences as ranges
#' draw.sim(sim, fossils = fossils, fossilsToDraw = "ranges")
#' draw.sim(sim, fossils = fossils, fossilsFormat = "ranges")
#'
#' ###
#' # sampling can be any function of time
Expand Down Expand Up @@ -170,7 +170,7 @@
#' bins = bins, returnTrue = FALSE)
#'
#' # draw simulation with fossil occurrences as ranges
#' draw.sim(sim, fossils = fossils, fossilsToDraw = "ranges")
#' draw.sim(sim, fossils = fossils, fossilsFormat = "ranges")
#'
#' ###
#' # now we can try a step function rate
Expand Down Expand Up @@ -206,7 +206,7 @@
#' bins = bins, returnTrue = FALSE)
#'
#' # draw simulation with fossil occurrences as ranges
#' draw.sim(sim, fossils = fossils, fossilsToDraw = "ranges")
#' draw.sim(sim, fossils = fossils, fossilsFormat = "ranges")
#'
#' ###
#' # finally, sample.clade also accepts an environmental variable
Expand Down Expand Up @@ -317,7 +317,7 @@
#' # the warning is to let you know the ranges won't be used
#'
#' # and also as ranges
#' draw.sim(sim, fossils = fossils, fossilsToDraw = "ranges")
#' draw.sim(sim, fossils = fossils, fossilsFormat = "ranges")
#'
#' ###
#' # we can have more parameters on adFun
Expand Down Expand Up @@ -397,7 +397,7 @@
#' # of age (a given percentile of the age, for instance) - see below
#'
#' # draw simulation with fossil occurrences as ranges
#' draw.sim(sim, fossils = fossils, fossilsToDraw = "ranges")
#' draw.sim(sim, fossils = fossils, fossilsFormat = "ranges")
#'
#' ###
#' # we can also have a hat-shaped increase through the duration of a species
Expand Down Expand Up @@ -543,7 +543,7 @@
#' returnTrue = FALSE)
#'
#' # draw simulation with fossil occurrences as time ranges
#' draw.sim(sim, fossils = fossils, fossilsToDraw = "ranges")
#' draw.sim(sim, fossils = fossils, fossilsFormat = "ranges")
#'
#' ###
#' # we can also have a mix of age-independent and age-dependent
Expand Down Expand Up @@ -634,7 +634,7 @@
#' bins = bins, returnTrue = FALSE)
#'
#' # draw simulation with fossil occurrences as ranges
#' draw.sim(sim, fossils = fossils, fossilsToDraw = "ranges")
#' draw.sim(sim, fossils = fossils, fossilsFormat = "ranges")
#'
#' # note how occurrences cluster close to the speciation time of
#' # species 1, but not its extinction time, since around 5mya
Expand Down
2 changes: 1 addition & 1 deletion R/sample.clade.traits.R
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
#'
#' # draw simulation with fossil occurrences as time points AND ranges
#' draw.sim(sim$SIM, traits = sim$TRAITS, fossils = fossils$FOSSILS,
#' fossilsToDraw = "all", traitLegendPlacement = "bottomleft")
#' fossilsFormat = "all", traitLegendPlacement = "bottomleft")
#' # note that there are a lot of fossils, so the ranges are difficult to see
#'
#' # see ?sample.clade for further examples using different return types
Expand Down
5 changes: 4 additions & 1 deletion man/bd.sim.Rd

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

5 changes: 4 additions & 1 deletion man/bd.sim.traits.Rd

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

14 changes: 7 additions & 7 deletions man/sample.clade.Rd

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

2 changes: 1 addition & 1 deletion man/sample.clade.traits.Rd

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

4 changes: 2 additions & 2 deletions vignettes/overview.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ simHead <- head(sim, 10)
suppressMessages(draw.sim(simHead, fossils = fossils))
```

We can also visualize the fossil ranges if we take away the `SampT` column, and set the `fossilsToDraw` parameter to `ranges`.
We can also visualize the fossil ranges if we take away the `SampT` column, and set the `fossilsFormat` parameter to `ranges`.

```{r}
# draw longevities with fossil time ranges
suppressMessages(draw.sim(simHead, fossils = fossils[, -3], fossilsToDraw = "ranges"))
suppressMessages(draw.sim(simHead, fossils = fossils[, -3], fossilsFormat = "ranges"))
```

This fossil record's data frame organization allows for easy evaluation of its components, and is close to ready for use in PyRate, one of the most widely used birth-death rates estimators in the field currently. To make it ready we must manipulate the `Extant` column, left like this for clarity. In PyRate, that column must be `status`, with extant species marked `extant` and extinct species marked `extinct`.
Expand Down

0 comments on commit 2165b43

Please sign in to comment.