Skip to content

Commit

Permalink
Optimise the 'pass_infos_discret' function (time divided by five)
Browse files Browse the repository at this point in the history
  • Loading branch information
aursiber committed Mar 20, 2024
1 parent 681644e commit bb758df
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: LifemapR
Title: Data Visualisation on 'Lifemap' Tree
Version: 1.1.1
Imports: leaflet, shiny, jsonlite, dplyr, leaflet.minicharts, htmltools, rlang, RCurl, fastmatch
Imports: leaflet, shiny, jsonlite, dplyr, tidyr, leaflet.minicharts, htmltools, rlang, RCurl, fastmatch
Authors@R: c(
person("Cassandra", "Bompard", role = "aut", email = "[email protected]"),
person("Damien M.", "de Vienne", role = "aut", email = "[email protected]"),
Expand Down
8 changes: 8 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ export(make_newick)
export(pass_infos)
export(pass_infos_discret)
importFrom(RCurl,url.exists)
importFrom(dplyr,all_of)
importFrom(dplyr,arrange)
importFrom(dplyr,bind_rows)
importFrom(dplyr,count)
importFrom(dplyr,distinct)
importFrom(dplyr,full_join)
importFrom(dplyr,group_by)
importFrom(dplyr,join_by)
importFrom(dplyr,left_join)
importFrom(dplyr,rename)
importFrom(dplyr,select)
importFrom(fastmatch,fmatch)
importFrom(htmltools,HTML)
importFrom(htmltools,p)
Expand Down Expand Up @@ -55,3 +61,5 @@ importFrom(shiny,observe)
importFrom(shiny,reactive)
importFrom(shiny,shinyApp)
importFrom(stats,complete.cases)
importFrom(stats,na.omit)
importFrom(tidyr,pivot_wider)
23 changes: 14 additions & 9 deletions R/create_matrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ pass_infos <- function(M, FUN, value){
#'
#' @return A dataframe containing the TaxIDs and as many columns as there are distinct values.
#' @export
#' @importFrom dplyr bind_rows
#' @importFrom dplyr select group_by count rename arrange all_of
#' @importFrom tidyr pivot_wider
#' @importFrom stats na.omit
#' @importFrom rlang .data
#'
#' @examples
#' data(LM_eukaryotes)
Expand All @@ -70,13 +73,15 @@ pass_infos <- function(M, FUN, value){
#'
#' inferred_values <- pass_infos_discret(M = infos, value = "Status")
pass_infos_discret <- function(M, value) {
tabled <- tapply(M[[value]], M$ancestor, function(x){
x <- x[!is.na(x)]
table(x)})
bind_values <- as.data.frame(dplyr::bind_rows(tabled))
bind_values[is.na(bind_values)] <- 0
bind_values$taxid <- names(tabled)
bind_values <- M |>
dplyr::select(.data$ancestor, dplyr::all_of(value)) |>
stats::na.omit() |>
dplyr::group_by(.data$Status, .data$ancestor) |>
dplyr::count() |>
tidyr::pivot_wider(names_from = .data$Status, values_from = .data$n, values_fill = 0) |>
as.data.frame() |>
dplyr::rename("taxid" = "ancestor") |>
dplyr::arrange(.data$taxid)

return(bind_values)
}


0 comments on commit bb758df

Please sign in to comment.