Skip to content

Commit

Permalink
Add guard against appending columns to subsetted cytoframe
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobpwagner committed Sep 17, 2020
1 parent b0980e1 commit b48c882
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions R/cytoframe.R
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,8 @@ cf_cleanup <- function(cf, cred = NULL){
#' @export
cf_append_cols <- function(cf, cols, cred = NULL){

if(cf_is_subsetted(cf))
stop("Columns cannot be added to subsetted cytoframes. This cytoframe must first be realized with `realize_view()`.\n")
cf <- new("cytoframe", pointer = append_cols(cf@pointer, colnames(cols), cols), use.exprs = TRUE);

}
4 changes: 4 additions & 0 deletions tests/testthat/cytoframe-suite.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ test_that("cf_append_cols", {
m <- matrix(1:(2*nrow(cf)), ncol = 2)
colnames(m) <- c("B", "C")

# Test error if trying to append to subsetted cytoframe
cf_subsetted <- cf[1:1000, 1:5]
expect_error(cf_append_cols(cf_subsetted, n), "cannot be added to subsetted")

# Add single column and make sure min/max keywords set appropriately
cf_expanded <- realize_view(cf)
cf_append_cols(cf_expanded, n)
Expand Down

0 comments on commit b48c882

Please sign in to comment.