Skip to content

Commit

Permalink
Removing dplyr dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
zsteinmetz committed Aug 8, 2023
1 parent bb59de6 commit 3c59325
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ Depends:
Imports:
methods,
magrittr,
dplyr,
data.table,
jsonlite,
yaml,
Expand All @@ -71,6 +70,7 @@ Suggests:
shinythemes,
shinyBS,
shinyWidgets,
dplyr,
ggplot2,
DT,
curl,
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ importFrom(data.table,rbindlist)
importFrom(data.table,setDT)
importFrom(data.table,transpose)
importFrom(digest,digest)
importFrom(dplyr,left_join)
importFrom(grDevices,chull)
importFrom(graphics,matlines)
importFrom(graphics,matplot)
Expand Down
23 changes: 15 additions & 8 deletions R/match_spec.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
#' @importFrom magrittr %>%
#' @importFrom stats cor
#' @importFrom data.table data.table fifelse .SD
#' @importFrom dplyr left_join
#' @export
correlate_spectra <- function(object, ...) {
UseMethod("correlate_spectra")
Expand Down Expand Up @@ -81,13 +80,21 @@ identify_spectra <- function(cor_matrix, object, library, top_n = NULL,
message("top_n was larger than the number of spectra in the library, returning all matches")
}

data.table(object_id = colnames(object$spectra),
library_id = rep(colnames(library$spectra),
each = ncol(object$spectra)),
match_val = c(cor_matrix)) %>%
{ if (is.numeric(top_n)) .[order(-match_val), head(.SD, top_n), by = object_id] else .} %>%
{ if (is.character(add_library_metadata)) left_join(., library$metadata, by = c("library_id" = add_library_metadata)) else . } %>%
{ if (is.character(add_object_metadata)) left_join(., object$metadata, by = c("object_id" = add_object_metadata)) else . }
out <- data.table(object_id = colnames(object$spectra),
library_id = rep(colnames(library$spectra),
each = ncol(object$spectra)),
match_val = c(cor_matrix))

if (is.character(add_library_metadata))
out <- merge(out, library$metadata,
by.x = "library_id", by.y = add_library_metadata, all.x = T)
if (is.character(add_object_metadata))
out <- merge(out, object$metadata,
by.x = "object_id", by.y = add_object_metadata, all.x = T)
if (is.numeric(top_n))
out <- out[order(-match_val), head(.SD, top_n), by = object_id]

return(out)
}

#' @export
Expand Down

0 comments on commit 3c59325

Please sign in to comment.