Skip to content

Commit 206a65e

Browse files
committed
small bugs
1 parent 2aadd12 commit 206a65e

File tree

8 files changed

+60
-20
lines changed

8 files changed

+60
-20
lines changed

CRAN-SUBMISSION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Version: 0.1.0
2-
Date: 2025-08-20 01:18:48 UTC
3-
SHA: da76a978e9a823001eadebb1cbae68dd8eb6635e
2+
Date: 2025-09-05 18:05:50 UTC
3+
SHA: 2aadd12809085f1cd9aea7b53198c5b042eccbaf

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: apa7
22
Title: Facilitate Writing Documents in American Psychological Association
33
Style, Seventh Edition
4-
Version: 0.1.0
4+
Version: 0.1.1
55
Authors@R:
66
person("W. Joel", "Schneider", , "w.joel.schneider@gmail.com", role = c("aut", "cre"),
77
comment = c(ORCID = "0000-0002-8393-5316"))

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# apa7 0.1.1 _2025-09-07_
2+
3+
* Fix `align_chr` so that setting `format_numeric_character = FALSE` works.
4+
* `list_column` gains a `unite` parameter that joins list and text columns.
5+
* `add_star_column` no longer add stars if the column value is missing.
6+
17
# apa7 0.1.0 _2025-08-19_
28

39
* Initial Cran Release

R/formating.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ align_chr <- function(
4848

4949
side <- match.arg(side, c("both", "left", "right"))
5050

51-
if (is.character(xx)) {
51+
if (is.character(xx) && format_numeric_character) {
5252
if (all(grepl("^[-0-9.]+$", xx))) xx <- as.numeric(xx)
5353
}
5454

@@ -642,7 +642,8 @@ the$pvalue_formatter <- \(x, accuracy = the$accuracy, ...) {
642642
x,
643643
markdown = TRUE,
644644
min_digits = min_digits,
645-
max_digits = max_digits, ...))
645+
max_digits = max_digits, ...),
646+
format_numeric_character = FALSE)
646647
}
647648

648649
the$trim_leading_zero <- \(x, accuracy = the$accuracy, ...) {

R/tables.R

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,23 @@ add_break_columns <- function(d,
7272
#' @param ... Column name or tidyselect function. Select columns. Default is first column
7373
#' @param type list type. Can be "1" (numeric), "a" (lowercase alphabetical), or "ABC" (uppercase alphabetical), "i" (lowercase Roman numerals), "I" (uppercase Roman numerals)
7474
#' @param sep separator
75+
#' @param merge If `TRUE`, list columns will be united with their respective text columns.
7576
#'
7677
#' @return data.frame
7778
#' @export
7879
#'
7980
#' @examples
8081
#' d <- data.frame(x = letters[1:5], y = letters[2:6])
8182
#' # default is first column
82-
#' add_list_column(d)
83+
#' add_list_column(d) |>
84+
#' apa_flextable()
8385
#' # select any column
84-
#' add_list_column(d, y)
86+
#' add_list_column(d, y) |>
87+
#' apa_flextable()
8588
#' add_list_column(d, type = "a", sep = ") ") |>
8689
#' apa_flextable()
87-
add_list_column <- function(data, ..., type = c("1", "a", "A", "I", "i"), sep = ".\u00A0") {
90+
#' add_list_column(d, merge = TRUE)
91+
add_list_column <- function(data, ..., type = c("1", "a", "A", "I", "i"), sep = ".\u00A0", merge = FALSE) {
8892
type <- match.arg(type)
8993
# l <- rlang::list2(...)
9094
nn <- colnames(dplyr::select(data, ...))
@@ -106,8 +110,13 @@ add_list_column <- function(data, ..., type = c("1", "a", "A", "I", "i"), sep =
106110

107111
for (n in nn) {
108112
vn <- paste0(n, "apa7listcolumn")
109-
data[vn] <- vl
110-
data <- dplyr::relocate(data, vn, .before = n)
113+
if (merge) {
114+
data[n] <- paste0(vl, data[[n]])
115+
} else {
116+
data[vn] <- vl
117+
data <- dplyr::relocate(data, vn, .before = n)
118+
}
119+
111120
}
112121
data
113122
}
@@ -174,7 +183,13 @@ add_star_column <- function(
174183
keys <- R.utils::insert(colnames(data),
175184
ats = where_numbers + 1,
176185
values = star_names)
177-
data[,star_names] <- p2stars(data[[p_names]], first_alpha_marginal = first_alpha_marginal, superscript = superscript, alpha = alpha, add_trailing_space = add_trailing_space, prefix = prefix)
186+
p_stars <- p2stars(data[[p_names]], first_alpha_marginal = first_alpha_marginal, superscript = superscript, alpha = alpha, add_trailing_space = add_trailing_space, prefix = prefix)
187+
188+
for (wn in where_names) {
189+
sn <- paste0(wn, "apa7starcolumn")
190+
data[,sn] <- ifelse(data[[wn]] == "" | is.na(data[[wn]]), "", p_stars)
191+
}
192+
178193
data <- data[,keys]
179194

180195
if (merge) {
@@ -409,7 +424,7 @@ dd |>
409424
#' @param star_significant start significant correlations
410425
#' @param significance_note If TRUE, place note at bottom of table that significant correlations are bolded.
411426
#' @param output output type. Can be "flextable" or "tibble"
412-
#' @param summary_functions A named list of functions that summarize data columns (e.g., mean, sd)
427+
#' @param summary_functions Any named list of functions that summarize data columns (e.g., `list(Mean = mean, SD = sd)`). Can also be a character vector of function names (e.g., `c("n", "M", "SD")`). Functions available in a character vector: IQR, Interquartile Range, Kurtosis, MAD, Median Absolute Deviation, M, Mean, Med, Median, n, N, Quantile, Range, SD, Skewness, Var, Variance
413428
#' @param keep_empty_star_columns Keep remove empty star columns (Default: `TRUE`)
414429
#' @param column_formats column_formats object
415430
#' @inheritParams apa_style
@@ -420,8 +435,10 @@ dd |>
420435
#' @export
421436
#'
422437
#' @examples
423-
#' apa_cor(mtcars[, c("mpg", "am", "gear", "carb")], output = "flextable")
424-
#' apa_cor(mtcars[, c("mpg", "am", "gear", "carb")], output = "tibble")
438+
#' apa_cor(mtcars[, c("mpg", "am", "gear", "carb")])
439+
#' apa_cor(mtcars[, c("mpg", "am", "gear", "carb")],
440+
#' output = "tibble",
441+
#' star_significant = FALSE)
425442
apa_cor <- function(data,
426443
note = NULL,
427444
p_value = c(.05, .01, .001),

man/add_list_column.Rd

Lines changed: 14 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/apa_cor.Rd

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/tests.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ test_that("align_chr", {
143143

144144
align_chr(c(".1", ".12^\\*\\*^")) |> align_chr()
145145

146+
expect_equal(align_chr(apa_p(posnum, min_digits = 3),
147+
format_numeric_character = FALSE), c(".010", ".511"))
148+
146149

147150
})
148151

0 commit comments

Comments
 (0)