From b84cbc0cb1a6411a47338de348d7eed9f433d803 Mon Sep 17 00:00:00 2001 From: Kasper Skytte Andersen Date: Mon, 6 Dec 2021 11:39:13 +0100 Subject: [PATCH] move some feature-specific pkgs to suggests --- DESCRIPTION | 29 ++++++++++++++--------------- NAMESPACE | 16 ++-------------- R/internals.R | 27 ++++++++++++++++++++++++--- R/mmload.R | 6 ++++-- R/mmplot_cov_profiles.R | 2 +- man/checkReqPkg.Rd | 22 ++++++++++++++++++++++ 6 files changed, 67 insertions(+), 35 deletions(-) create mode 100644 man/checkReqPkg.Rd diff --git a/DESCRIPTION b/DESCRIPTION index e591326..9563ab4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: mmgenome2 Type: Package Title: Tools for extracting individual genomes from metagenomes Description: mmgenome: a toolbox for extracting individual genomes from metagenomes. -Version: 2.2.0 +Version: 2.2.1 Date: 2018-01-01 Encoding: UTF-8 Authors@R: c( @@ -46,29 +46,28 @@ Imports: magrittr, dplyr, Biostrings, - rstudioapi, - clipr, + digest, igraph, ggrepel, tibble, tidyr, stringr, - shiny, - rlang -biocViews: - Biostrings -RoxygenNote: 7.1.1 + purrr, + rlang, + plyr, + forcats +remotes: + github::kasperskytte/Rtsne@openmp, + bioc::Biostrings +RoxygenNote: 7.1.2 VignetteBuilder: knitr Suggests: testthat, knitr, - tools, - utils, vegan, + shiny, Rtsne, - digest, - plotly, - purrr, - plyr, - forcats + rstudioapi, + clipr, + plotly URL: https://kasperskytte.github.io/mmgenome2 diff --git a/NAMESPACE b/NAMESPACE index 0b49b06..ec3accc 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -20,7 +20,6 @@ importFrom(Biostrings,readDNAStringSet) importFrom(Biostrings,reverseComplement) importFrom(Biostrings,width) importFrom(Biostrings,writeXStringSet) -importFrom(clipr,write_clip) importFrom(cowplot,plot_grid) importFrom(data.table,data.table) importFrom(data.table,fread) @@ -53,21 +52,10 @@ importFrom(igraph,graph.data.frame) importFrom(igraph,layout_with_fr) importFrom(magrittr,"%<>%") importFrom(magrittr,"%>%") +importFrom(plyr,ldply) +importFrom(purrr,imap) importFrom(rlang,quos) importFrom(rlang,sym) -importFrom(rstudioapi,viewer) -importFrom(shiny,actionButton) -importFrom(shiny,div) -importFrom(shiny,fillPage) -importFrom(shiny,icon) -importFrom(shiny,observeEvent) -importFrom(shiny,p) -importFrom(shiny,plotOutput) -importFrom(shiny,reactiveValues) -importFrom(shiny,renderPlot) -importFrom(shiny,runApp) -importFrom(shiny,shinyApp) -importFrom(shiny,stopApp) importFrom(sp,point.in.polygon) importFrom(stringr,str_remove) importFrom(stringr,str_replace_all) diff --git a/R/internals.R b/R/internals.R index d746d09..6bdd6fa 100644 --- a/R/internals.R +++ b/R/internals.R @@ -1,3 +1,23 @@ +#' @title Check for installed package +#' @description Returns error if a required package is not installed. Mostly used for checking whether packages listed under the Suggests field in the DESCRIPTION file is installed. +#' +#' @param pkg The package to check for, a character of length 1. +#' @param msg Optionally additional text appended (with \code{paste0}) to the default error message. +#' +#' @return Returns error and message if not installed, otherwise \code{invisible(TRUE)} +#' @author Kasper Skytte Andersen \email{ksa@@bio.aau.dk} +checkReqPkg <- function(pkg, msg = "") { + stopifnot(is.character(pkg), length(pkg) == 1L, nchar(pkg) > 0) + if (!requireNamespace(pkg, quietly = TRUE)) { + stopifnot(is.character(msg)) + stop( + paste0("Package '", pkg, "' is required but not installed. ", msg), + call. = FALSE + ) + } + require(pkg, quietly = TRUE, character.only = TRUE) +} + #' @title Merge mm object with more data #' #' @description Internal function used in mmload. \code{y} can be a named vector, dataframe, or a list containing any of these types of data to be merged with \code{x}. @@ -117,15 +137,16 @@ mmmerge <- function(x, y, type) { #' @return A data frame with the x/y coordinates of the mousepositions clicked in the ggplot2 plot. #' #' @import ggplot2 -#' @importFrom shiny actionButton div fillPage icon observeEvent p plotOutput reactiveValues renderPlot runApp shinyApp stopApp -#' @importFrom clipr write_clip -#' @importFrom rstudioapi viewer #' #' @author Kasper Skytte Andersen \email{ksa@@bio.aau.dk} #' @author Rasmus Hansen Kirkegaard \email{rhk@@bio.aau.dk} #' @author Soren M. Karst \email{smk@@bio.aau.dk} #' @author Mads Albertsen \email{MadsAlbertsen85@@gmail.com} mmlocator <- function(plot, x_scale = NULL, y_scale = NULL) { + checkReqPkg("shiny") + checkReqPkg("rstudioapi") + checkReqPkg("clipr") + app <- shinyApp( ui = fillPage( padding = c(5, 5, 50), diff --git a/R/mmload.R b/R/mmload.R index 41bd9b1..7a8c3e9 100644 --- a/R/mmload.R +++ b/R/mmload.R @@ -29,6 +29,7 @@ #' @importFrom dplyr mutate_all funs group_by left_join summarise_all #' @importFrom stringr str_replace_all str_remove #' @importFrom data.table fread +#' @importFrom tools file_path_sans_ext #' #' @examples #' \dontrun{ @@ -201,7 +202,8 @@ mmload <- function(assembly, ##### PCA of tetranucleotides ##### if (isTRUE(kmer_pca)) { - checkReqPkgs("vegan") + checkReqPkg("vegan") + if (isTRUE(verbose)) { message(paste0( "Calculating principal components of kmer (k=", @@ -222,7 +224,7 @@ mmload <- function(assembly, ##### BH tSNE of tetranucleotides ##### if (isTRUE(kmer_BH_tSNE)) { - checkReqPkgs("Rtsne") + checkReqPkg("Rtsne", "To install with support for multithreading run:\n remotes::install_github('kasperskytte/Rtsne@openmp')\notherwise just install from CRAN.") if (isTRUE(verbose)) { message(paste0( "Calculating Barnes-Hut t-Distributed Stochastic Neighbor Embedding representations of kmer (k=", diff --git a/R/mmplot_cov_profiles.R b/R/mmplot_cov_profiles.R index f864e8c..ada4300 100644 --- a/R/mmplot_cov_profiles.R +++ b/R/mmplot_cov_profiles.R @@ -148,7 +148,7 @@ mmplot_cov_profiles <- function(mm, # add points to plot and generate plotly hover labels if interactive, return plot if (isTRUE(interactive_plot)) { - checkReqPkgs(c("plotly", "purrr")) + checkReqPkg("plotly") data_plotly <- gg %>% purrr::imap(~ paste(.y, .x, sep = ": ")) %>% as.data.frame() %>% diff --git a/man/checkReqPkg.Rd b/man/checkReqPkg.Rd new file mode 100644 index 0000000..d823380 --- /dev/null +++ b/man/checkReqPkg.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/internals.R +\name{checkReqPkg} +\alias{checkReqPkg} +\title{Check for installed package} +\usage{ +checkReqPkg(pkg, msg = "") +} +\arguments{ +\item{pkg}{The package to check for, a character of length 1.} + +\item{msg}{Optionally additional text appended (with \code{paste0}) to the default error message.} +} +\value{ +Returns error and message if not installed, otherwise \code{invisible(TRUE)} +} +\description{ +Returns error if a required package is not installed. Mostly used for checking whether packages listed under the Suggests field in the DESCRIPTION file is installed. +} +\author{ +Kasper Skytte Andersen \email{ksa@bio.aau.dk} +}