From 53a1e7ff6293d373d8c8d3e83eaafa17b340a237 Mon Sep 17 00:00:00 2001 From: gaballench Date: Tue, 4 Jun 2024 08:02:20 -0300 Subject: [PATCH] Version 1.4.2 accepted on CRAN. --- DESCRIPTION | 24 +++++++++++++----------- R/conflate.R | 14 ++++---------- R/crossplot.R | 4 ---- R/measureSimil.R | 2 +- R/stratCI.R | 2 +- R/summaryBrlen.R | 6 ++++-- R/table2nexus.R | 2 +- R/tnt2newick.R | 14 ++------------ R/topoFreq.R | 1 + R/xintercept.R | 2 +- man/conflate.Rd | 8 +------- man/crossplot.Rd | 4 ---- man/density_fun.Rd | 2 +- man/measureSimil.Rd | 2 +- man/summaryBrlen.Rd | 6 ++++-- man/table2nexus.Rd | 2 +- man/tbea-package.Rd | 4 ++-- man/tnt2newick.Rd | 14 ++------------ man/topoFreq.Rd | 1 + man/xintercept.Rd | 2 +- tests/testthat/test-tnt2newick.R | 5 +++-- 21 files changed, 45 insertions(+), 76 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index c68052b..433358e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,20 +1,22 @@ Package: tbea -Title: Tools for Pre- And Post-Processing in Bayesian Evolutionary Analyses +Title: Pre- And Post-Processing in Bayesian Evolutionary Analyses Version: 1.4.2 Authors@R: c(person("Gustavo A.", "Ballen", email = "gustavo.a.ballen@gmail.com", role = c("aut", "cre")), person("Sandra", "Reinales", email = "spreinalesl@gmail.com", role = c("aut"))) -Description: Package for Bayesian inference in phylogenetics and evolution. - It provides functions for prior specification in divergence time - estimation using fossils as well as other kinds of data. The package +Description: Functions are provided for prior specification in divergence time + estimation using fossils as well as other kinds of data. It provides tools for interacting with the input and output of Bayesian - platforms in evolutionary biology such as BEAST2, MrBayes, RevBayes, - or MCMCTree. - The package implements a way to measure similarity between probability - density functions in the context of comparisons between prior and + platforms in evolutionary biology such as 'BEAST2', 'MrBayes', 'RevBayes', + or 'MCMCTree'. + It Implements a simple measure similarity between probability + density functions for comparing prior and posterior Bayesian densities, as well as code for calculating the - combination of distributions using conflation. Tools for estimating the - origination time in collections of distributions using x-intercept and - stratigraphic intervals are also available. + combination of distributions using conflation of Hill (2008). Functions for estimating the + origination time in collections of distributions using the x-intercept (e.g., Draper and Smith, 1998) and + stratigraphic intervals (Marshall 2010) are also available. + Hill, T. 2008. "Conflations of probability distributions". Transactions of the American Mathematical Society, 363:3351-3372. , + Draper, N. R. and Smith, H. 1998. "Applied Regression Analysis". 1--706. Wiley Interscience, New York. , + Marshall, C. R. 2010. "Using confidence intervals to quantify the uncertainty in the end-points of stratigraphic ranges". Quantitative Methods in Paleobiology, 291--316. . Depends: R (>= 3.5.0) Imports: ape, Rfit, boot, graphics, stats, utils, coda License: file LICENSE diff --git a/R/conflate.R b/R/conflate.R index 70dc261..eefd2c2 100644 --- a/R/conflate.R +++ b/R/conflate.R @@ -16,13 +16,7 @@ #' conflated PDF on the sequence of x values determined by #' a number n of equidistant points between from and to. #' @examples -#' \dontrun{ -#' conflate(c("density_fun(x, 'dnorm', mean=0, sd=1)", -#' "density_fun(x, 'dnorm', mean=3, sd=1)"), -#' from=-4, to=4, n=101, add=TRUE, plot=TRUE) -#' curve(density_fun(x, 'dnorm', mean=0, sd=1), add=TRUE, col="red") -#' curve(density_fun(x, 'dnorm', mean=3, sd=1), add=TRUE, col="blue") -#' +#' \donttest{ #' conflated_normals <- conflate(c("density_fun(x, 'dnorm', mean=0, sd=1)", #' "density_fun(x, 'dnorm', mean=3, sd=1)"), #' from=-4, to=4, n=101, plot=FALSE) @@ -60,7 +54,7 @@ conflate <- function(pdfs, plot = TRUE, from, to, n, add = FALSE) { #' See the documentation for each individual distribution to call their parameters #' adequately. Argument names and values should be used. #' @examples -#' \dontrun{ +#' \donttest{ #' c("density_fun(x, 'dnorm', mean=0, sd=1)", #' "density_fun(x, 'dnorm', mean=-1, sd=1)", #' "density_fun(x, 'dnorm', mean=1, sd=1)") @@ -93,7 +87,7 @@ density_fun <- function(x, dist, ...) { #' with densities / int(densities) in an appropriate #' interval from--to #' @examples -#' \dontrun{ +#' \donttest{ #' conflated <- .str_conflate("density_fun(x, 'dnorm', mean=0, sd=1)", "density_fun(x, 'dnorm', mean=3, sd=1)", from = -1, to = 1) #' } #' @@ -122,7 +116,7 @@ density_fun <- function(x, dist, ...) { #' conflation but it is also useful for calculating a series #' of x values of the conflated PDF from a sequence of x values #' @examples -#' \dontrun{ +#' \donttest{ #' conflated <- .str_conflate("density_fun(x, 'dnorm', mean=0, sd=1)", "density_fun(x, 'dnorm', mean=3, sd=1)", from = -1, to = 1) #' } #' diff --git a/R/crossplot.R b/R/crossplot.R index db0e93e..7ef5936 100644 --- a/R/crossplot.R +++ b/R/crossplot.R @@ -49,10 +49,6 @@ #' #' @examples #' \dontrun{ -#' write.table(x=data.frame(par1=rnorm(1000), par2=rnorm(1000), par3=rnorm(1000), -#' par4=rnorm(1000), par5=rnorm(1000)), file="log1.tsv", row.names=FALSE) -#' write.table(x=data.frame(par1=rnorm(1000), par2=rnorm(1000), par3=rnorm(1000), -#' par4=rnorm(1000, mean=5), par5=rnorm(1000)), file="log2.tsv", row.names=FALSE) #' crossplot(log1Path="log1.tsv", log2Path="log2.tsv", skip.char="#", #' pattern="par", cols=NULL, bar.lty=1, bar.lwd=1, #' identity.lty=2, identity.lwd=1, diff --git a/R/measureSimil.R b/R/measureSimil.R index 8b31bec..96284f7 100644 --- a/R/measureSimil.R +++ b/R/measureSimil.R @@ -18,7 +18,7 @@ #' #' @details Similarity is measured as the overlapping portion between two densities. It has a value between 0 and 1. The values of the vector rawData determine the behavior of the function and therefore attention must be paid to their consistence with the nature of arguments d1 and d2. Despite the function was designed in order to allow to quantify similarity between the posterior and the prior, this can be used to quantify any overlap between two given densities and for any other purpose. #' @examples -#' \dontrun{ +#' \donttest{ #' # Set seed and colors to use in plots in the order: Prior, posterior, and intersection #' set.seed(1985) #' colors <- c("red", "blue", "lightgray") diff --git a/R/stratCI.R b/R/stratCI.R index ec4655d..6bc01ad 100644 --- a/R/stratCI.R +++ b/R/stratCI.R @@ -246,7 +246,7 @@ stratCI <- function(times, method, nparams, C, endpoint, confidence, quantile) { if(output >= 1) { return(output) } else { - print("Impossible to calculate lower bound") + message("Impossible to calculate lower bound\n") } } diff --git a/R/summaryBrlen.R b/R/summaryBrlen.R index 5b945d5..5b95eea 100644 --- a/R/summaryBrlen.R +++ b/R/summaryBrlen.R @@ -13,16 +13,18 @@ #' first enclosed in a list #' #' @examples -#' \dontrun{ +#' \donttest{ #' set.seed(1) +#' library(ape) #' trl <- ape::rmtree(10, 4) #' tpf <- topoFreq(unroot(trl), output="trees") #' sumtrees <- summaryBrlen(tpf$trees, method = "median") +#' oldpar <- par(no.readonly = TRUE) #' par(mfrow=c(1,3)) #' plot(sumtrees[[1]], type="unrooted", show.node.label=FALSE, cex=1.5) #' plot(sumtrees[[2]], type="unrooted", show.node.label=FALSE, cex=1.5) #' plot(sumtrees[[3]], type="unrooted", show.node.label=FALSE, cex=1.5) -#' par(mfrow=c(1,1)) +#' par(oldpar) #' } #' #' @export diff --git a/R/table2nexus.R b/R/table2nexus.R index 6600a59..f2be3f1 100644 --- a/R/table2nexus.R +++ b/R/table2nexus.R @@ -28,7 +28,7 @@ #' @examples #' \dontrun{ #' # this will return the matrix to the console rather than to a file -#' table2nexus(path="../prototipos/morpho.csv", datatype="standard", header=FALSE, sep=",") +#' table2nexus(path="morpho.csv", datatype="standard", header=FALSE, sep=",") #' } #' @export #' @importFrom utils read.delim diff --git a/R/tnt2newick.R b/R/tnt2newick.R index c7fe183..5ce367d 100644 --- a/R/tnt2newick.R +++ b/R/tnt2newick.R @@ -19,19 +19,9 @@ #' @details This function has been tested for cases where only one tree is in the original tnt tree file. Please be careful with files containing multiple trees. #' #' @examples -#' # create a file with multiple trees tree in TNT format to convert to newick format -#' writeLines( -#' text = c( -#' "tread 'some comment'", -#' "(Taxon_A ((Taxon_B Taxon_C)(Taxon_D Taxon_E)))*", -#' "(Taxon_A (Taxon_B (Taxon_C (Taxon_D Taxon_E))))*", -#' "(Taxon_A (Taxon_C (Taxon_B (Taxon_D Taxon_E))));", -#' "proc-;" -#' ), -#' con = "someTrees.tre" -#' ) +#' \dontrun{ #' tnt2newick(file = "someTrees.tre", return = TRUE) -#' file.remove("someTrees.tre") +#' } #' @export tnt2newick <- function(file, output = NULL, string = NULL, return = FALSE, subsetting = FALSE, name.sep = NULL){ diff --git a/R/topoFreq.R b/R/topoFreq.R index 9acb285..52316aa 100644 --- a/R/topoFreq.R +++ b/R/topoFreq.R @@ -20,6 +20,7 @@ #' @examples #' # tests #' set.seed(1) +#' library(ape) #' trl <- ape::rmtree(10, 4) #' tpf <- topoFreq(ape::unroot(trl), output="trees") #' diff --git a/R/xintercept.R b/R/xintercept.R index a3bc7dd..75de33c 100644 --- a/R/xintercept.R +++ b/R/xintercept.R @@ -39,7 +39,7 @@ #' ages <- ages[complete.cases(ages)] # remove NAs #' ages <- ages[which(ages < 10)] # remove outliers #' -#' \dontrun{ +#' \donttest{ #' # Draper-Smith, OLS #' draperSmithNormalX0 <- xintercept(x = ages, method = "Draper-Smith", alpha = 0.05, robust = FALSE) #' # Draper-Smith, Robust fit diff --git a/man/conflate.Rd b/man/conflate.Rd index d683189..a2791df 100644 --- a/man/conflate.Rd +++ b/man/conflate.Rd @@ -34,13 +34,7 @@ conflated PDF on the sequence of x values determined by a number n of equidistant points between from and to. } \examples{ -\dontrun{ -conflate(c("density_fun(x, 'dnorm', mean=0, sd=1)", - "density_fun(x, 'dnorm', mean=3, sd=1)"), - from=-4, to=4, n=101, add=TRUE, plot=TRUE) -curve(density_fun(x, 'dnorm', mean=0, sd=1), add=TRUE, col="red") -curve(density_fun(x, 'dnorm', mean=3, sd=1), add=TRUE, col="blue") - +\donttest{ conflated_normals <- conflate(c("density_fun(x, 'dnorm', mean=0, sd=1)", "density_fun(x, 'dnorm', mean=3, sd=1)"), from=-4, to=4, n=101, plot=FALSE) diff --git a/man/crossplot.Rd b/man/crossplot.Rd index b3b13d2..ef4d838 100644 --- a/man/crossplot.Rd +++ b/man/crossplot.Rd @@ -71,10 +71,6 @@ then they should fall on the identity y=x line. } \examples{ \dontrun{ -write.table(x=data.frame(par1=rnorm(1000), par2=rnorm(1000), par3=rnorm(1000), - par4=rnorm(1000), par5=rnorm(1000)), file="log1.tsv", row.names=FALSE) -write.table(x=data.frame(par1=rnorm(1000), par2=rnorm(1000), par3=rnorm(1000), - par4=rnorm(1000, mean=5), par5=rnorm(1000)), file="log2.tsv", row.names=FALSE) crossplot(log1Path="log1.tsv", log2Path="log2.tsv", skip.char="#", pattern="par", cols=NULL, bar.lty=1, bar.lwd=1, identity.lty=2, identity.lwd=1, diff --git a/man/density_fun.Rd b/man/density_fun.Rd index c621866..8299375 100644 --- a/man/density_fun.Rd +++ b/man/density_fun.Rd @@ -27,7 +27,7 @@ See the documentation for each individual distribution to call their parameters adequately. Argument names and values should be used. } \examples{ -\dontrun{ +\donttest{ c("density_fun(x, 'dnorm', mean=0, sd=1)", "density_fun(x, 'dnorm', mean=-1, sd=1)", "density_fun(x, 'dnorm', mean=1, sd=1)") diff --git a/man/measureSimil.Rd b/man/measureSimil.Rd index 883f27b..648244a 100644 --- a/man/measureSimil.Rd +++ b/man/measureSimil.Rd @@ -40,7 +40,7 @@ Calculate the Intersection Between Two Densities Similarity is measured as the overlapping portion between two densities. It has a value between 0 and 1. The values of the vector rawData determine the behavior of the function and therefore attention must be paid to their consistence with the nature of arguments d1 and d2. Despite the function was designed in order to allow to quantify similarity between the posterior and the prior, this can be used to quantify any overlap between two given densities and for any other purpose. } \examples{ -\dontrun{ +\donttest{ # Set seed and colors to use in plots in the order: Prior, posterior, and intersection set.seed(1985) colors <- c("red", "blue", "lightgray") diff --git a/man/summaryBrlen.Rd b/man/summaryBrlen.Rd index 9261219..f400b6b 100644 --- a/man/summaryBrlen.Rd +++ b/man/summaryBrlen.Rd @@ -26,16 +26,18 @@ tree density. Alternatively, it can be used with a single element provided that first enclosed in a list } \examples{ -\dontrun{ +\donttest{ set.seed(1) +library(ape) trl <- ape::rmtree(10, 4) tpf <- topoFreq(unroot(trl), output="trees") sumtrees <- summaryBrlen(tpf$trees, method = "median") +oldpar <- par(no.readonly = TRUE) par(mfrow=c(1,3)) plot(sumtrees[[1]], type="unrooted", show.node.label=FALSE, cex=1.5) plot(sumtrees[[2]], type="unrooted", show.node.label=FALSE, cex=1.5) plot(sumtrees[[3]], type="unrooted", show.node.label=FALSE, cex=1.5) -par(mfrow=c(1,1)) +par(oldpar) } } diff --git a/man/table2nexus.Rd b/man/table2nexus.Rd index 97b24bb..772c223 100644 --- a/man/table2nexus.Rd +++ b/man/table2nexus.Rd @@ -45,7 +45,7 @@ This function will concatenate matrices in nexus format (mandatory) and write to \examples{ \dontrun{ # this will return the matrix to the console rather than to a file -table2nexus(path="../prototipos/morpho.csv", datatype="standard", header=FALSE, sep=",") +table2nexus(path="morpho.csv", datatype="standard", header=FALSE, sep=",") } } \author{ diff --git a/man/tbea-package.Rd b/man/tbea-package.Rd index 38277cc..14fc9bf 100644 --- a/man/tbea-package.Rd +++ b/man/tbea-package.Rd @@ -4,9 +4,9 @@ \name{tbea-package} \alias{tbea} \alias{tbea-package} -\title{tbea: Tools for Pre- And Post-Processing in Bayesian Evolutionary Analyses} +\title{tbea: Pre- And Post-Processing in Bayesian Evolutionary Analyses} \description{ -Package for Bayesian inference in phylogenetics and evolution. It provides functions for prior specification in divergence time estimation using fossils as well as other kinds of data. The package provides tools for interacting with the input and output of Bayesian platforms in evolutionary biology such as BEAST2, MrBayes, RevBayes, or MCMCTree. The package implements a way to measure similarity between probability density functions in the context of comparisons between prior and posterior Bayesian densities, as well as code for calculating the combination of distributions using conflation. Tools for estimating the origination time in collections of distributions using x-intercept and stratigraphic intervals are also available. +Functions are provided for prior specification in divergence time estimation using fossils as well as other kinds of data. It provides tools for interacting with the input and output of Bayesian platforms in evolutionary biology such as 'BEAST2', 'MrBayes', 'RevBayes', or 'MCMCTree'. It Implements a simple measure similarity between probability density functions for comparing prior and posterior Bayesian densities, as well as code for calculating the combination of distributions using conflation of Hill (2008). Functions for estimating the origination time in collections of distributions using the x-intercept (e.g., Draper and Smith, 1998) and stratigraphic intervals (Marshall 2010) are also available. Hill, T. 2008. "Conflations of probability distributions". Transactions of the American Mathematical Society, 363:3351-3372. \doi{10.48550/arXiv.0808.1808}, Draper, N. R. and Smith, H. 1998. "Applied Regression Analysis". 1--706. Wiley Interscience, New York. \doi{10.1002/9781118625590}, Marshall, C. R. 2010. "Using confidence intervals to quantify the uncertainty in the end-points of stratigraphic ranges". Quantitative Methods in Paleobiology, 291--316. \doi{10.1017/S1089332600001911}. } \seealso{ Useful links: diff --git a/man/tnt2newick.Rd b/man/tnt2newick.Rd index 7892a52..d31e8ce 100644 --- a/man/tnt2newick.Rd +++ b/man/tnt2newick.Rd @@ -36,19 +36,9 @@ tnt2newick: Function for converting from TNT tree format to newick parenthetical This function has been tested for cases where only one tree is in the original tnt tree file. Please be careful with files containing multiple trees. } \examples{ -# create a file with multiple trees tree in TNT format to convert to newick format -writeLines( -text = c( -"tread 'some comment'", -"(Taxon_A ((Taxon_B Taxon_C)(Taxon_D Taxon_E)))*", -"(Taxon_A (Taxon_B (Taxon_C (Taxon_D Taxon_E))))*", -"(Taxon_A (Taxon_C (Taxon_B (Taxon_D Taxon_E))));", -"proc-;" -), -con = "someTrees.tre" -) +\dontrun{ tnt2newick(file = "someTrees.tre", return = TRUE) -file.remove("someTrees.tre") +} } \author{ Gustavo A. Ballen diff --git a/man/topoFreq.Rd b/man/topoFreq.Rd index 8bd44e8..1011d99 100644 --- a/man/topoFreq.Rd +++ b/man/topoFreq.Rd @@ -34,6 +34,7 @@ cause any issues under your computing conditions (e.g. when lots of trees are be \examples{ # tests set.seed(1) +library(ape) trl <- ape::rmtree(10, 4) tpf <- topoFreq(ape::unroot(trl), output="trees") diff --git a/man/xintercept.Rd b/man/xintercept.Rd index 359eacb..7e1a3d8 100644 --- a/man/xintercept.Rd +++ b/man/xintercept.Rd @@ -49,7 +49,7 @@ ages <- andes$ages ages <- ages[complete.cases(ages)] # remove NAs ages <- ages[which(ages < 10)] # remove outliers -\dontrun{ +\donttest{ # Draper-Smith, OLS draperSmithNormalX0 <- xintercept(x = ages, method = "Draper-Smith", alpha = 0.05, robust = FALSE) # Draper-Smith, Robust fit diff --git a/tests/testthat/test-tnt2newick.R b/tests/testthat/test-tnt2newick.R index 386a540..8cb1e0c 100644 --- a/tests/testthat/test-tnt2newick.R +++ b/tests/testthat/test-tnt2newick.R @@ -1,4 +1,5 @@ -# create some input tree and their expected outputs +# create some input tree and their expected outputs in the tempdir() +setwd(tempdir()) # create a file with multiple trees in TNT format to convert to newick format writeLines( @@ -53,6 +54,6 @@ test_that("number of name separators got completely replaced using name.sep", { sum(sapply(gregexpr(pattern = "--", text = tnt2newick(file = "someTrees.tre", output = NULL, string = NULL, return = TRUE, subsetting = FALSE, name.sep = c("_", "--")), fixed=TRUE), function(i) sum(i > 0)))) }) -# clean tesating files +# clean testing files file.remove(dir(pattern = ".tre$")) file.remove(dir(pattern = ".newick$"))