From 563a6d1adfcca65a77a209d159595b05649076cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lie=20Siberchicot?= Date: Wed, 31 Jul 2024 09:06:03 +0200 Subject: [PATCH] Just spaces --- R/build_Lifemap.R | 36 ++++++++++++++++++++++-------------- R/display_map.R | 14 +++++++------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/R/build_Lifemap.R b/R/build_Lifemap.R index 408864c..576ea02 100644 --- a/R/build_Lifemap.R +++ b/R/build_Lifemap.R @@ -36,19 +36,21 @@ build_Lifemap <- function(df, basemap = c("ncbi", "base", "fr", "virus"), verbose = TRUE) { basemap <- match.arg(arg = basemap, choices = basemap) - if(is.null(df$taxid)) { + if (is.null(df$taxid)) { stop('The dataframe must at least contain a "taxid" column') } # create a new "environment" to store the full data - if(!exists("lifemap_basemap_envir", where = .GlobalEnv)) lifemap_basemap_envir <- new.env() + if (!exists("lifemap_basemap_envir", where = .GlobalEnv)) { + lifemap_basemap_envir <- new.env() + } ## SET DATASETS ASDRESSES # getting the right URL depending on the basemap wanted - if(basemap == "ncbi") { + if (basemap == "ncbi") { basemap_url <- "https://lifemap-ncbi.univ-lyon1.fr/data/lmdata.Rdata" - } else if(basemap == "fr") { + } else if (basemap == "fr") { basemap_url <- "https://lifemap-fr.univ-lyon1.fr/data/lmdata.Rdata" - } else if(basemap == "base") { + } else if (basemap == "base") { basemap_url <- "https://lifemap.univ-lyon1.fr/data/lmdata.Rdata" } # else if(basemap == "virus") { @@ -71,9 +73,11 @@ build_Lifemap <- function(df, basemap = c("ncbi", "base", "fr", "virus"), verbos } ) - if(!is.na(y)) { + if (!is.na(y)) { # download full data for chosen basemap - if(verbose) cat("Downloading basemap coordinates...\n") + if (verbose) { + cat("Downloading basemap coordinates...\n") + } load(url(basemap_url), envir = lifemap_basemap_envir) # add LUCA @@ -82,17 +86,21 @@ build_Lifemap <- function(df, basemap = c("ncbi", "base", "fr", "virus"), verbos # get info for unique taxids (then we work with df_distinct, not df anymore) df_distinct <- dplyr::distinct(df, .data$taxid, .keep_all = TRUE) - if(nrow(df_distinct) != nrow(df)) { - warning(sprintf("%s duplicated TaxIDs were removed \n",nrow(df)-nrow(df_distinct))) + if (nrow(df_distinct) != nrow(df)) { + warning(sprintf("%s duplicated TaxIDs were removed \n", nrow(df) - nrow(df_distinct))) } # get data - if(verbose) cat("Getting info for requested taxids...\n") + if (verbose) { + cat("Getting info for requested taxids...\n") + } # get index of requested taxids indexes <- fastmatch::fmatch(df_distinct$taxid, lifemap_basemap_envir$DF$taxid) - if(sum(is.na(indexes)) > 0) { - warning(sprintf("%s TaxID(s) could not be found: %s \n",sum(is.na(indexes)), paste(df_distinct$taxid[is.na(indexes)], sep=","))) + if (sum(is.na(indexes)) > 0) { + warning(sprintf("%s TaxID(s) could not be found: %s \n", + sum(is.na(indexes)), + paste(df_distinct$taxid[is.na(indexes)], sep = ","))) } # create new df with only existing taxids @@ -105,8 +113,8 @@ build_Lifemap <- function(df, basemap = c("ncbi", "base", "fr", "virus"), verbos ANCESTORS <- lifemap_basemap_envir$DF[fastmatch::fmatch(real_ancestors, lifemap_basemap_envir$DF$taxid), ] # add type - DATA0$type<-"requested" - ANCESTORS$type<-"ancestor" + DATA0$type <- "requested" + ANCESTORS$type <- "ancestor" # bind all DATA1 <- rbind(DATA0, ANCESTORS) diff --git a/R/display_map.R b/R/display_map.R index c7fc2ce..32ca94c 100644 --- a/R/display_map.R +++ b/R/display_map.R @@ -17,18 +17,18 @@ #' #' @examples #' display_map() -display_map <- function(df = NULL, basemap = c("fr","ncbi", "base","virus")) { +display_map <- function(df = NULL, basemap = c("fr", "ncbi", "base", "virus")) { basemap <- match.arg(basemap) if (basemap == "fr"){ - display="http://lifemap-fr.univ-lyon1.fr/osm_tiles/{z}/{x}/{y}.png" + display <- "http://lifemap-fr.univ-lyon1.fr/osm_tiles/{z}/{x}/{y}.png" } else if (basemap == "ncbi"){ - display="http://lifemap-ncbi.univ-lyon1.fr/osm_tiles/{z}/{x}/{y}.png" + display <- "http://lifemap-ncbi.univ-lyon1.fr/osm_tiles/{z}/{x}/{y}.png" } else if (basemap == "base"){ - display="http://lifemap.univ-lyon1.fr/osm_tiles/{z}/{x}/{y}.png" + display <- "http://lifemap.univ-lyon1.fr/osm_tiles/{z}/{x}/{y}.png" } else if (basemap == "virus"){ - display="https://virusmap.univ-lyon1.fr/osm_tiles/{z}/{x}/{y}.png" + display <- "https://virusmap.univ-lyon1.fr/osm_tiles/{z}/{x}/{y}.png" } - url2check<-strsplit(display, "osm_tiles")[[1]][1] + url2check <- strsplit(display, "osm_tiles")[[1]][1] m <- tryCatch({ leaflet::leaflet(df) |> @@ -44,7 +44,7 @@ display_map <- function(df = NULL, basemap = c("fr","ncbi", "base","virus")) { } ) - if(!all(is.na(m))) { + if (!all(is.na(m))) { return(m) } else { return(NA)