From 86cc33995f22122af04bd668957deacba66664a9 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 1 Sep 2026 07:09:11 +0000 Subject: [PATCH 1/2] Fix as_tibble_from_namedVec() returning a character matrix, not a tibble, for its default argument With transpose = TRUE (the default), the function built a 2-column (name, value) tibble, then did t(as.matrix(tbl)). as.matrix() on a mixed-type tibble coerces every column to a common type (character here, since one column is character), so the "transposed" result was always a character matrix - not a tibble as the function's own name and @description promise ("Convert a vector with names into a tibble"), and the original numeric type of the input vector was lost (e.g. 1 became "1"). Fix: use tibble::as_tibble_row(vec.w.names) for the transpose = TRUE branch - the standard tibble-package primitive for converting a named vector into a single-row, names-as-columns tibble, which preserves the input's original type. transpose = FALSE is unchanged (already returned a valid two-column tibble). Also removed a leftover commented-out alternative implementation of this same logic that was superseded by the current code before this fix. Verified: as_tibble_from_namedVec() (default args) now returns an actual tibble with the numeric type preserved, instead of a character matrix; as_tibble_from_namedVec(transpose = FALSE) is unaffected. Version bumped 2.8.16 -> 2.8.21 (distinct from sibling PRs #75/#76/#77/#78, which also branch from the same 2.8.16 base and already claimed 2.8.17-2.8.20). --- DESCRIPTION | 2 +- Development/config.R | 2 +- R/CodeAndRoll2.R | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 227f9ee..b910e18 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: CodeAndRoll2 Title: CodeAndRoll2 for vector, matrix and list manipulations -Version: 2.8.16 +Version: 2.8.21 Authors@R: person("Abel", "Vertesy", , "av@imba.oeaw.ac.at", role = c("aut", "cre")) Description: CodeAndRoll2 is a set of more than 170 productivity functions diff --git a/Development/config.R b/Development/config.R index cc4bdcb..28dd1ac 100644 --- a/Development/config.R +++ b/Development/config.R @@ -3,7 +3,7 @@ DESCRIPTION <- list( package.name = "CodeAndRoll2", - version = "2.8.16", + version = "2.8.21", title = "CodeAndRoll2 for vector, matrix and list manipulations", description = "CodeAndRoll2 is a set of more than 170 productivity functions for vector, matrix and list manipulations and math. Used by MarkdownReports, ggExpress, SeuratUtils, etc.", diff --git a/R/CodeAndRoll2.R b/R/CodeAndRoll2.R index efafc51..b865b3d 100644 --- a/R/CodeAndRoll2.R +++ b/R/CodeAndRoll2.R @@ -1092,15 +1092,15 @@ tibble_summary_to_namedVec <- function( #' @export as_tibble_from_namedVec <- function(vec.w.names = c("a" = 1, "b" = 2), transpose = TRUE) { stopifnot(!is.null(names(vec.w.names))) - # tbl <- dplyr::bind_rows(vec.w.names) - # if (transpose) t(tbl) else tbl - tbl <- tibble::tibble( + if (transpose) { + return(tibble::as_tibble_row(vec.w.names)) + } + + tibble::tibble( name = names(vec.w.names), value = unname(vec.w.names) ) - - if (transpose) t(as.matrix(tbl)) else tbl } From 5d86ed19e9f1dcf526a0e0b35b886fcece50df4b Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 1 Sep 2026 07:14:27 +0000 Subject: [PATCH 2/2] Fix as_tibble_from_namedVec() rejecting duplicate/empty names after the tibble fix tibble::as_tibble_row() defaults to .name_repair = "check_unique", which errors on a vector with duplicate names (e.g. c(a=1, a=2)) - a regression versus the previous (buggy in a different way) implementation, which never validated column-name uniqueness since names were just data values in a "name" column, not column headers. Fix: pass .name_repair = "minimal" to as_tibble_row(), which accepts the names as-is without validation, matching the previous implementation's permissiveness. Verified: as_tibble_from_namedVec(c(a=1, a=2)) now succeeds instead of erroring; the default and transpose = FALSE cases are unaffected. --- R/CodeAndRoll2.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/CodeAndRoll2.R b/R/CodeAndRoll2.R index b865b3d..7286ee0 100644 --- a/R/CodeAndRoll2.R +++ b/R/CodeAndRoll2.R @@ -1094,7 +1094,7 @@ as_tibble_from_namedVec <- function(vec.w.names = c("a" = 1, "b" = 2), transpose stopifnot(!is.null(names(vec.w.names))) if (transpose) { - return(tibble::as_tibble_row(vec.w.names)) + return(tibble::as_tibble_row(vec.w.names, .name_repair = "minimal")) } tibble::tibble(