From cb77c341a17e12d63d3d5f6add9f39e2d74426ca Mon Sep 17 00:00:00 2001 From: Gregory Jefferis Date: Mon, 2 Mar 2026 07:11:02 +0000 Subject: [PATCH 1/7] Add cf_add_meta() function to enrich dataframes with metadata New exported function for enriching dataframes containing neuron keys with metadata. Supports: - Single or multiple key columns - Configurable suffixes for multiple columns - Optional column selection via cols parameter - Warning for missing column names Also updates to exclude tissue/sex columns from metadata join since these are typically already present. --- NAMESPACE | 1 + R/meta.R | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) diff --git a/NAMESPACE b/NAMESPACE index ccb03a3..5d89297 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,6 +4,7 @@ S3method(c,cidlist) S3method(print,cidlist) export("%>%") export(abbreviate_datasets) +export(cf_add_meta) export(cf_cosine_plot) export(cf_datasets) export(cf_ids) diff --git a/R/meta.R b/R/meta.R index f274593..3602cda 100644 --- a/R/meta.R +++ b/R/meta.R @@ -334,6 +334,117 @@ cf_meta <- function(ids, bind.rows=TRUE, integer64=FALSE, keep.all=FALSE, res } + +#' Add metadata to a dataframe containing neuron keys +#' +#' @description Enriches a dataframe with metadata for neurons identified by +#' key columns. This is useful for adding metadata to partner data or other +#' results that contain neuron keys. +#' +#' @param x A data.frame containing one or more columns with keys +#' @param keycol Character vector of column names containing keys. +#' Default \code{"key"}. When multiple columns specified, metadata is joined +#' for each with corresponding suffixes. +#' @param suffix Character vector of suffixes for added columns. Must match +#' length of keycol. Default generates \code{""} for single keycol, or +#' \code{".1"}, \code{".2"}, etc. for multiple. Use \code{""} for no suffix. +#' @param cols Character vector of column names to add from metadata. +#' Default \code{NULL} adds all columns. Warns if any specified columns +#' are not found in metadata. The \code{key} column is always kept for joining. +#' @param ... Additional arguments passed to \code{\link{cf_meta}} +#' +#' @return data.frame with additional metadata columns +#' @export +#' +#' @examples +#' \dontrun{ +#' # Add metadata to partner column only +#' partners <- cf_partners(cf_ids(hemibrain='DA2_lPN'), threshold=10, details=FALSE) +#' partners_meta <- cf_add_meta(partners, keycol="post_key") +#' +#' # Add metadata to both pre and post +#' partners_both <- cf_add_meta(partners, +#' keycol = c("pre_key", "post_key"), +#' suffix = c(".pre", ".post")) +#' +#' # Add only type and side columns +#' partners_minimal <- cf_add_meta(partners, keycol="post_key", +#' cols = c("type", "side")) +#' } +cf_add_meta <- function(x, keycol = "key", suffix = NULL, cols = NULL, ...) { + # Validate inputs + if (!is.data.frame(x) || nrow(x) == 0) { + return(x) + } + + missing_cols <- setdiff(keycol, names(x)) + if (length(missing_cols)) + stop("Column(s) not found in x: ", paste(missing_cols, collapse = ", ")) + + # Set default suffixes + if (is.null(suffix)) { + suffix <- if (length(keycol) == 1) "" else paste0(".", seq_along(keycol)) + } + if (length(suffix) != length(keycol)) + stop("Length of suffix must match length of keycol") + + # Extract unique keys and fetch metadata once + all_keys <- unique(unlist(x[keycol], use.names = FALSE)) + all_keys <- all_keys[!is.na(all_keys) & nzchar(all_keys)] + + if (length(all_keys) == 0) { + warning("No valid keys found in specified columns") + return(x) + } + + meta <- cf_meta(all_keys, ...) + + if (is.null(meta) || nrow(meta) == 0) { + warning("No metadata found for provided keys") + return(x) + } + + + # Remove columns that would conflict or are typically already present + meta_cols_to_drop <- c("id", "dataset", "tissue", "sex") + meta <- meta[, setdiff(names(meta), meta_cols_to_drop), drop = FALSE] + + # Subset columns if requested (character vector) + if (!is.null(cols)) { + if (!is.character(cols)) { + stop("cols must be a character vector of column names") + } + missing <- setdiff(cols, names(meta)) + if (length(missing) > 0) { + warning("Column(s) not found in metadata: ", + paste(missing, collapse = ", ")) + } + keep_cols <- c("key", intersect(cols, names(meta))) + meta <- meta[, keep_cols, drop = FALSE] + } + + # Join for each keycol + for (i in seq_along(keycol)) { + kc <- keycol[i] + sf <- suffix[i] + + # Prepare metadata with suffixed column names (except key) + meta_i <- meta + if (sf != "") { + names(meta_i) <- ifelse(names(meta_i) == "key", + "key", + paste0(names(meta_i), sf)) + } + + # Join by key column + join_by <- stats::setNames("key", kc) + x <- dplyr::left_join(x, meta_i, by = join_by) + } + + x +} + + # Shared helper for fanc and banc metadata fancorbanc_meta <- function(table, ids=NULL, ...) { ol_classes=c("centrifugal", "distal medulla", "distal medulla dorsal rim area", From 441649be2087ec143a93d4177dd706d508a7e7ab Mon Sep 17 00:00:00 2001 From: Gregory Jefferis Date: Mon, 2 Mar 2026 07:11:09 +0000 Subject: [PATCH 2/7] Add extended details parameter to cf_partners() Changes details from boolean to character options: - "partner" (default): Add metadata for partner neurons only - "query": Add metadata for query neurons only - "both": Add metadata for both sides with .pre/.post suffixes - "neither": No metadata, return minimal columns for speed The implementation: - Keeps only core connectivity columns (pre_id, post_id, weight) - Uses cf_add_meta() to add metadata consistently from cf_meta() - Removes the add_partner_metadata() helper function Includes comprehensive tests for all details options and cf_add_meta functionality. --- R/meta.R | 16 ++--- R/partners.R | 111 +++++++++++------------------- man/cf_partners.Rd | 10 +++ tests/testthat/test-partners.R | 122 +++++++++++++++++++++++++++++++++ 4 files changed, 177 insertions(+), 82 deletions(-) diff --git a/R/meta.R b/R/meta.R index 3602cda..f1b3496 100644 --- a/R/meta.R +++ b/R/meta.R @@ -428,17 +428,11 @@ cf_add_meta <- function(x, keycol = "key", suffix = NULL, cols = NULL, ...) { kc <- keycol[i] sf <- suffix[i] - # Prepare metadata with suffixed column names (except key) - meta_i <- meta - if (sf != "") { - names(meta_i) <- ifelse(names(meta_i) == "key", - "key", - paste0(names(meta_i), sf)) - } - - # Join by key column - join_by <- stats::setNames("key", kc) - x <- dplyr::left_join(x, meta_i, by = join_by) + # Rename key column to match keycol, add suffix to other columns, then join + x <- meta %>% + dplyr::rename(!!kc := key) %>% + dplyr::rename_with(~paste0(.x, sf), .cols = -dplyr::all_of(kc)) %>% + dplyr::left_join(x, ., by = kc) } x diff --git a/R/partners.R b/R/partners.R index 3aefd1d..99b3c8b 100644 --- a/R/partners.R +++ b/R/partners.R @@ -15,6 +15,14 @@ #' @param partners Whether to return inputs or outputs #' @param MoreArgs Additional arguments in the form of a hierarchical list #' (expert use; see details and examples). +#' @param details Which neurons to enrich with metadata. Options: +#' \itemize{ +#' \item \code{"partner"} (default): Add metadata for partner neurons only +#' \item \code{"query"}: Add metadata for query neurons only +#' \item \code{"both"}: Add metadata for both with \code{.pre}/\code{.post} suffixes +#' \item \code{"neither"}: No metadata, return minimal columns for speed +#' } +#' Metadata can also be added later via \code{\link{cf_add_meta}}. #' #' @inheritParams cf_meta #' @return A data.frame or a named list (when \code{bind.rows=FALSE}) @@ -38,9 +46,11 @@ #' } cf_partners <- function(ids, threshold=1L, partners=c("inputs", "outputs"), bind.rows=TRUE, MoreArgs=list(), keep.all=FALSE, + details=c("partner", "query", "both", "neither"), use_superclass=getOption("coconatfly.use_superclass", FALSE), harmonise_class=getOption("coconatfly.harmonise_class", FALSE)) { partners=match.arg(partners) + details=match.arg(details) threshold <- checkmate::assert_integerish( threshold, lower=0L,len = 1, null.ok = F, all.missing = F) @@ -51,7 +61,7 @@ cf_partners <- function(ids, threshold=1L, partners=c("inputs", "outputs"), if(is.data.frame(ids)) { ss=split(ids$id, ids$dataset) res=cf_partners(ss, threshold = threshold, partners = partners, - bind.rows = bind.rows, MoreArgs=MoreArgs, + bind.rows = bind.rows, MoreArgs=MoreArgs, details=details, use_superclass=use_superclass, harmonise_class=harmonise_class) return(res) } @@ -90,14 +100,7 @@ cf_partners <- function(ids, threshold=1L, partners=c("inputs", "outputs"), do.call(PFUN, commonArgs) } - # Enrich with partner metadata if partnerfun returned minimal data - tres <- add_partner_metadata(tres, dataset = n, partners = partners) - tres=coconat:::standardise_partner_summary(tres) - if(isTRUE(harmonise_class) && "class" %in% colnames(tres)) - tres$class=harmonise_top_class_values(tres$class, n) - if("side" %in% colnames(tres)) - tres$side=normalise_side(tres$side) if(nrow(tres)>0) { tres$dataset=n tres$tissue=dataset_tissue(n) @@ -108,8 +111,37 @@ cf_partners <- function(ids, threshold=1L, partners=c("inputs", "outputs"), tres$sex=character() warning("no ", partners, " found for `", n, "` dataset.") } + # Add keys before metadata enrichment tres$pre_key=keys(tres, idcol="pre_id") tres$post_key=keys(tres, idcol='post_id') + + # Enrich with metadata based on details option + # Always use cf_add_meta rather than relying on partnerfun metadata + if (details != "neither" && nrow(tres) > 0) { + # Keep only core connectivity columns, drop all partnerfun metadata + # cf_add_meta will re-add metadata from cf_meta for consistency + core_cols <- c("pre_id", "post_id", "weight", "dataset", "tissue", "sex", + "pre_key", "post_key") + tres <- tres[, intersect(names(tres), core_cols), drop = FALSE] + + # Determine which key columns to enrich + query_col <- if (partners == "outputs") "pre_key" else "post_key" + partner_col <- if (partners == "outputs") "post_key" else "pre_key" + + keycols <- switch(details, + partner = partner_col, + query = query_col, + both = c("pre_key", "post_key") + ) + suffixes <- switch(details, + partner = "", + query = "", + both = c(".pre", ".post") + ) + + tres <- cf_add_meta(tres, keycol = keycols, suffix = suffixes, + harmonise_class = harmonise_class) + } res[[n]]=tres } if(isTRUE(bind.rows)) { @@ -270,66 +302,3 @@ cf_partner_summary <- function(ids, threshold=1L, partners=c("inputs", "outputs" outputcol = ifelse(partners=='outputs', group.post[1], group.pre[1]), standardise_input = F, sparse = rval=="sparse") } - - -# Add metadata to partner results if the partnerfun returned minimal columns -# This allows partnerfuns to return just ids + weight and have metadata added -# automatically via cf_meta() -add_partner_metadata <- function(tres, dataset, partners) { - if (is.null(tres) || !is.data.frame(tres) || nrow(tres) == 0) { - return(tres) - } - - # Check if we need to fetch partner metadata: - # - 3 columns (pre_id, post_id, weight) always needs enrichment - # - <=5 columns without 'type' likely needs enrichment - needs_enrichment <- ncol(tres) == 3 || - (ncol(tres) <= 5 && !"type" %in% names(tres)) - - if (!needs_enrichment) { - return(tres) - } - - # Find the partner column based on query direction - # For outputs: partners are post_id; for inputs: partners are pre_id - partner_col <- if (partners == "outputs") "post_id" else "pre_id" - - # Check if expected column exists, otherwise try to find it - - if (!partner_col %in% colnames(tres)) { - # Fallback: look for a single *_id column or 'partner' column - id_cols <- grep("_id$", colnames(tres), value = TRUE) - if (length(id_cols) == 1) { - partner_col <- id_cols - } else { - partner_col <- grep("^partner$", colnames(tres), value = TRUE) - } - } - - if (length(partner_col) != 1 || !partner_col %in% colnames(tres)) { - warning("Unable to find partner column for dataset: ", dataset, - "\nPartnerfuns should return pre_id/post_id columns or include metadata") - return(tres) - } - - # Fetch metadata for unique partner IDs - pids <- unique(tres[[partner_col]]) - # Convert to character for keys() and ensure dataset uses abbreviation - pids_char <- coconat::id2char(pids) - metadf <- cf_meta(keys(data.frame(id = pids_char, dataset = dataset))) - - if (is.null(metadf) || nrow(metadf) == 0) { - return(tres) - } - - # Remove columns that will be added by cf_partners later - metadf <- metadf[setdiff(colnames(metadf), c("dataset", "key"))] - - # Rename id column to match partner column for joining - colnames(metadf)[1] <- partner_col - - # Ensure partner column is character for joining - tres[[partner_col]] <- coconat::id2char(tres[[partner_col]]) - - dplyr::left_join(tres, metadf, by = partner_col) -} diff --git a/man/cf_partners.Rd b/man/cf_partners.Rd index 323844b..eca0150 100644 --- a/man/cf_partners.Rd +++ b/man/cf_partners.Rd @@ -11,6 +11,7 @@ cf_partners( bind.rows = TRUE, MoreArgs = list(), keep.all = FALSE, + details = c("partner", "query", "both", "neither"), use_superclass = getOption("coconatfly.use_superclass", FALSE), harmonise_class = getOption("coconatfly.harmonise_class", FALSE) ) @@ -36,6 +37,15 @@ note that some columns will be dropped by unless \code{keep.all=TRUE}).} rather than just those in common (default=\code{FALSE} only keeps shared columns).} +\item{details}{Which neurons to enrich with metadata. Options: +\itemize{ + \item \code{"partner"} (default): Add metadata for partner neurons only + \item \code{"query"}: Add metadata for query neurons only + \item \code{"both"}: Add metadata for both with \code{.pre}/\code{.post} suffixes + \item \code{"neither"}: No metadata, return minimal columns for speed +} +Metadata can also be added later via \code{\link{cf_add_meta}}.} + \item{use_superclass}{If \code{TRUE}, rename class/subclass/subsubclass columns to superclass/class/subclass. Can also be set via the \code{coconatfly.use_superclass} option.} diff --git a/tests/testthat/test-partners.R b/tests/testthat/test-partners.R index 7f3c286..654b0b1 100644 --- a/tests/testthat/test-partners.R +++ b/tests/testthat/test-partners.R @@ -57,3 +57,125 @@ test_that("partner metadata enrichment works", { # Verify the types are correct (partners of neuron 10001 are neurons 10002 and 10003) expect_true(all(c("G1.2_PN", "G2_PN") %in% pp$type)) }) + + +test_that("cf_partners details='neither' returns minimal columns", { + register_rhubarb() + + # With details="neither", should NOT have type/class columns + pp <- cf_partners(cf_ids(rhubarb = 10001), partners = "outputs", + threshold = 1, details = "neither") + + expect_s3_class(pp, "data.frame") + expect_true(nrow(pp) > 0) + + # Should have minimal columns + expect_true(all(c("pre_id", "post_id", "weight", "pre_key", "post_key", "dataset") + %in% colnames(pp))) + # Should NOT have metadata columns + expect_false("type" %in% colnames(pp)) + expect_false("class" %in% colnames(pp)) +}) + + +test_that("cf_partners details='query' adds metadata to query neurons", { + register_rhubarb() + + # For outputs: query is pre, partner is post + pp <- cf_partners(cf_ids(rhubarb = 10001), partners = "outputs", + threshold = 1, details = "query") + + expect_s3_class(pp, "data.frame") + expect_true(nrow(pp) > 0) + + # Should have type (from query neuron 10001) + expect_true("type" %in% colnames(pp)) + expect_equal(unique(pp$type), "G1_PN") # neuron 10001's type +}) + + +test_that("cf_partners details='both' adds metadata to both sides", { + register_rhubarb() + + pp <- cf_partners(cf_ids(rhubarb = 10001), partners = "outputs", + threshold = 1, details = "both") + + expect_s3_class(pp, "data.frame") + expect_true(nrow(pp) > 0) + + # Should have suffixed columns for both sides + expect_true("type.pre" %in% colnames(pp)) + expect_true("type.post" %in% colnames(pp)) + expect_true("class.pre" %in% colnames(pp)) + expect_true("class.post" %in% colnames(pp)) + + # Query neuron 10001 is pre (for outputs) + expect_equal(unique(pp$type.pre), "G1_PN") + # Partners are 10002 and 10003 + expect_true(all(c("G1.2_PN", "G2_PN") %in% pp$type.post)) +}) + + +test_that("cf_add_meta adds metadata to single key column", { + register_rhubarb() + + # Get partners without details + partners <- cf_partners(cf_ids(rhubarb = 10001), partners = "outputs", + threshold = 1, details = "neither") + + # Add metadata to post_key column + result <- cf_add_meta(partners, keycol = "post_key") + + expect_true("type" %in% names(result)) + expect_true("class" %in% names(result)) + # Check that metadata was actually joined + expect_true(all(c("G1.2_PN", "G2_PN") %in% result$type)) +}) + + +test_that("cf_add_meta handles multiple key columns with suffixes", { + register_rhubarb() + + partners <- cf_partners(cf_ids(rhubarb = 10001), partners = "outputs", + threshold = 1, details = "neither") + + result <- cf_add_meta(partners, + keycol = c("pre_key", "post_key"), + suffix = c(".pre", ".post")) + + expect_true("type.pre" %in% names(result)) + expect_true("type.post" %in% names(result)) + expect_true("class.pre" %in% names(result)) + expect_true("class.post" %in% names(result)) +}) + + +test_that("cf_add_meta cols parameter limits columns", { + register_rhubarb() + + partners <- cf_partners(cf_ids(rhubarb = 10001), partners = "outputs", + threshold = 1, details = "neither") + + result <- cf_add_meta(partners, keycol = "post_key", + cols = c("type", "side")) + + expect_true("type" %in% names(result)) + expect_true("side" %in% names(result)) + expect_false("class" %in% names(result)) + expect_false("subclass" %in% names(result)) +}) + + +test_that("cf_add_meta warns about missing columns", { + register_rhubarb() + + partners <- cf_partners(cf_ids(rhubarb = 10001), partners = "outputs", + threshold = 1, details = "neither") + + # Character vector with non-existent column should warn + expect_warning( + cf_add_meta(partners, keycol = "post_key", + cols = c("type", "nonexistent_col")), + "not found in metadata" + ) +}) From 2e450f17cb528b46e67d9010bf661da207f8622f Mon Sep 17 00:00:00 2001 From: Gregory Jefferis Date: Wed, 1 Apr 2026 07:49:11 +0100 Subject: [PATCH 3/7] Improve cf_add_meta missing key message and add test * nb this replaces a bad commit from claude --- R/meta.R | 4 +++- tests/testthat/test-partners.R | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/R/meta.R b/R/meta.R index f1b3496..9c0d69f 100644 --- a/R/meta.R +++ b/R/meta.R @@ -379,7 +379,9 @@ cf_add_meta <- function(x, keycol = "key", suffix = NULL, cols = NULL, ...) { missing_cols <- setdiff(keycol, names(x)) if (length(missing_cols)) - stop("Column(s) not found in x: ", paste(missing_cols, collapse = ", ")) + stop("keycol column(s) not found in x: ", paste(missing_cols, collapse = ", "), + "\nHint: use keys(x) to add a '", paste(missing_cols, collapse = "/"), + "' column, or set keycol= to identify the correct key column.") # Set default suffixes if (is.null(suffix)) { diff --git a/tests/testthat/test-partners.R b/tests/testthat/test-partners.R index 654b0b1..f3a9f46 100644 --- a/tests/testthat/test-partners.R +++ b/tests/testthat/test-partners.R @@ -147,6 +147,22 @@ test_that("cf_add_meta handles multiple key columns with suffixes", { expect_true("type.post" %in% names(result)) expect_true("class.pre" %in% names(result)) expect_true("class.post" %in% names(result)) + expect_equal(unique(result$type.pre), "G1_PN") + expect_true(all(c("G1.2_PN", "G2_PN") %in% result$type.post)) +}) + + +test_that("cf_add_meta uses dataset-encoded keys without requiring dataset column", { + register_rhubarb() + + partners <- cf_partners(cf_ids(rhubarb = 10001), partners = "outputs", + threshold = 1, details = "neither") + partners$dataset <- NULL + + result <- cf_add_meta(partners, keycol = "post_key") + + expect_true("type" %in% names(result)) + expect_true(all(c("G1.2_PN", "G2_PN") %in% result$type)) }) From ffeb026d48af7f082a1855fc55b19023e06c3b50 Mon Sep 17 00:00:00 2001 From: Gregory Jefferis Date: Wed, 1 Apr 2026 08:34:29 +0100 Subject: [PATCH 4/7] add missing doc file --- man/cf_add_meta.Rd | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 man/cf_add_meta.Rd diff --git a/man/cf_add_meta.Rd b/man/cf_add_meta.Rd new file mode 100644 index 0000000..4807b05 --- /dev/null +++ b/man/cf_add_meta.Rd @@ -0,0 +1,49 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/meta.R +\name{cf_add_meta} +\alias{cf_add_meta} +\title{Add metadata to a dataframe containing neuron keys} +\usage{ +cf_add_meta(x, keycol = "key", suffix = NULL, cols = NULL, ...) +} +\arguments{ +\item{x}{A data.frame containing one or more columns with keys} + +\item{keycol}{Character vector of column names containing keys. +Default \code{"key"}. When multiple columns specified, metadata is joined +for each with corresponding suffixes.} + +\item{suffix}{Character vector of suffixes for added columns. Must match +length of keycol. Default generates \code{""} for single keycol, or +\code{".1"}, \code{".2"}, etc. for multiple. Use \code{""} for no suffix.} + +\item{cols}{Character vector of column names to add from metadata. +Default \code{NULL} adds all columns. Warns if any specified columns +are not found in metadata. The \code{key} column is always kept for joining.} + +\item{...}{Additional arguments passed to \code{\link{cf_meta}}} +} +\value{ +data.frame with additional metadata columns +} +\description{ +Enriches a dataframe with metadata for neurons identified by + key columns. This is useful for adding metadata to partner data or other + results that contain neuron keys. +} +\examples{ +\dontrun{ +# Add metadata to partner column only +partners <- cf_partners(cf_ids(hemibrain='DA2_lPN'), threshold=10, details=FALSE) +partners_meta <- cf_add_meta(partners, keycol="post_key") + +# Add metadata to both pre and post +partners_both <- cf_add_meta(partners, + keycol = c("pre_key", "post_key"), + suffix = c(".pre", ".post")) + +# Add only type and side columns +partners_minimal <- cf_add_meta(partners, keycol="post_key", + cols = c("type", "side")) +} +} From 9622d911b4c79345f5bc44a6bfc173b497faa198 Mon Sep 17 00:00:00 2001 From: Gregory Jefferis Date: Wed, 1 Apr 2026 08:45:15 +0100 Subject: [PATCH 5/7] unrelated: partial string matching for datasets * the suggestions were poor because partial string matching was not enabled. * For example opic went to manc not opticlobe because of the length * also added package prefix for namespace issue --- R/datasets.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/datasets.R b/R/datasets.R index aba09b2..c96ab3e 100644 --- a/R/datasets.R +++ b/R/datasets.R @@ -38,7 +38,7 @@ match_datasets <- function(ds) { if(length(missing_ds)>0) { # Try approximate matching for each missing dataset suggestions <- vapply(missing_ds, function(m) { - distances <- adist(m, dss, ignore.case = TRUE) + distances <- utils::adist(m, dss, ignore.case = TRUE, partial=TRUE) closest_idx <- which.min(distances) min_dist <- distances[closest_idx] if (min_dist <= 3) { From 41ded20419282db3daa4245ccfe53049b1103aff Mon Sep 17 00:00:00 2001 From: Gregory Jefferis Date: Wed, 1 Apr 2026 08:53:09 +0100 Subject: [PATCH 6/7] better limits on dataset partial matching * also fixes new test error --- R/datasets.R | 2 +- tests/testthat/test-datasets.R | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/R/datasets.R b/R/datasets.R index c96ab3e..c6e33ba 100644 --- a/R/datasets.R +++ b/R/datasets.R @@ -41,7 +41,7 @@ match_datasets <- function(ds) { distances <- utils::adist(m, dss, ignore.case = TRUE, partial=TRUE) closest_idx <- which.min(distances) min_dist <- distances[closest_idx] - if (min_dist <= 3) { + if (min_dist <= 2) { paste0("Did you mean '", dss[closest_idx], "'?") } else { "" diff --git a/tests/testthat/test-datasets.R b/tests/testthat/test-datasets.R index df9685b..afcb8be 100644 --- a/tests/testthat/test-datasets.R +++ b/tests/testthat/test-datasets.R @@ -8,8 +8,9 @@ test_that("dataset functions work", { test_that("match_datasets suggests close matches", { # Typo should suggest correct dataset - expect_error(match_datasets("hemibran"), "Did you mean 'hemibrain'") - expect_error(match_datasets("flywie"), "Did you mean 'flywire'") + expect_error(match_datasets("hemb"), "Did you mean 'hemibrain'") + expect_error(match_datasets("flyb"), "Did you mean 'flywire'") + expect_error(match_datasets("opic"), "Did you mean 'opticlobe'") }) test_that("match_datasets shows no suggestion for unrelated names", { From ffc425222ff689ea124a70f696adb7c9389da23d Mon Sep 17 00:00:00 2001 From: Gregory Jefferis Date: Wed, 1 Apr 2026 12:20:14 +0100 Subject: [PATCH 7/7] add cf_add_meta to pkgdown --- _pkgdown.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/_pkgdown.yml b/_pkgdown.yml index 63a7b24..1cba866 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -14,6 +14,7 @@ reference: desc: Fetch neuron metadata and synaptic partner information contents: - cf_meta + - cf_add_meta - cf_partners - cf_partner_summary - multi_connection_table