diff --git a/R/diversity_alpha.R b/R/diversity_alpha.R index 5571b26..556436e 100644 --- a/R/diversity_alpha.R +++ b/R/diversity_alpha.R @@ -59,9 +59,12 @@ setMethod( F1 <- sum(x == 1) # Number of singleton species if (F1 == N_rare) { - warning(tr_("ACE is undefined when all rare species are singletons."), "\n", - tr_("Consider using the bias-corrected Chao1 estimator instead."), - call. = FALSE) + if (getOption("tabula.verbose")) { + message( + tr_("ACE is undefined when all rare species are singletons."), "\n", + tr_("Consider using the bias-corrected Chao1 estimator instead.") + ) + } return(NA_real_) } @@ -191,10 +194,11 @@ setMethod( f3 <- sum(x == 3) # Number of triple species f4 <- sum(x == 4) # Number of quadruple species if (f4 == 0) { - warning( - tr_("Improved Chao1 estimator is undefined when there is no quadruple species."), - call. = FALSE - ) + if (getOption("tabula.verbose")) { + message( + tr_("Improved Chao1 estimator is undefined when there is no quadruple species.") + ) + } return(NA_real_) } @@ -236,10 +240,11 @@ setMethod( q3 <- sum(q == 3) # Number of triple species q4 <- sum(q == 4) # Number of quadruple species if (q4 == 0) { - warning( - tr_("Improved Chao2 estimator is undefined when there is no quadruple species."), - call. = FALSE - ) + if (getOption("tabula.verbose")) { + message( + tr_("Improved Chao2 estimator is undefined when there is no quadruple species.") + ) + } return(NA_real_) } @@ -272,9 +277,12 @@ setMethod( q1 <- sum(q == 1) # Number of unique species in the assemblage if (q1 == N_infr) { - warning(tr_("ICE is undefined when all rare species are singletons."), "\n", - tr_("Consider using the bias-corrected Chao2 estimator instead."), - call. = FALSE) + if (getOption("tabula.verbose")) { + message( + tr_("ICE is undefined when all rare species are singletons."), "\n", + tr_("Consider using the bias-corrected Chao2 estimator instead.") + ) + } return(NA_real_) } diff --git a/R/statistics.R b/R/statistics.R index 2b8a134..c2856f5 100644 --- a/R/statistics.R +++ b/R/statistics.R @@ -49,7 +49,7 @@ combination <- function(n, k) { arkhe::assert_scalar(k, "numeric") if (n > 170 | k > 170) { - if (getOption("tabula.verbose")) message(tr_("Ramanujan approximation of x!")) + ## Ramanujan approximation of x! c <- exp(ramanujan(n) - ramanujan(k) - ramanujan(n - k)) } else { c <- factorial(n) / (factorial(k) * factorial(n - k)) diff --git a/R/tabula-package.R b/R/tabula-package.R index 924ee18..6ee60c6 100644 --- a/R/tabula-package.R +++ b/R/tabula-package.R @@ -8,6 +8,13 @@ #' **JOSS:** \tab \doi{10.21105/joss.01821} \cr #' } #' +#' @section Package options: +#' \pkg{tabula} uses the following [options()] to configure behavior: +#' * `tabula.progress`: a [`logical`] scalar. Should progress bars be +#' displayed? Defaults to [interactive()]. +#' * `tabula.verbose`: a [`logical`] scalar. Should \R report extra information +#' on progress? Defaults to [interactive()]. +#' #' @author #' **Full list of authors and contributors** (alphabetic order) #' diff --git a/R/zzz.R b/R/zzz.R index 4020acd..406ddc6 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -1,8 +1,8 @@ .onLoad <- function(libname, pkgname){ op <- options() op.tabula <- list( - tabula.progress = TRUE, - tabula.verbose = FALSE + tabula.progress = interactive(), + tabula.verbose = interactive() ) toset <- !(names(op.tabula) %in% names(op)) if(any(toset)) options(op.tabula[toset]) diff --git a/inst/tinytest/test_index.R b/inst/tinytest/test_index.R index 774e658..8bd9f63 100644 --- a/inst/tinytest/test_index.R +++ b/inst/tinytest/test_index.R @@ -7,8 +7,7 @@ expect_equal(round(index_menhinick(n), 3), 1.534) # 1.534 expect_equal(round(index_margalef(n), 3), 3.7) # 3.7 expect_equal(round(index_berger(n), 3), 0.206) # 0.2059 expect_equal(round(index_chao1(n, unbiased = TRUE), 3), 21.491) # 21.49 -expect_warning(index_chao1(n, unbiased = TRUE, improved = TRUE)) # 22.65 (?) -expect_equal(suppressWarnings(index_chao1(n, unbiased = TRUE, improved = TRUE)), NA_real_) # 22.65 (?) +expect_equal(index_chao1(n, unbiased = TRUE, improved = TRUE), NA_real_) # 22.65 (?) expect_equal(round(index_ace(n), 3), 22.087) # 22.09 expect_equal(round(index_squares(n), 3), 21.924) # 21.92 diff --git a/inst/tinytest/test_statistics.R b/inst/tinytest/test_statistics.R index 26607d2..653177a 100644 --- a/inst/tinytest/test_statistics.R +++ b/inst/tinytest/test_statistics.R @@ -9,6 +9,3 @@ expect_equal(tabula:::combination(4, 3), 4) # Ramanujan factorial approx. expect_equal(tabula:::combination(171, 3), 818816.247275706) expect_error(tabula:::combination(3, "a")) - -options("tabula.verbose" = TRUE) -expect_message(tabula:::combination(171, 3), "Ramanujan approximation of x!") diff --git a/man/tabula-package.Rd b/man/tabula-package.Rd index 66462d3..e7db258 100644 --- a/man/tabula-package.Rd +++ b/man/tabula-package.Rd @@ -20,6 +20,17 @@ An easy way to examine archaeological count data. This package provides several \strong{JOSS:} \tab \doi{10.21105/joss.01821} \cr } } +\section{Package options}{ + +\pkg{tabula} uses the following \code{\link[=options]{options()}} to configure behavior: +\itemize{ +\item \code{tabula.progress}: a \code{\link{logical}} scalar. Should progress bars be +displayed? Defaults to \code{\link[=interactive]{interactive()}}. +\item \code{tabula.verbose}: a \code{\link{logical}} scalar. Should \R report extra information +on progress? Defaults to \code{\link[=interactive]{interactive()}}. +} +} + \seealso{ Useful links: \itemize{ diff --git a/po/R-fr.po b/po/R-fr.po index dcf3a45..2c9e529 100644 --- a/po/R-fr.po +++ b/po/R-fr.po @@ -1,7 +1,7 @@ msgid "" msgstr "" "Project-Id-Version: tabula 3.1.1.9000\n" -"POT-Creation-Date: 2025-01-02 17:05+0100\n" +"POT-Creation-Date: 2025-01-02 18:37+0100\n" "PO-Revision-Date: 2024-12-16 19:01+0100\n" "Last-Translator: Nicolas Frerebeau \n" @@ -12,37 +12,37 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" -#: diversity_alpha.R:62 +#: diversity_alpha.R:64 msgid "ACE is undefined when all rare species are singletons." msgstr "" "L'estimateur ACE est indéfini lorsque toutes les espèces rares sont des " "singletons." -#: diversity_alpha.R:63 +#: diversity_alpha.R:65 msgid "Consider using the bias-corrected Chao1 estimator instead." msgstr "Envisagez plutôt d'utiliser l'estimateur Chao1 non biaisé." -#: diversity_alpha.R:195 +#: diversity_alpha.R:199 msgid "" "Improved Chao1 estimator is undefined when there is no quadruple species." msgstr "" "L'estimateur Chao1 amélioré est indéfini lorsqu'il n'y a pas d'espèce " "quadruple." -#: diversity_alpha.R:240 +#: diversity_alpha.R:245 msgid "" "Improved Chao2 estimator is undefined when there is no quadruple species." msgstr "" "L'estimateur Chao2 amélioré est indéfini lorsqu'il n'y a pas d'espèce " "quadruple." -#: diversity_alpha.R:275 +#: diversity_alpha.R:282 msgid "ICE is undefined when all rare species are singletons." msgstr "" "L'estimateur ICE est indéfini lorsque toutes les espèces rares sont des " "singletons." -#: diversity_alpha.R:276 +#: diversity_alpha.R:283 msgid "Consider using the bias-corrected Chao2 estimator instead." msgstr "Envisagez plutôt d'utiliser l'estimateur Chao2 non biaisé." @@ -81,7 +81,3 @@ msgstr "Fréquence" #: rarefaction.R:126 msgid "Expected species index" msgstr "Indice de diversité attendu" - -#: statistics.R:52 -msgid "Ramanujan approximation of x!" -msgstr "" diff --git a/po/R-tabula.pot b/po/R-tabula.pot index da0591c..eadb33d 100644 --- a/po/R-tabula.pot +++ b/po/R-tabula.pot @@ -1,7 +1,7 @@ msgid "" msgstr "" "Project-Id-Version: tabula 3.1.1.9000\n" -"POT-Creation-Date: 2025-01-02 17:05+0100\n" +"POT-Creation-Date: 2025-01-02 18:37+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -10,29 +10,29 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -#: diversity_alpha.R:62 +#: diversity_alpha.R:64 msgid "ACE is undefined when all rare species are singletons." msgstr "" -#: diversity_alpha.R:63 +#: diversity_alpha.R:65 msgid "Consider using the bias-corrected Chao1 estimator instead." msgstr "" -#: diversity_alpha.R:195 +#: diversity_alpha.R:199 msgid "" "Improved Chao1 estimator is undefined when there is no quadruple species." msgstr "" -#: diversity_alpha.R:240 +#: diversity_alpha.R:245 msgid "" "Improved Chao2 estimator is undefined when there is no quadruple species." msgstr "" -#: diversity_alpha.R:275 +#: diversity_alpha.R:282 msgid "ICE is undefined when all rare species are singletons." msgstr "" -#: diversity_alpha.R:276 +#: diversity_alpha.R:283 msgid "Consider using the bias-corrected Chao2 estimator instead." msgstr "" @@ -71,7 +71,3 @@ msgstr "" #: rarefaction.R:126 msgid "Expected species index" msgstr "" - -#: statistics.R:52 -msgid "Ramanujan approximation of x!" -msgstr ""