Skip to content

Commit

Permalink
Fixes bug in option passing apa_interval() and fixes failing tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
crsh committed Oct 23, 2024
1 parent a469051 commit c9a6ed5
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 64 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@
^vignettes/papaja.tex$
^CRAN-SUBMISSION$
^revdep$
^.luarc.json$
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Imports:
knitr (>= 1.26),
methods,
rmarkdown (>= 2.4),
rmdfiltr (>= 0.1.3),
rmdfiltr (>= 0.1.5),
utils,
yaml,
zip
Expand Down
59 changes: 38 additions & 21 deletions R/apa_interval.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,19 @@
#' apa_confint(confint(lm(cars)))
#' apa_confint(confint(lm(cars)), digits = 3)

apa_interval <- function(
x
, conf.int = NULL
, interval_type = NULL
, enclose_math = FALSE
, ...
) {
sapply(x, validate, name = "x", check_class = "numeric", check_infinite = FALSE)
validate(enclose_math, check_class = "logical", check_length = 1)
if(!is.null(interval_type)) validate(interval_type, check_class = "character", check_length = 1)
apa_interval <- function(x, ...) {
ellipsis <- list(...)
enclose_math <- ellipsis$enclose_math
interval_type <- ellipsis$interval_type
conf.int <- ellipsis$conf.int

sapply(x, validate, name = "x", check_class = "numeric", check_infinite = FALSE)
if(!is.null(enclose_math)) validate(enclose_math, check_class = "logical", check_length = 1)
if(!is.null(interval_type)) validate(interval_type, check_class = "character", check_length = 1)

if(!is.null(conf.int)) validate(conf.int, check_class = "numeric", check_length = 1, check_range = c(0, 100))
if(!is.null(conf.int)) validate(conf.int, check_class = "numeric", check_length = 1, check_range = c(0, 100))

UseMethod("apa_interval", x)
UseMethod("apa_interval", x)
}

#' @rdname apa_interval
Expand All @@ -70,10 +69,10 @@ apa_interval.default <- function(x, ...) {
apa_interval.numeric <- function(
x
, y = NULL
, ...
, conf.int = NULL
, interval_type = NULL
, enclose_math = FALSE
, ...
) {
ellipsis_ci <- deprecate_ci(conf.int = conf.int, ...)
conf.int <- ellipsis_ci$conf.int
Expand Down Expand Up @@ -145,10 +144,10 @@ apa_interval.numeric <- function(

apa_interval.matrix <- function(
x
, ...
, conf.int = NULL
, interval_type = NULL
, enclose_math = FALSE
, ...
) {
ellipsis_ci <- deprecate_ci(conf.int = conf.int, ...)
conf.int <- ellipsis_ci$conf.int
Expand Down Expand Up @@ -218,13 +217,19 @@ apa_interval.matrix <- function(

apa_interval.data.frame <- function(
x
, ...
, conf.int = NULL
, interval_type = NULL
, enclose_math = FALSE
, ...
) {
x <- as.matrix(x)
apa_interval(x, ...)
apa_interval(
x
, interval_type = interval_type
, conf.int = conf.int
, enclose_math = enclose_math
, ...
)
}

#' @rdname apa_interval
Expand All @@ -233,10 +238,10 @@ apa_interval.data.frame <- function(

apa_interval.list <- function(
x
, ...
, conf.int = NULL
, interval_type = NULL
, enclose_math = FALSE
, ...
) {
x <- as.data.frame(x)
apa_interval(x, ...)
Expand All @@ -248,12 +253,18 @@ apa_interval.list <- function(

apa_confint <- function(
x
, ...
, conf.int = NULL
, interval_type = "CI"
, enclose_math = FALSE
, ...
) {
apa_interval(x, interval_type = interval_type, ...)
apa_interval(
x
, interval_type = interval_type
, conf.int = conf.int
, enclose_math = enclose_math
, ...
)
}

#' @rdname apa_interval
Expand All @@ -266,12 +277,18 @@ print_confint <- apa_confint

apa_hdint <- function(
x
, ...
, conf.int = NULL
, interval_type = "HDI"
, enclose_math = FALSE
, ...
) {
apa_interval(x, interval_type = interval_type, ...)
apa_interval(
x
, interval_type = interval_type
, conf.int = conf.int
, enclose_math = enclose_math
, ...
)
}

#' @rdname apa_interval
Expand Down
10 changes: 5 additions & 5 deletions R/apa_print_wsci.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ apa_print.papaja_wsci <- function(x, ...) {
"$M = "
, apa_num(summary_wsci$mean, ...)
, "$, "
,
apa_confint(
x = summary_wsci[, c("lower_limit", "upper_limit")]
, conf.int = attr(x, "Confidence level")
, ...
, apa_confint(
x = summary_wsci[, c("lower_limit", "upper_limit")]
, conf.int = attr(x, "Confidence level")
, enclose_math = TRUE
, ...
)
)
)
Expand Down
54 changes: 21 additions & 33 deletions man/apa_interval.Rd

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

2 changes: 1 addition & 1 deletion tests/testthat/test_apa_print_wsci.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test_that(
)
expect_identical(
apa_wsci$estimate$N0_P0
, "$M = 51.717$, 98\\% CI [46.603, 56.831]"
, "$M = 51.717$, 98\\% CI $[46.603, 56.831]$"
)
}
)
6 changes: 3 additions & 3 deletions tests/testthat/test_meta.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ test_that(
lang <- papaja:::localize("english")

expect_is(lang, "list")
expect_equal(length(lang), 9)
expect_equal(names(lang), c("author_note", "abstract", "keywords", "word_count", "table", "figure", "note", "correspondence", "email"))
expect_equivalent(sapply(lang, class), rep("character", 9))
expect_equal(length(lang), 14)
expect_equal(names(lang), c("author_note", "abstract", "keywords", "word_count", "table", "figure", "note", "correspondence", "email", "version", "and", "cite_r_packages_s", "cite_r_packages_pl", "cite_r_footnote"))
expect_equivalent(sapply(lang, class), rep("character", 14))
}
)

0 comments on commit c9a6ed5

Please sign in to comment.