# thisutils

# thisutils 0.4.5

* **feat**:
  * Add `collapse_sparse_rows()`: collapse sparse matrix rows by group while preserving sparse output and row order.
  * Update `compute_lisi()`: simplify nearest-neighbor backend selection by removing the `hnsw` path and using a more conservative `"auto"` strategy that prefers the package's exact backend only for very small problems.
  * Improve `parallelize_fun()`: refactor verbose multi-core execution to collect results dynamically while preserving input order and progress reporting across uneven workloads.
  * Improve `log_message()`: allow explicit `verbose` to override the global option and normalize captured `cli` alerts emitted inside `expr`.

* **fix**:
  * Harden `normalization()` against degenerate inputs so zero-variance or zero-sum vectors return stable values instead of `NaN`/`Inf`.
  * Fix `matrix_to_table()` sparse `keep_zero = TRUE` handling to match dense output more reliably and make equal-magnitude sorting deterministic.
  * Fix `table_to_matrix()` to aggregate duplicate row/column coordinates consistently in both dense and sparse output paths.
  * Update package startup behavior to stay silent in non-interactive sessions and when verbose logging is disabled.
  * Update package installation helpers to use `pak::pkg_install()`/`pak::pkg_remove()` with explicit library handling.

* **docs**:
  * Add a runnable example for `collapse_sparse_rows()`.
  * Refresh `compute_lisi()` and `log_message()` documentation to match the current arguments and defaults.

* **tests**:
  * Add regression tests for `collapse_sparse_rows()` edge cases, `compute_lisi()` backend consistency, captured `cli` messages in `log_message(expr = ...)`, matrix conversion corner cases, `parallelize_fun()` ordering/export behavior, normalization on degenerate inputs, and startup suppression when verbose logging is disabled.

# thisutils 0.4.4

* **feat**:
  * Add `compute_lisi()`: compute per-cell Local Inverse Simpson's Index (LISI) scores for categorical variables. Supports multiple nearest-neighbor backends (`"auto"`, `"rann"`, `"fnn"`, `"hnsw"`, `"exact"`) with configurable perplexity and tolerance. Includes `compute_simpson_index()` for low-level Simpson index computation from KNN graphs, backed by a C++ implementation.
  * Enhance `log_message()`: add optional `expr` support to capture standard output, messages, and warnings from another expression and re-print them with `log_message()` formatting while returning the evaluated result.
  * `parallelize_fun()`:
    * Suppress C/C++ level stderr output (e.g., `"Error : Not a matrix."`) and warnings during function execution in `parallelize_fun()` via stderr redirection and `suppressWarnings()`.
    * Group error reporting by message: identical errors are now collapsed into a single line with count and up to 3 example task names, instead of printing every failure individually.
    * Add `progress_bar_width` to `parallelize_fun()` for direct progress bar width control; default width is now `10`.

* **fix**:
  * `parallelize_fun()`
    * Fix result length mismatch when `cores = 1`: use `output_list[i] <- list(result)` instead of `output_list[[i]] <- result` to prevent `NULL` returns from shrinking the output list.
    * Fix multi-core result ordering in verbose mode: results are now written back by original index so output order and assigned names stay aligned with input.
    * Fix core detection fallback: when `parallel::detectCores(logical = FALSE)` is unavailable or returns an invalid value, execution now falls back safely to at least one worker instead of failing.

# thisutils 0.4.2

* **feat**:
  * Add `check_ci_env()`: detect whether the current session should be treated as CI/pkgdown context; returns `TRUE` for interactive sessions and for GitHub Actions when `GITHUB_ACTIONS=true` and `GITHUB_WORKFLOW=pkgdown` (case-insensitive), otherwise returns `FALSE`.
  * Add `is_outlier()`: detect outlier indices using median and MAD-based bounds (`nmads`, `constant`) with `type = "both"|"lower"|"higher`; `NA` values are also included in the returned index vector.
  * Export `check_pkg_status()`: make the package/version checker available as a public API; it checks installation status in a target library (`lib`) and optionally verifies exact version match when `version` is provided.

# thisutils 0.4.1

* **feat**:
  * Remove `@examples` for `check_r()` function.

# thisutils 0.4.0

* **feat**:
  * Add `check_r()`: check and install R packages from CRAN, Bioconductor, or GitHub; supports version pinning (`pkg@version` or `pkg==version`) and optional `force` reinstall; uses `pak::pak()` for installation with configurable `lib` and `dependencies`.
  * Add `remove_r()`: check and remove installed R packages from the given library; uses `pak::pkg_remove()`; skips packages that are not installed and reports success or failure per package.

# thisutils 0.3.9

* **feat**:
  * Fix `add_pkg_file()` dependency management: `cli` dependency is now added with correct comma separation, and both Imports and Suggests sections are automatically sorted alphabetically. The Suggests section is now enforced to follow Imports.

# thisutils 0.3.8

* **feat**:
  * Improve `add_pkg_file()` flow: better metadata extraction/logging from DESCRIPTION, and smarter logo generation fallback when figlet fails. Generated package files now include `@useDynLib` only when `src/` exists.
  * Refresh startup messages: `.onAttach()` now shows package version, release date, and website link in both generated package files.

# thisutils 0.3.7

* **feat**:
  * Optimize `matrix_to_table()` C++ implementation: Improved dimnames handling using `Rf_getAttrib` and `R_DimNamesSymbol` for better compatibility. Enhanced `keep_zero = TRUE` logic to efficiently include all row/column combinations (including zeros) using `unordered_set` and `unordered_map` for optimized lookups.
  * Improve `table_to_matrix()` C++ implementation: Enhanced sparse matrix construction by ensuring zero values are not added to sparse matrices. Improved dimnames setting using `Rf_setAttrib` and `R_DimNamesSymbol` for better compatibility.

# thisutils 0.3.6

* **feat**:
  * Fix warning about ‘ATTRIB’ from check results of *CRAN*.

# thisutils 0.3.5

* **feat**:
  * Simplify `parallelize_fun()` function: Unified progress bar creation logic by removing conditional branches and using a single consistent format. Updated progress bar format string for better readability and consistency.
  * Add `get_namespace_fun()` function.

# thisutils 0.3.4

* **feat**:
  * Enhance `log_message()` function: Added new `"ask"` message type for interactive user prompts. When `message_type = "ask"`, the function uses `utils::askYesNo()` to prompt the user and returns `TRUE` for Yes, `FALSE` for No, and `NA` for Cancel.
  * Optimize `parallelize_fun()` function: Improved progress bar status display in parallel processing mode. Now shows only the first item name/value with ellipsis ("…") instead of concatenating all chunk items, resulting in cleaner and more concise progress display.

# thisutils 0.3.3

* **feat**:
  * Refactor internal helper functions in `log_message()` and `add_pkg_file()`: Converted private helper functions (prefixed with `.`) to public functions, improving code accessibility and maintainability. Functions affected include `build_message()`, `validate_params()`, `output_message()`, `style_formatting()`, `plain_text_output()`, `get_caller_call()`, `extract_function_name()`, `make_color_style()`, `check_color()`, and `generate_content()`.

* **docs**:
  * Add `@return` documentation for `thisutils_logo()` and logo functions generated by `add_pkg_file()`.

# thisutils 0.3.2

* **feat**:
  * Change default value of `timestamp_style` parameter in `log_message()` function from `TRUE` to `FALSE` for cleaner default output.

# thisutils 0.3.1

* **docs**:
  * Update `figlet()` references to use HTTPS, addressing CRAN incoming NOTE.

# thisutils 0.3.0

* **feat**:
  * Enhance `log_message()` function: Added new `plain_text` parameter to suppress level, symbol, timestamp, and message type formatting while preserving color and multiline settings, allowing for cleaner text-only output.
  * Improve `add_pkg_file()` function: Enhanced message types and formatting, using more appropriate message types (`warning`, `running`) and improved file references in log messages.

# thisutils 0.2.5

* **feat**:
  * Optimize `check_sparsity()` function: Improved calculation logic by computing total counts upfront, avoiding redundant calculations for sparse and non-sparse matrices.
  * Optimize `normalization()` function: Enhanced `max_min` and `maximum` methods by caching min/max values to avoid repeated calculations.
  * Improve code quality in `parallelize_fun()`: Replaced `sapply()` with `vapply()` for type-safe return values and optimized error handling logic.
  * Optimize P-value combination functions (`meanp()`, `sump()`, `votep()`): Extracted `validp` variable to avoid repeated indexing and improved code efficiency.
  * Enhance `sump()` function: Replaced loop-based calculation with vectorized operations for better performance.
  * Improve `capitalize()` and `unnest_fun()` functions: Replaced `sapply()` with `vapply()` for type safety.
  * Enhance `add_pkg_file()` function: Now automatically checks for the existence of `src` directory and only adds `@useDynLib` directive when `src` folder is present in the package environment.

# thisutils 0.2.4

* **feat**:
  * Enhance `log_message()` function: Now automatically handles non-character objects (e.g., `data.table`, `data.frame`) by formatting them with `capture.output(print(...))`, allowing direct object input without manual string conversion.

# thisutils 0.2.3

* **feat**:
  * Rewrite `matrix_to_table()` C++ implementation to iterate `dgCMatrix` slots directly, avoiding dense conversion and reducing memory/time cost on large sparse matrices.
  * Align `keep_zero`/`threshold` semantics across C++/R: retain entries if `abs(value) >= threshold`; zeros are retained only when `keep_zero = TRUE` and `threshold == 0`.

# thisutils 0.2.2

* **feat**:
  * Enhance `parallelize_fun()` function: Added support for named vectors and vectors in progress display, showing current processing item names or values in the progress bar. Improved progress bar formatting with status information and enhanced parallel processing progress updates.
  * Improve visual formatting in `add_pkg_file()` and `thisutils-package.R`: Enhanced separator line display with grey color styling using `cli::col_grey()` for better visual consistency.

# thisutils 0.2.1

* **feat**:
  * Enhance `add_pkg_file()` function: Added automatic dependency checking to ensure `cli` package is included in DESCRIPTION file, and automatic pkgdown configuration checking to ensure proper package overview section setup.

# thisutils 0.2.0

* **feat**:
  * Add package logo.
  * Add `get_verbose()` function: New exported function to get verbose option from global options or local arguments, providing better control over message display.
  * Enhance `.onAttach()` function: Now respects verbose settings and only displays startup messages when verbose mode is enabled, improving user experience.
  * Update `add_pkg_file()` function: Generated `.onAttach()` function now includes verbose check using `get_verbose()`, ensuring consistency with package behavior.

* **docs**:
  * Corrected brace escaping in `parse_inline_expressions()`.

# thisutils 0.1.9

* **feat**:
  * Remove `list_figlet_fonts()` and `rescale()` functions.

# thisutils 0.1.7

* **feat**:
  * Refactor `add_pkg_file()` function: Simplified function parameters by removing manual parameter inputs and automatically extracting all package information from DESCRIPTION file. Enhanced error handling and improved logging messages.
  * Enhance `parallelize_fun()` function with robust error handling: Added `clean_result` parameter to control automatic removal of failed results, and `throw_error` parameter to control detailed error message display. Functions now gracefully handle partial failures without stopping execution.
  * Add `parse_inline_expressions()` function: High-performance inline expression parser that evaluates `{}` expressions while preserving CLI formatting markers like `{.val ...}`.
  * Enhance `log_message()` function: Add new `"running"` message type with orange circle dotted symbol (`◌`) to indicate ongoing processes.

# thisutils 0.1.6

* **feat**:
  * Add statistical *P-value* combination functions: `wilkinsonp()`, `maximump()`, `minimump()`, `meanp()`, `votep()`, and `sump()` for meta-analysis and multiple study result integration.
  * Add `max_depth()` function to calculate the maximum depth of nested lists.

# thisutils 0.1.5

* **feat**:
  * Update `add_pkg_file()` function. Now, `add_pkg_file()` can automatically extract information of *R* package from `DESCRIPTION` file and save it in the `./R/` folder.

# thisutils 0.1.4

* **feat**:
  * Delete `str_wrap()` function.

# thisutils 0.1.3

* **feat**:
  * Replace `purrr::map2()` with `mapply()`, and delete `purrr` package in `DESCRIPTION`.
  * Replace `methods::is()` with `inherits()`, and delete `methods` package in `DESCRIPTION`.

* **docs**:
  * Update documentation for some functions.

# thisutils 0.1.1

* **feat**:
  * Add `matrix_process()` function.

# thisutils 0.0.9

* **feat**:
  * Add `matrix_to_table()` and `table_to_matrix()` functions for data conversion between matrix and table formats.
  * Modify parameter `sparse` to `return_sparse` for `as_matrix()`

* **docs**:
  * Update documentation for some functions.

# thisutils 0.0.8

* **docs**:
  * Update documentation for some functions.
