From 09b1365c160d14069611a0b3dcec5b5f45c8d02c Mon Sep 17 00:00:00 2001 From: lcolladotor Date: Fri, 26 Jul 2024 14:30:06 -0400 Subject: [PATCH] Resolve sapply() -> vapply() BiocCheck NOTE Co-authored-by: Nick Eagles --- R/add_overlap_info.R | 10 ++++++---- R/prep_fiji_coords.R | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) 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.")