Closed fmmattioni closed 4 years ago
This is definitely a bug in how ggstatsplot
is currently doing argument evaluation using rlang
. I plan to completely rewrite it but it will take a while. I will see if I can find an alternative way to get your custom function to run without a rewrite.
Related to https://github.com/IndrajeetPatil/ggstatsplot/issues/329.
Thank you for the feedback! There is no rush, though, as I currently have a workaround. But it would be nice to have that fixed in the future. Thanks again!
Here is how to make all of these work:
library(ggstatsplot)
data_bugs <- bugs_long %>%
dplyr::filter(region %in% c("Europe", "North America")) %>%
dplyr::filter(condition %in% c("LDLF", "LDHF"))
display_grouped_within <- function(
.data,
x = condition,
y = desire,
grouping.var = region
) {
grouped_ggwithinstats(
data = .data,
x = {{ x }},
y = {{ y }},
grouping.var = {{ grouping.var }},
messages = FALSE
)
}
data_bugs %>%
display_grouped_within()
library(ggstatsplot)
data_bugs <- bugs_long %>%
dplyr::filter(region %in% c("Europe", "North America")) %>%
dplyr::filter(condition %in% c("LDLF", "LDHF"))
display_grouped_within <- function(
.data,
x = condition,
y = desire,
grouping.var = region
) {
grouped_ggwithinstats(
data = .data,
x = {{x}},
y = {{y}},
grouping.var = {{grouping.var}},
messages = FALSE
)
}
data_bugs %>%
display_grouped_within()
library(ggstatsplot)
data_bugs <- bugs_long %>%
dplyr::filter(region %in% c("Europe", "North America")) %>%
dplyr::filter(condition %in% c("LDLF", "LDHF"))
display_grouped_within <- function(
.data,
x = "condition",
y = "desire",
grouping.var = "region"
) {
grouped_ggwithinstats(
data = .data,
x = {{x}},
y = {{y}},
grouping.var = {{grouping.var}},
messages = FALSE
)
}
data_bugs %>%
display_grouped_within()
Created on 2020-05-26 by the reprex package (v0.3.0.9001)
That is great!!! Thank you very much for the hard work, @IndrajeetPatil!
I am currently trying to wrap a
ggstatsplot
inside a function, but it doesn't seem to work regardless if arguments are quoted or not.Minimal reprex:
normal example, everything works
``` r library(ggstatsplot) data_bugs <- bugs_long %>% dplyr::filter(region %in% c("Europe", "North America")) %>% dplyr::filter(condition %in% c("LDLF", "LDHF")) data_bugs %>% grouped_ggwithinstats( x = condition, y = desire, grouping.var = region, messages = FALSE ) ``` ![](https://i.imgur.com/kMWqnCH.png) Created on 2020-02-05 by the [reprex package](https://reprex.tidyverse.org) (v0.3.0)including inside a function example 1
``` r library(ggstatsplot) data_bugs <- bugs_long %>% dplyr::filter(region %in% c("Europe", "North America")) %>% dplyr::filter(condition %in% c("LDLF", "LDHF")) display_grouped_within <- function( .data, x = condition, y = desire, grouping.var = region ) { grouped_ggwithinstats( data = .data, x = {{ x }}, y = {{ y }}, grouping.var = {{ grouping.var }}, messages = FALSE ) } data_bugs %>% display_grouped_within() #> Warning in if (as.character(param_list$x) == #> as.character(param_list$grouping.var)) {: the condition has length > 1 and only #> the first element will be used #> #> Error: Identical variable ( { ) was used for both grouping and x axis, which is not allowed. #> Identical variable ( { #> x #> } ) was used for both grouping and x axis, which is not allowed. #> ``` Created on 2020-02-05 by the [reprex package](https://reprex.tidyverse.org) (v0.3.0)including inside a function example 2
``` r library(ggstatsplot) data_bugs <- bugs_long %>% dplyr::filter(region %in% c("Europe", "North America")) %>% dplyr::filter(condition %in% c("LDLF", "LDHF")) display_grouped_within <- function( .data, x = condition, y = desire, grouping.var = region ) { grouped_ggwithinstats( data = .data, x = x, y = y, grouping.var = grouping.var, messages = FALSE ) } data_bugs %>% display_grouped_within() #> Error: Can't subset columns that don't exist. #> x The column `grouping.var` doesn't exist. ``` Created on 2020-02-05 by the [reprex package](https://reprex.tidyverse.org) (v0.3.0)including inside a function example 3
``` r library(ggstatsplot) data_bugs <- bugs_long %>% dplyr::filter(region %in% c("Europe", "North America")) %>% dplyr::filter(condition %in% c("LDLF", "LDHF")) display_grouped_within <- function( .data, x = "condition", y = "desire", grouping.var = "region" ) { grouped_ggwithinstats( data = .data, x = x, y = y, grouping.var = grouping.var, messages = FALSE ) } data_bugs %>% display_grouped_within() #> Error: Can't subset columns that don't exist. #> x The column `grouping.var` doesn't exist. ``` Created on 2020-02-05 by the [reprex package](https://reprex.tidyverse.org) (v0.3.0)session info
```r ─ Session info ────────────────────────────────────────────────────────────────────────────────────────────── setting value version R version 3.6.1 (2019-07-05) os macOS Catalina 10.15.2 system x86_64, darwin15.6.0 ui RStudio language (EN) collate en_US.UTF-8 ctype en_US.UTF-8 tz Europe/Berlin date 2020-02-05 ─ Packages ────────────────────────────────────────────────────────────────────────────────────────────────── package * version date lib source abind 1.4-5 2016-07-21 [1] CRAN (R 3.6.0) assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.6.0) backports 1.1.5 2019-10-02 [1] CRAN (R 3.6.0) base64enc 0.1-3 2015-07-28 [1] CRAN (R 3.6.0) BayesFactor 0.9.12-4.2 2018-05-19 [1] CRAN (R 3.6.0) bayestestR 0.5.1 2020-01-27 [1] CRAN (R 3.6.1) bbmle 1.0.23.1 2020-02-03 [1] CRAN (R 3.6.1) bdsmatrix 1.3-4 2020-01-13 [1] CRAN (R 3.6.0) boot 1.3-24 2019-12-20 [1] CRAN (R 3.6.0) bridgesampling 0.8-1 2020-01-16 [1] CRAN (R 3.6.1) Brobdingnag 1.2-6 2018-08-13 [1] CRAN (R 3.6.0) broom 0.5.4 2020-01-27 [1] CRAN (R 3.6.1) broom.mixed 0.2.4 2019-02-21 [1] CRAN (R 3.6.0) broomExtra 1.0.1 2020-01-07 [1] CRAN (R 3.6.1) callr 3.4.1 2020-01-24 [1] CRAN (R 3.6.1) car 3.0-6 2019-12-23 [1] CRAN (R 3.6.0) carData 3.0-3 2019-11-16 [1] CRAN (R 3.6.0) cellranger 1.1.0 2016-07-27 [1] CRAN (R 3.6.0) cli 2.0.1 2020-01-08 [1] CRAN (R 3.6.1) clipr 0.7.0 2019-07-23 [1] CRAN (R 3.6.0) cluster 2.1.0 2019-06-19 [1] CRAN (R 3.6.1) coda 0.19-3 2019-07-05 [1] CRAN (R 3.6.0) codetools 0.2-16 2018-12-24 [1] CRAN (R 3.6.1) coin 1.3-1 2019-08-28 [1] CRAN (R 3.6.0) colorspace 1.4-1 2019-03-18 [1] CRAN (R 3.6.0) cowplot 1.0.0 2019-07-11 [1] CRAN (R 3.6.0) crayon 1.3.4 2017-09-16 [1] CRAN (R 3.6.0) curl 4.3 2019-12-02 [1] CRAN (R 3.6.0) data.table 1.12.8 2019-12-09 [1] CRAN (R 3.6.0) desc 1.2.0 2018-05-01 [1] CRAN (R 3.6.0) DescTools 0.99.32 2020-01-17 [1] CRAN (R 3.6.1) details 0.2.1 2020-01-14 [1] Github (yonicd/details@af2cb25) dichromat 2.0-0 2013-01-24 [1] CRAN (R 3.6.0) digest 0.6.23 2019-11-23 [1] CRAN (R 3.6.0) dplyr 0.8.4 2020-01-31 [1] CRAN (R 3.6.1) effectsize 0.1.2 2020-02-04 [1] Github (easystats/effectsize@57e5f11) ellipsis 0.3.0 2019-09-20 [1] CRAN (R 3.6.0) emmeans 1.4.4 2020-01-28 [1] CRAN (R 3.6.1) EMT 1.1 2013-01-29 [1] CRAN (R 3.6.0) estimability 1.3 2018-02-11 [1] CRAN (R 3.6.0) evaluate 0.14 2019-05-28 [1] CRAN (R 3.6.0) expm 0.999-4 2019-03-21 [1] CRAN (R 3.6.0) ez 4.4-0 2016-11-02 [1] CRAN (R 3.6.0) fansi 0.4.1 2020-01-08 [1] CRAN (R 3.6.1) farver 2.0.3 2020-01-16 [1] CRAN (R 3.6.1) fastGHQuad 1.0 2018-09-30 [1] CRAN (R 3.6.0) fastmap 1.0.1 2019-10-08 [1] CRAN (R 3.6.0) forcats 0.4.0 2019-02-17 [1] CRAN (R 3.6.0) foreign 0.8-71 2018-07-20 [1] CRAN (R 3.6.1) fs 1.3.1 2019-05-06 [1] CRAN (R 3.6.0) generics 0.0.2 2018-11-29 [1] CRAN (R 3.6.0) ggcorrplot 0.1.3 2019-05-19 [1] CRAN (R 3.6.0) ggExtra 0.9 2019-08-27 [1] CRAN (R 3.6.0) ggplot2 3.2.1 2019-08-10 [1] CRAN (R 3.6.0) ggrepel 0.8.1 2019-05-07 [1] CRAN (R 3.6.0) ggsignif 0.6.0 2019-08-08 [1] CRAN (R 3.6.0) ggstatsplot * 0.2.0 2020-02-03 [1] CRAN (R 3.6.1) glue 1.3.1.9000 2020-02-05 [1] Github (tidyverse/glue@c1067c3) gridExtra 2.3 2017-09-09 [1] CRAN (R 3.6.0) groupedstats 0.1.1 2020-01-14 [1] CRAN (R 3.6.1) gtable 0.3.0 2019-03-25 [1] CRAN (R 3.6.0) gtools 3.8.1 2018-06-26 [1] CRAN (R 3.6.0) haven 2.2.0 2019-11-08 [1] CRAN (R 3.6.0) hms 0.5.3 2020-01-08 [1] CRAN (R 3.6.1) htmltools 0.4.0 2019-10-04 [1] CRAN (R 3.6.0) httpuv 1.5.2 2019-09-11 [1] CRAN (R 3.6.0) httr 1.4.1 2019-08-05 [1] CRAN (R 3.6.0) inline 0.3.15 2018-05-18 [1] CRAN (R 3.6.0) insight 0.8.1 2020-02-02 [1] CRAN (R 3.6.0) jcolors 0.0.4 2019-05-22 [1] CRAN (R 3.6.0) jmv 1.0.8 2019-10-23 [1] CRAN (R 3.6.0) jmvcore 1.2.5 2020-02-05 [1] CRAN (R 3.6.1) jsonlite 1.6.1 2020-02-02 [1] CRAN (R 3.6.0) knitr 1.27 2020-01-16 [1] CRAN (R 3.6.1) labeling 0.3 2014-08-23 [1] CRAN (R 3.6.0) LaplacesDemon 16.1.1 2018-06-30 [1] CRAN (R 3.6.0) later 1.0.0 2019-10-04 [1] CRAN (R 3.6.0) lattice 0.20-38 2018-11-04 [1] CRAN (R 3.6.1) lazyeval 0.2.2 2019-03-15 [1] CRAN (R 3.6.0) libcoin 1.0-5 2019-08-27 [1] CRAN (R 3.6.0) lifecycle 0.1.0 2019-08-01 [1] CRAN (R 3.6.0) lme4 1.1-21 2019-03-05 [1] CRAN (R 3.6.0) lmtest 0.9-37 2019-04-30 [1] CRAN (R 3.6.0) logspline 2.1.15 2019-11-08 [1] CRAN (R 3.6.0) loo 2.2.0 2019-12-19 [1] CRAN (R 3.6.0) magrittr 1.5 2014-11-22 [1] CRAN (R 3.6.0) mapproj 1.2.7 2020-02-03 [1] CRAN (R 3.6.1) maps 3.3.0 2018-04-03 [1] CRAN (R 3.6.0) MASS 7.3-51.4 2019-03-31 [1] CRAN (R 3.6.1) Matrix 1.2-18 2019-11-27 [1] CRAN (R 3.6.0) MatrixModels 0.4-1 2015-08-22 [1] CRAN (R 3.6.0) matrixStats 0.55.0 2019-09-07 [1] CRAN (R 3.6.0) mc2d 0.1-18 2017-03-06 [1] CRAN (R 3.6.0) metaBMA 0.6.2 2019-09-16 [1] CRAN (R 3.6.0) metafor 2.1-0 2019-05-14 [1] CRAN (R 3.6.0) metaplus 0.7-11 2018-04-01 [1] CRAN (R 3.6.0) mgcv 1.8-28 2019-03-21 [1] CRAN (R 3.6.1) mime 0.9 2020-02-04 [1] CRAN (R 3.6.1) miniUI 0.1.1.1 2018-05-18 [1] CRAN (R 3.6.0) minqa 1.2.4 2014-10-09 [1] CRAN (R 3.6.0) mnormt 1.5-6 2020-02-03 [1] CRAN (R 3.6.1) modelr 0.1.5 2019-08-08 [1] CRAN (R 3.6.0) modeltools 0.2-22 2018-07-16 [1] CRAN (R 3.6.0) multcomp 1.4-12 2020-01-10 [1] CRAN (R 3.6.1) multcompView 0.1-8 2019-12-19 [1] CRAN (R 3.6.0) munsell 0.5.0 2018-06-12 [1] CRAN (R 3.6.0) mvtnorm 1.0-12 2020-01-09 [1] CRAN (R 3.6.1) nlme 3.1-140 2019-05-12 [1] CRAN (R 3.6.1) nloptr 1.2.1 2018-10-03 [1] CRAN (R 3.6.0) nortest 1.0-4 2015-07-30 [1] CRAN (R 3.6.0) numDeriv 2016.8-1.1 2019-06-06 [1] CRAN (R 3.6.0) oompaBase 3.2.9 2019-08-24 [1] CRAN (R 3.6.0) openxlsx 4.1.4 2019-12-06 [1] CRAN (R 3.6.0) packrat 0.5.0 2018-11-14 [1] CRAN (R 3.6.0) pairwiseComparisons 0.2.0 2020-02-02 [1] CRAN (R 3.6.0) paletteer 1.0.0 2019-12-18 [1] CRAN (R 3.6.1) palr 0.2.0 2020-01-30 [1] CRAN (R 3.6.1) pals 1.6 2019-12-04 [1] CRAN (R 3.6.0) parameters 0.4.1 2020-01-17 [1] CRAN (R 3.6.1) pbapply 1.4-2 2019-08-31 [1] CRAN (R 3.6.0) performance 0.4.3 2020-01-22 [1] CRAN (R 3.6.1) pillar 1.4.3 2019-12-20 [1] CRAN (R 3.6.0) pkgbuild 1.0.6 2019-10-09 [1] CRAN (R 3.6.0) pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 3.6.0) plyr 1.8.5 2019-12-10 [1] CRAN (R 3.6.0) png 0.1-7 2013-12-03 [1] CRAN (R 3.6.0) prettyunits 1.1.1 2020-01-24 [1] CRAN (R 3.6.1) prismatic 0.2.0 2019-12-01 [1] CRAN (R 3.6.0) processx 3.4.1 2019-07-18 [1] CRAN (R 3.6.0) promises 1.1.0 2019-10-04 [1] CRAN (R 3.6.0) ps 1.3.0 2018-12-21 [1] CRAN (R 3.6.0) psych 1.9.12.31 2020-01-08 [1] CRAN (R 3.6.1) purrr 0.3.3 2019-10-18 [1] CRAN (R 3.6.0) R6 2.4.1 2019-11-12 [1] CRAN (R 3.6.0) rcompanion 2.3.21 2020-01-09 [1] CRAN (R 3.6.1) Rcpp 1.0.3 2019-11-08 [1] CRAN (R 3.6.0) readxl 1.3.1 2019-03-13 [1] CRAN (R 3.6.0) rematch2 2.1.0 2019-07-11 [1] CRAN (R 3.6.0) repr 1.1.0 2020-01-28 [1] CRAN (R 3.6.1) reprex 0.3.0 2019-05-16 [1] CRAN (R 3.6.0) reshape 0.8.8 2018-10-23 [1] CRAN (R 3.6.0) reshape2 1.4.3 2017-12-11 [1] CRAN (R 3.6.0) rio 0.5.16 2018-11-26 [1] CRAN (R 3.6.0) rjson 0.2.20 2018-06-08 [1] CRAN (R 3.6.0) rlang 0.4.4 2020-01-28 [1] CRAN (R 3.6.1) rmarkdown 2.1 2020-01-20 [1] CRAN (R 3.6.1) rprojroot 1.3-2 2018-01-03 [1] CRAN (R 3.6.0) rstan 2.19.2 2019-07-09 [1] CRAN (R 3.6.0) rstantools 2.0.0 2019-09-15 [1] CRAN (R 3.6.0) rstudioapi 0.10 2019-03-19 [1] CRAN (R 3.6.0) sandwich 2.5-1 2019-04-06 [1] CRAN (R 3.6.0) scales 1.1.0 2019-11-18 [1] CRAN (R 3.6.1) scico 1.1.0 2018-11-20 [1] CRAN (R 3.6.0) sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 3.6.0) shiny 1.4.0 2019-10-10 [1] CRAN (R 3.6.0) sjlabelled 1.1.3 2020-01-28 [1] CRAN (R 3.6.1) sjmisc 2.8.3 2020-01-10 [1] CRAN (R 3.6.1) sjstats 0.17.8 2020-01-21 [1] CRAN (R 3.6.1) skimr 2.1 2020-02-01 [1] CRAN (R 3.6.0) StanHeaders 2.21.0-1 2020-01-19 [1] CRAN (R 3.6.1) statsExpressions 0.3.0 2020-01-29 [1] CRAN (R 3.6.1) stringi 1.4.5 2020-01-11 [1] CRAN (R 3.6.1) stringr 1.4.0 2019-02-10 [1] CRAN (R 3.6.0) survival 2.44-1.1 2019-04-01 [1] CRAN (R 3.6.1) TH.data 1.0-10 2019-01-21 [1] CRAN (R 3.6.0) tibble 2.1.3 2019-06-06 [1] CRAN (R 3.6.0) tidyr 1.0.2 2020-01-24 [1] CRAN (R 3.6.1) tidyselect 1.0.0 2020-01-27 [1] CRAN (R 3.6.1) TMB 1.7.16 2020-01-15 [1] CRAN (R 3.6.0) utf8 1.1.4 2018-05-24 [1] CRAN (R 3.6.0) vctrs 0.2.99.9005 2020-02-01 [1] Github (r-lib/vctrs@9970a0b) whisker 0.4 2019-08-28 [1] CRAN (R 3.6.0) withr 2.1.2 2018-03-15 [1] CRAN (R 3.6.0) WRS2 1.0-0 2019-06-06 [1] CRAN (R 3.6.0) xfun 0.12 2020-01-13 [1] CRAN (R 3.6.0) xml2 1.2.2 2019-08-09 [1] CRAN (R 3.6.0) xtable 1.8-4 2019-04-21 [1] CRAN (R 3.6.0) yaml 2.2.1 2020-02-01 [1] CRAN (R 3.6.1) zeallot 0.1.0 2018-01-28 [1] CRAN (R 3.6.0) zip 2.0.4 2019-09-01 [1] CRAN (R 3.6.0) zoo 1.8-7 2020-01-10 [1] CRAN (R 3.6.1) [1] /Library/Frameworks/R.framework/Versions/3.6/Resources/library ```Anything that I might be missing?