-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#' Highlight a matrix | ||
#' | ||
#' Generate a matrix with active areas. | ||
#' | ||
#' @param x A matrix. | ||
#' @param rows An interger vector with valid row index locations. | ||
#' @param columns An integer vector containing valid column indexlocations. | ||
#' @param points An m by 2 matrix with points listed in x, y format. | ||
#' | ||
#' @return | ||
#' A logical matrix with the required rows and/or columns or points set to | ||
#' `TRUE`. All other values are given as `FALSE`. | ||
#' | ||
#' @export | ||
#' @examples | ||
#' | ||
#' x = matrix(1:12, nrow = 4) | ||
#' | ||
#' # Highlight entries only in the 1st and 3rd rows. | ||
#' highlight_matrix(x, rows = c(1, 3)) | ||
#' | ||
#' # Highlight entries only in the first two rows: | ||
#' highlight_matrix(x, rows = 1:2) | ||
#' | ||
#' # Highlight entries in the last row | ||
#' highlight_matrix(x, rows = nrow(x)) | ||
#' | ||
#' # Highlight entries in the first column | ||
#' highlight_matrix(x, columns = 1) | ||
#' | ||
#' # Highlight entries in the first column or first row. | ||
#' highlight_matrix(x, rows = 1, columns = 1) | ||
highlight_matrix <- function(x, rows = NULL, columns = NULL, points = NULL) { | ||
|
||
# Create a logical matrix with the same dimensions as 'x' | ||
logical_matrix <- matrix(FALSE, nrow = nrow(x), ncol = ncol(x)) | ||
|
||
# Nothing to mark. | ||
if (is.null(rows) && is.null(columns) && is.null(points)) { | ||
return(logical_matrix) | ||
} | ||
|
||
if(!is.null(points)){ | ||
stopifnot("points must contain only two columns." = ncol(points) == 2) | ||
logical_matrix[points] <- TRUE | ||
} | ||
|
||
# Enable rows | ||
if(!is.null(rows)){ | ||
logical_matrix[rows, ] <- TRUE | ||
} | ||
|
||
# Enable columns | ||
if(!is.null(columns)){ | ||
logical_matrix[, columns] <- TRUE | ||
} | ||
|
||
logical_matrix | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.