Skip to content

Commit

Permalink
Change default options
Browse files Browse the repository at this point in the history
  • Loading branch information
nfrerebeau committed Jan 2, 2025
1 parent 43ebf19 commit d9f3fb4
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 44 deletions.
36 changes: 22 additions & 14 deletions R/diversity_alpha.R
Original file line number Diff line number Diff line change
Expand Up @@ -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_)
}

Expand Down Expand Up @@ -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_)
}

Expand Down Expand Up @@ -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_)
}

Expand Down Expand Up @@ -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_)
}

Expand Down
2 changes: 1 addition & 1 deletion R/statistics.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
7 changes: 7 additions & 0 deletions R/tabula-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
#'
Expand Down
4 changes: 2 additions & 2 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -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])
Expand Down
3 changes: 1 addition & 2 deletions inst/tinytest/test_index.R
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 0 additions & 3 deletions inst/tinytest/test_statistics.R
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
11 changes: 11 additions & 0 deletions man/tabula-package.Rd

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

18 changes: 7 additions & 11 deletions po/R-fr.po
Original file line number Diff line number Diff line change
@@ -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 <nicolas.frerebeau@u-bordeaux-montaigne."
"fr>\n"
Expand All @@ -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é."

Expand Down Expand Up @@ -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 ""
18 changes: 7 additions & 11 deletions po/R-tabula.pot
Original file line number Diff line number Diff line change
@@ -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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand All @@ -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 ""

Expand Down Expand Up @@ -71,7 +71,3 @@ msgstr ""
#: rarefaction.R:126
msgid "Expected species index"
msgstr ""

#: statistics.R:52
msgid "Ramanujan approximation of x!"
msgstr ""

0 comments on commit d9f3fb4

Please sign in to comment.