diff --git a/R/add_overlap_info.R b/R/add_overlap_info.R index 07b1b6a..231fc90 100644 --- a/R/add_overlap_info.R +++ b/R/add_overlap_info.R @@ -77,11 +77,12 @@ add_overlap_info <- function(spe, metric_name) { ungroup() # Since we only want overlapping spot keys, remove the "identity spot" - col_data$overlap_key <- sapply( + col_data$overlap_key <- vapply( seq_len(nrow(col_data)), function(i) { sub(col_data$key[i], "", col_data$overlap_key[i], fixed = TRUE) - } + }, + character(1) ) # Remove double commas (only possible in the middle) or leading/trailing @@ -102,7 +103,7 @@ add_overlap_info <- function(spe, metric_name) { ungroup() |> arrange(desc(exclude_overlapping_mean_tmp)) - col_data$exclude_overlapping <- sapply( + col_data$exclude_overlapping <- vapply( seq_len(nrow(col_data)), function(i) { # Don't exclude spots that don't overlap anything @@ -124,7 +125,8 @@ add_overlap_info <- function(spe, metric_name) { match(col_data$capture_area[i], metrics_by_id$capture_area) return(exclude) - } + }, + logical(1) ) # Add colData back to the SpatialExperiment diff --git a/R/prep_fiji_coords.R b/R/prep_fiji_coords.R index c6ae965..b7be386 100644 --- a/R/prep_fiji_coords.R +++ b/R/prep_fiji_coords.R @@ -110,8 +110,8 @@ prep_fiji_coords <- function(sample_info, out_dir) { # Find paths to input images and the order the corresponding capture # areas appear in these paths input_paths <- xml_attr(transform_nodes, "file_path") - input_indices <- sapply( - this_sample_info$capture_area, function(x) grep(x, input_paths) + input_indices <- vapply( + this_sample_info$capture_area, function(x) grep(x, input_paths), integer(1) ) if (length(input_paths) != nrow(this_sample_info) || any(is.na(input_indices))) { stop("Expected each capture area to be present exactly once in the input filenames to Fiji for each group.")