From f637a3c9fe0e73f88346b1624d28ce381cf8be27 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Thu, 29 Aug 2019 17:32:05 -0400 Subject: [PATCH] rely on purrr instead of purrrlyr --- DESCRIPTION | 2 +- NAMESPACE | 5 ++++- R/pairwise_comparisons.R | 39 +++++++++++++++++++++++++-------------- codemeta.json | 18 ++++++++++++------ 4 files changed, 42 insertions(+), 22 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 63e03c4..bb0cd91 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -30,7 +30,7 @@ Imports: groupedstats, jmv, magrittr (>= 1.5), - purrrlyr, + purrr, rlang (>= 0.4.0), stats, stringr, diff --git a/NAMESPACE b/NAMESPACE index b4be3dc..b0dcce6 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -19,6 +19,7 @@ importFrom(WRS2,rmmcp) importFrom(dplyr,everything) importFrom(dplyr,full_join) importFrom(dplyr,group_by) +importFrom(dplyr,group_nest) importFrom(dplyr,mutate) importFrom(dplyr,mutate_at) importFrom(dplyr,mutate_if) @@ -36,7 +37,7 @@ importFrom(jmv,anovaRMNP) importFrom(magrittr,"%$%") importFrom(magrittr,"%<>%") importFrom(magrittr,"%>%") -importFrom(purrrlyr,by_row) +importFrom(purrr,map) importFrom(rlang,"!!") importFrom(rlang,"%|%") importFrom(rlang,"%||%") @@ -59,6 +60,8 @@ importFrom(tibble,enframe) importFrom(tibble,rowid_to_column) importFrom(tibble,tibble) importFrom(tidyr,gather) +importFrom(tidyr,nest) importFrom(tidyr,separate) importFrom(tidyr,spread) +importFrom(tidyr,unnest) importFrom(utils,combn) diff --git a/R/pairwise_comparisons.R b/R/pairwise_comparisons.R index 2886e93..772e9fa 100644 --- a/R/pairwise_comparisons.R +++ b/R/pairwise_comparisons.R @@ -51,15 +51,16 @@ #' } #' #' @importFrom dplyr select rename mutate mutate_if everything full_join vars +#' @importFrom dplyr group_nest #' @importFrom stats p.adjust pairwise.t.test na.omit aov TukeyHSD var sd #' @importFrom stringr str_replace #' @importFrom WRS2 lincon rmmcp -#' @importFrom tidyr gather spread separate +#' @importFrom tidyr gather spread separate unnest nest #' @importFrom rlang !! enquo as_string ensym #' @importFrom tibble as_tibble rowid_to_column enframe #' @importFrom jmv anovaNP anovaRMNP #' @importFrom forcats fct_relabel -#' @importFrom purrrlyr by_row +#' @importFrom purrr map #' #' @examples #' @@ -472,17 +473,27 @@ pairwise_comparisons <- function(data, .predicate = is.factor, .funs = ~ as.character(.) ) %>% - purrrlyr::by_row( - .d = ., - ..f = ~ specify_decimal_p( - x = .$p.value, - k = k, - p.value = TRUE - ), - .collate = "rows", - .to = "label", - .labels = TRUE - ) %>% + dplyr::mutate(.data = ., rowid = dplyr::row_number()) %>% + dplyr::group_nest(.tbl = ., rowid) %>% + dplyr::mutate( + .data = ., + label = data %>% + purrr::map( + .x = ., + .f = ~ specify_decimal_p(x = .$p.value, k = k, p.value = TRUE) + ) + ) + + # unnesting the dataframe + if (utils::packageVersion("tidyr") <= "0.8.9") { + df %<>%tidyr::unnest(.) + } else { + df%<>% tidyr::unnest(., cols = c(data, label)) + } + + + # formatting label + df %<>% dplyr::mutate( .data = ., p.value.label = dplyr::case_when( @@ -490,7 +501,7 @@ pairwise_comparisons <- function(data, TRUE ~ paste("list(~italic(p)==", label, ")", sep = " ") ) ) %>% - dplyr::select(.data = ., -label) + dplyr::select(.data = ., -label, -rowid) # return return(tibble::as_tibble(df)) diff --git a/codemeta.json b/codemeta.json index a7ae8ea..7df50c2 100644 --- a/codemeta.json +++ b/codemeta.json @@ -8,10 +8,10 @@ "description": "Multiple pairwise comparison tests for one-way\n analysis of variance for both between-subjects and within-subjects\n designs. Currently, it supports only the most common types of\n statistical analyses and tests: parametric (Welch's and Student's\n t-test), nonparametric (Durbin-Conover test and\n Dwass-Steel-Crichtlow-Fligner test), robust (Yuen’s trimmed means test).", "name": "pairwiseComparisons: Multiple Pairwise Comparison Tests", "codeRepository": "https://github.com/IndrajeetPatil/pairwiseComparisons", - "relatedLink": "https://indrajeetpatil.github.io/pairwiseComparisons/", + "relatedLink": ["https://indrajeetpatil.github.io/pairwiseComparisons/", "https://CRAN.R-project.org/package=pairwiseComparisons"], "issueTracker": "\n https://github.com/IndrajeetPatil/pairwiseComparisons/issues", "license": "https://spdx.org/licenses/GPL-3.0", - "version": "0.1.0", + "version": "0.1.0.9000", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R", @@ -207,15 +207,15 @@ }, { "@type": "SoftwareApplication", - "identifier": "purrrlyr", - "name": "purrrlyr", + "identifier": "purrr", + "name": "purrr", "provider": { "@id": "https://cran.r-project.org", "@type": "Organization", "name": "Comprehensive R Archive Network (CRAN)", "url": "https://cran.r-project.org" }, - "sameAs": "https://CRAN.R-project.org/package=purrrlyr" + "sameAs": "https://CRAN.R-project.org/package=purrr" }, { "@type": "SoftwareApplication", @@ -318,5 +318,11 @@ "url": "https://CRAN.R-project.org/package=pairwiseComparisons" } ], - "readme": "https://github.com/IndrajeetPatil/pairwiseComparisons/blob/master/README.md" + "readme": "https://github.com/IndrajeetPatil/pairwiseComparisons/blob/master/README.md", + "provider": { + "@id": "https://cran.r-project.org", + "@type": "Organization", + "name": "Comprehensive R Archive Network (CRAN)", + "url": "https://cran.r-project.org" + } }