Skip to content

Commit

Permalink
Change prefix matching to simpler exact method
Browse files Browse the repository at this point in the history
Should match start of column names without running into #19
  • Loading branch information
lazappi committed Jan 28, 2020
1 parent 722de56 commit cd04a2a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 1 addition & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# clustree (development version)

* Add tests for matching prefix values
* Change prefix matching to use regex (with anchor) instead of fixed value
* Add tests for prefixes with wildcards
* Change prefix matching to simpler exact method without regular expressions

## clustree 0.4.1.9001 (2020-01-27)

Expand Down
4 changes: 3 additions & 1 deletion R/clustree.R
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,9 @@ clustree.data.frame <- function(x, prefix, ...) {
checkmate::assert_data_frame(x, col.names = "unique")
checkmate::assert_character(prefix, any.missing = FALSE, len = 1)

clust_cols <- grepl(paste0("^", prefix), colnames(x))
cols_prefix <- substr(colnames(x), 1, nchar(prefix))
clust_cols <- cols_prefix == prefix

if (sum(clust_cols) < 2) {
stop("Less than two column names matched the prefix: ", prefix,
call. = FALSE)
Expand Down
4 changes: 3 additions & 1 deletion R/clustree_overlay.R
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,9 @@ clustree_overlay.data.frame <- function(x, prefix, ...) {
checkmate::assert_data_frame(x, col.names = "unique")
checkmate::assert_character(prefix, any.missing = FALSE, len = 1)

clust_cols <- grepl(paste0("^", prefix), colnames(x))
cols_prefix <- substr(colnames(x), 1, nchar(prefix))
clust_cols <- cols_prefix == prefix

if (sum(clust_cols) < 2) {
stop("Less than two column names matched the prefix: ", prefix,
call. = FALSE)
Expand Down

0 comments on commit cd04a2a

Please sign in to comment.