diff --git a/AGENTS.md b/AGENTS.md index a28a654..29a97ec 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,6 +1,6 @@ # Guidance for Agents -Version: 2026.08.27-00:00 +Version: 2026.08.31-00:01 ## I: Generic (all @vertesy repos) @@ -31,7 +31,14 @@ For each finding, state: Keep only findings that can be explained clearly and concisely. Do not flag formatting, line length, or missing tests. -### 3. Update the Source, Not Just the Documentation +### 3. Pull Request Descriptions + +Open each PR with a few bullets per major change: what was wrong, how it was fixed, and whether it changes the function's output or behavior. + +- Scale the description to the change: a typo or comment-only fix needs one short line, not a paragraph. +- Keep the whole description under 250 words; reserve that ceiling for genuinely complex PRs. If it doesn't fit, split the PR instead of writing more. + +### 4. Update the Source, Not Just the Documentation Documentation is generated from upstream sources: `.Rd` files from roxygen annotations and `DESCRIPTION` from `Development/Dependencies.R` via `config.R`. @@ -41,7 +48,8 @@ Package rebuilds overwrite these files, so always update the upstream source fir - New arguments go at the end, just before `...`. Never insert in the middle. - Do not use tests. -- Whenever you are implementing a larger change (a bug fix, a substantial code change), you shoud increase the version number in `Development/config.R` by 0.0.1. +- Never update the package version unless the user explicitly requests a version change. +- Do not raise code review findings that ask for a package version change. ## III: CodeAndRoll2 specific diff --git a/DESCRIPTION b/DESCRIPTION index 57761fe..444ef2d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: CodeAndRoll2 Title: CodeAndRoll2 for vector, matrix and list manipulations -Version: 2.8.15 +Version: 2.8.20 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/Create_the_CodeAndRoll2_Package.R b/Development/Create_the_CodeAndRoll2_Package.R index 17f6b9c..7795738 100644 --- a/Development/Create_the_CodeAndRoll2_Package.R +++ b/Development/Create_the_CodeAndRoll2_Package.R @@ -85,7 +85,8 @@ for (scriptX in ls.scripts.full.path) { } file.edit(paste0(repository.dir, "/R/list.of.functions.in.", package.name, ".det.md")) file.edit(paste0(repository.dir, "/README.md")) -file.remove(paste0(repository.dir, "/R/list.of.functions.in.", package.name, ".det.md")) +# file.remove(paste0(repository.dir, "/R/list.of.functions.in.", package.name, ".det.md")) +file.remove(list.files(file.path(repository.dir, "R"), pattern = "^list\\.of\\.functions\\.in\\..+\\.det\\.md$", full.names = TRUE)) r$PackageTools() PackageTools::copy_github_badge("active") # Add badge to readme via clipboard diff --git a/Development/config.R b/Development/config.R index ee34ab1..8b1745c 100644 --- a/Development/config.R +++ b/Development/config.R @@ -3,7 +3,7 @@ DESCRIPTION <- list( package.name = "CodeAndRoll2", - version = "2.8.15", + version = "2.8.20", 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/NAMESPACE b/NAMESPACE index 4737d4c..51b559a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -106,6 +106,7 @@ export(pAny) export(pFilter) export(pLength) export(pSee) +export(pU) export(pc_TRUE) export(pc_in_total_of_match) export(pc_overlap) diff --git a/R/CodeAndRoll2.R b/R/CodeAndRoll2.R index 23e6bea..24738ae 100644 --- a/R/CodeAndRoll2.R +++ b/R/CodeAndRoll2.R @@ -350,6 +350,7 @@ pLength <- function(x) { #' @param x The object whose unique elements to print and return. Default: None. #' @param head_n Max number of unique elements to print. Default: 20 #' @return The input object `x`, unchanged. +#' @export #' @examples #' results <- c(1, 2, 2, 3, 3, 3) |> #' pU() |> @@ -834,7 +835,7 @@ table_decreasing_hybrid <- function(vec, first_elements = FALSE, useNA = "ifany" #' @export #' @examples getCategories(c("A" = 1, "B" = 1, "C" = 2, 3)) getCategories <- function(named_categ_vec) { - named_categ_vec[names(unique(named_categ_vec))] + named_categ_vec[!duplicated(named_categ_vec)] } @@ -963,12 +964,11 @@ as.named.vector.table <- function(table, verbose = TRUE, stopifnot("table must be 1D" = length(dim(table)) <= 1) stopifnot(Stringendo::HasNames(table)) - # NOTE: BUG -- the lines that would actually build 'v' are commented out below, - # so 'v' is never defined; any call to this (deprecated) function errors. - # v <- as.vector(unclass(table)); attributes(v) <- NULL; # Atomic vector with names - # names(v) <- dimnames(table)[[1]] # Even after unclass(), the dim attribute remains, and is.vector() only returns TRUE if # an object has no attributes other than names. + v <- as.vector(unclass(table), ...) + attributes(v) <- NULL + names(v) <- dimnames(table)[[1]] stopifnot(length(v) == length(table)) return(v) @@ -1049,7 +1049,8 @@ df.col.2.named.vector <- function(df, col, names = NULL) { df.row.2.named.vector <- function(df, row, names = NULL) { stopifnot(length(row) == 1) - vec <- as.vector(df[row, , drop = TRUE]) + row_list <- lapply(df[row, , drop = TRUE], function(x) if (is.factor(x)) as.character(x) else x) + vec <- unlist(row_list, use.names = FALSE) names(vec) <- if (is.null(names)) colnames(df) else as.vector(unlist(df[names])) return(vec) } @@ -1093,15 +1094,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, .name_repair = "minimal")) + } + + tibble::tibble( name = names(vec.w.names), value = unname(vec.w.names) ) - - if (transpose) t(as.matrix(tbl)) else tbl } @@ -1274,8 +1275,14 @@ translate <- function(vec, old, new) { #' @param upto max, Default: 100 #' @export rescale <- function(vec, from = 0, upto = 100) { - vec <- vec - min(vec, na.rm = TRUE) - vec <- vec * ((upto - from) / max(vec, na.rm = TRUE)) + vmin <- min(vec, na.rm = TRUE) + vmax <- max(vec, na.rm = TRUE) + if (vmax == vmin) { + vec[!is.na(vec)] <- from / 2 + upto / 2 + return(vec) + } + vec <- vec - vmin + vec <- vec * ((upto - from) / (vmax - vmin)) vec <- vec + from return(vec) } # fun @@ -2548,7 +2555,7 @@ select_rows_and_columns <- function(df, RowIDs = NULL, ColIDs = NULL) { } else { Stringendo::iprint("All row IDs found") } # if - df <- df[true_rownames, ] + df <- df[true_rownames, , drop = FALSE] } # if if (length(ColIDs)) { true_colnames <- intersect(colnames(df), ColIDs) @@ -2558,7 +2565,7 @@ select_rows_and_columns <- function(df, RowIDs = NULL, ColIDs = NULL) { } else { Stringendo::iprint("All column IDs found") } - df <- df[, true_colnames] + df <- df[, true_colnames, drop = FALSE] } # if Stringendo::iprint(dim(df)) return(df) @@ -3927,7 +3934,7 @@ movingAve <- function(x, oneSide = 5, partial = TRUE) { # _________________________________________________________________________________________________ -#' @title Moving / rolling average (v2, filter) [Deprecated] +#' @title Moving / rolling average (v2, filter) (Deprecated) #' @description Calculates the moving / rolling average of a numeric vector, using `filter()`. #' Deprecated in favor of [movingAve()], which offers the same shrinking- vs. fixed-window #' choice (via `partial`) in a single implementation. Note `n` here is the *total* window @@ -3981,7 +3988,7 @@ movingSEM <- function(x, oneSide = 5, partial = TRUE) { # _________________________________________________________________________________________________ -#' @title imovingSEM [Deprecated] +#' @title imovingSEM (Deprecated) #' #' @description Calculates the moving / rolling standard error of the mean (SEM), shrinking the #' window near the edges. Deprecated: identical to `movingSEM(x, oneSide, partial = TRUE)`, use diff --git a/man/imovingSEM.Rd b/man/imovingSEM.Rd index 1fc03cc..2523065 100644 --- a/man/imovingSEM.Rd +++ b/man/imovingSEM.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/CodeAndRoll2.R \name{imovingSEM} \alias{imovingSEM} -\title{imovingSEM [Deprecated]} +\title{imovingSEM (Deprecated)} \usage{ imovingSEM(x, oneSide = 5) } diff --git a/man/movingAve2.Rd b/man/movingAve2.Rd index 36b549f..76200c9 100644 --- a/man/movingAve2.Rd +++ b/man/movingAve2.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/CodeAndRoll2.R \name{movingAve2} \alias{movingAve2} -\title{Moving / rolling average (v2, filter) [Deprecated]} +\title{Moving / rolling average (v2, filter) (Deprecated)} \usage{ movingAve2(x, n = 5) }