From bbab104a04f12667e29426e9b829e806e80e92ac Mon Sep 17 00:00:00 2001 From: igor <6363505+igordot@users.noreply.github.com> Date: Fri, 20 Dec 2024 23:22:19 -0500 Subject: [PATCH] Clean up code --- .travis.yml | 14 ------ NAMESPACE | 12 ----- R/msigdbr.R | 43 +++++++++--------- R/utils-tidy-eval.R | 107 -------------------------------------------- man/tidyeval.Rd | 98 ---------------------------------------- 5 files changed, 21 insertions(+), 253 deletions(-) delete mode 100644 .travis.yml delete mode 100644 R/utils-tidy-eval.R delete mode 100644 man/tidyeval.Rd diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index a8280a0..0000000 --- a/.travis.yml +++ /dev/null @@ -1,14 +0,0 @@ -language: r -cache: packages - -r: - - 3.3 - - oldrel - - release - - devel - -r_packages: - - covr - -after_success: - - Rscript -e 'library(covr); codecov()' diff --git a/NAMESPACE b/NAMESPACE index 0b77268..8e051f1 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,12 +1,6 @@ # Generated by roxygen2: do not edit by hand export("%>%") -export(":=") -export(.data) -export(as_label) -export(as_name) -export(enquo) -export(enquos) export(msigdbr) export(msigdbr_collections) export(msigdbr_show_species) @@ -23,12 +17,6 @@ importFrom(dplyr,mutate) importFrom(dplyr,rename) importFrom(dplyr,select) importFrom(magrittr,"%>%") -importFrom(rlang,":=") -importFrom(rlang,.data) -importFrom(rlang,as_label) -importFrom(rlang,as_name) -importFrom(rlang,enquo) -importFrom(rlang,enquos) importFrom(tibble,as_tibble) importFrom(tidyselect,any_of) importFrom(tidyselect,everything) diff --git a/R/msigdbr.R b/R/msigdbr.R index 503e4cb..af5274a 100644 --- a/R/msigdbr.R +++ b/R/msigdbr.R @@ -28,7 +28,6 @@ #' msigdbr(species = "Mus musculus", category = "C2", subcategory = "CGP") #' } msigdbr <- function(species = "Homo sapiens", category = NULL, subcategory = NULL) { - # confirm that only one species is specified if (length(species) > 1) { stop("please specify only one species at a time") @@ -62,11 +61,9 @@ msigdbr <- function(species = "Homo sapiens", category = NULL, subcategory = NUL } # combine gene sets and genes - genesets_subset <- - genesets_subset %>% - inner_join(msigdbr_geneset_genes, by = "gs_id") %>% - inner_join(msigdbr_genes, by = "gene_id") %>% - select(-any_of(c("gene_id"))) + genesets_subset <- inner_join(genesets_subset, msigdbr_geneset_genes, by = "gs_id") + genesets_subset <- inner_join(genesets_subset, msigdbr_genes, by = "gene_id", relationship = "many-to-many") + genesets_subset <- select(genesets_subset, !any_of(c("gene_id"))) # retrieve orthologs if (species %in% c("Homo sapiens", "human")) { @@ -82,7 +79,7 @@ msigdbr <- function(species = "Homo sapiens", category = NULL, subcategory = NUL } else { orthologs_subset <- orthologs(genes = genesets_subset$human_ensembl_gene, species = species) %>% - select(-any_of(c("human_symbol", "human_entrez"))) %>% + select(!any_of(c("human_symbol", "human_entrez"))) %>% rename( human_ensembl_gene = "human_ensembl", gene_symbol = "symbol", @@ -94,19 +91,21 @@ msigdbr <- function(species = "Homo sapiens", category = NULL, subcategory = NUL } # combine gene sets and orthologs - genesets_subset %>% - inner_join(orthologs_subset, by = "human_ensembl_gene") %>% - arrange(.data$gs_name, .data$human_gene_symbol, .data$gene_symbol) %>% - select( - "gs_cat", - "gs_subcat", - "gs_name", - "gene_symbol", - "entrez_gene", - "ensembl_gene", - "human_gene_symbol", - "human_entrez_gene", - "human_ensembl_gene", - everything() - ) + genesets_subset <- inner_join(genesets_subset, orthologs_subset, by = "human_ensembl_gene", relationship = "many-to-many") + genesets_subset <- arrange(genesets_subset, .data$gs_name, .data$human_gene_symbol, .data$gene_symbol) + genesets_subset <- select( + genesets_subset, + "gs_cat", + "gs_subcat", + "gs_name", + "gene_symbol", + "entrez_gene", + "ensembl_gene", + "human_gene_symbol", + "human_entrez_gene", + "human_ensembl_gene", + everything() + ) + + return(genesets_subset) } diff --git a/R/utils-tidy-eval.R b/R/utils-tidy-eval.R deleted file mode 100644 index 09c3698..0000000 --- a/R/utils-tidy-eval.R +++ /dev/null @@ -1,107 +0,0 @@ -#' Tidy eval helpers -#' -#' @description -#' This page lists the tidy eval tools reexported in this package from -#' rlang. To learn about using tidy eval in scripts and packages at a -#' high level, see the [dplyr programming -#' vignette](https://dplyr.tidyverse.org/articles/programming.html) -#' and the [ggplot2 in packages -#' vignette](https://ggplot2.tidyverse.org/articles/ggplot2-in-packages.html). -#' The [Metaprogramming -#' section](https://adv-r.hadley.nz/metaprogramming.html) of [Advanced -#' R](https://adv-r.hadley.nz) may also be useful for a deeper dive. -#' -#' * The tidy eval operators `{{`, `!!`, and `!!!` are syntactic -#' constructs which are specially interpreted by tidy eval functions. -#' You will mostly need `{{`, as `!!` and `!!!` are more advanced -#' operators which you should not have to use in simple cases. -#' -#' The curly-curly operator `{{` allows you to tunnel data-variables -#' passed from function arguments inside other tidy eval functions. -#' `{{` is designed for individual arguments. To pass multiple -#' arguments contained in dots, use `...` in the normal way. -#' -#' ``` -#' my_function <- function(data, var, ...) { -#' data %>% -#' group_by(...) %>% -#' summarise(mean = mean({{ var }})) -#' } -#' ``` -#' -#' * [enquo()] and [enquos()] delay the execution of one or several -#' function arguments. The former returns a single expression, the -#' latter returns a list of expressions. Once defused, expressions -#' will no longer evaluate on their own. They must be injected back -#' into an evaluation context with `!!` (for a single expression) and -#' `!!!` (for a list of expressions). -#' -#' ``` -#' my_function <- function(data, var, ...) { -#' # Defuse -#' var <- enquo(var) -#' dots <- enquos(...) -#' -#' # Inject -#' data %>% -#' group_by(!!!dots) %>% -#' summarise(mean = mean(!!var)) -#' } -#' ``` -#' -#' In this simple case, the code is equivalent to the usage of `{{` -#' and `...` above. Defusing with `enquo()` or `enquos()` is only -#' needed in more complex cases, for instance if you need to inspect -#' or modify the expressions in some way. -#' -#' * The `.data` pronoun is an object that represents the current -#' slice of data. If you have a variable name in a string, use the -#' `.data` pronoun to subset that variable with `[[`. -#' -#' ``` -#' my_var <- "disp" -#' mtcars %>% summarise(mean = mean(.data[[my_var]])) -#' ``` -#' -#' * Another tidy eval operator is `:=`. It makes it possible to use -#' glue and curly-curly syntax on the LHS of `=`. For technical -#' reasons, the R language doesn't support complex expressions on -#' the left of `=`, so we use `:=` as a workaround. -#' -#' ``` -#' my_function <- function(data, var, suffix = "foo") { -#' # Use `{{` to tunnel function arguments and the usual glue -#' # operator `{` to interpolate plain strings. -#' data %>% -#' summarise("{{ var }}_mean_{suffix}" := mean({{ var }})) -#' } -#' ``` -#' -#' * Many tidy eval functions like `dplyr::mutate()` or -#' `dplyr::summarise()` give an automatic name to unnamed inputs. If -#' you need to create the same sort of automatic names by yourself, -#' use `as_label()`. For instance, the glue-tunnelling syntax above -#' can be reproduced manually with: -#' -#' ``` -#' my_function <- function(data, var, suffix = "foo") { -#' var <- enquo(var) -#' prefix <- as_label(var) -#' data %>% -#' summarise("{prefix}_mean_{suffix}" := mean(!!var)) -#' } -#' ``` -#' -#' Expressions defused with `enquo()` (or tunnelled with `{{`) need -#' not be simple column names, they can be arbitrarily complex. -#' `as_label()` handles those cases gracefully. If your code assumes -#' a simple column name, use `as_name()` instead. This is safer -#' because it throws an error if the input is not a name as expected. -#' -#' @md -#' @name tidyeval -#' @keywords internal -#' @importFrom rlang enquo enquos .data := as_name as_label -#' @aliases enquo enquos .data := as_name as_label -#' @export enquo enquos .data := as_name as_label -NULL diff --git a/man/tidyeval.Rd b/man/tidyeval.Rd deleted file mode 100644 index f773abf..0000000 --- a/man/tidyeval.Rd +++ /dev/null @@ -1,98 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils-tidy-eval.R -\name{tidyeval} -\alias{tidyeval} -\alias{enquo} -\alias{enquos} -\alias{.data} -\alias{:=} -\alias{as_name} -\alias{as_label} -\title{Tidy eval helpers} -\description{ -This page lists the tidy eval tools reexported in this package from -rlang. To learn about using tidy eval in scripts and packages at a -high level, see the \href{https://dplyr.tidyverse.org/articles/programming.html}{dplyr programming vignette} -and the \href{https://ggplot2.tidyverse.org/articles/ggplot2-in-packages.html}{ggplot2 in packages vignette}. -The \href{https://adv-r.hadley.nz/metaprogramming.html}{Metaprogramming section} of \href{https://adv-r.hadley.nz}{Advanced R} may also be useful for a deeper dive. -\itemize{ -\item The tidy eval operators \verb{\{\{}, \verb{!!}, and \verb{!!!} are syntactic -constructs which are specially interpreted by tidy eval functions. -You will mostly need \verb{\{\{}, as \verb{!!} and \verb{!!!} are more advanced -operators which you should not have to use in simple cases. - -The curly-curly operator \verb{\{\{} allows you to tunnel data-variables -passed from function arguments inside other tidy eval functions. -\verb{\{\{} is designed for individual arguments. To pass multiple -arguments contained in dots, use \code{...} in the normal way. - -\if{html}{\out{