1

I wrote a function to parse the data.frame and it was throwing an error with rstatix::dunn_test which I cannot solve. This is because variable names are incorrect passed to the formula.

>selectedcolnames<-"SF36"
>group_name<-"therapy"
>dunn_test(eval(parse(text=glue("{selectedcolnames}")))~eval(parse(text=glue("{group_name}"))),data=data,p.adjust.method = "holm",detailed = F)

this give an error:

Error: Can't extract columns that don't exist.
x Column `eval(parse(text = glue("{group_name}")))` doesn't exist.

The column "SF36" with data and column "therapy" with grouping factor exist. I checked it works in:

wilcox.test(eval(parse(text=glue("{selected}")))~eval(parse(text=glue("{group_name}"))),data)

or

coin::wilcox_test(eval(parse(text=glue("{selected}")))~eval(parse(text=glue("{group_name}"))),data)

Have anyone any idea how to solve this?

VoronDM
  • 33
  • 4
  • Please trim your code to make it easier to find your problem. Follow these guidelines to create a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – Community Sep 10 '21 at 11:38

2 Answers2

1

I found another way (may be more complicated):

library(rstatix)
library(glue)

selectedcolnames <- 'Petal.Length'
group_name <- 'Species'
    
dunn_test(formula=eval(parse(text=glue("{selectedcolnames}~{group_name}"))),data=iris,p.adjust.method = "holm",detailed = F)
VoronDM
  • 33
  • 4
0

I ran this code with toy data by reformulating, it's just worked fine in that way;

library(rstatix)
library(glue)

selectedcolnames <- 'Petal.Length'
group_name <- 'Species'

frm <- reformulate(glue("{group_name}"),glue("{selectedcolnames}"))

dunn_test(frm,data=iris,p.adjust.method = "holm",detailed = F)

output;

# A tibble: 3 x 9
  .y.      group1   group2     n1    n2 statistic        p    p.adj p.adj.signif
* <chr>    <chr>    <chr>   <int> <int>     <dbl>    <dbl>    <dbl> <chr>       
1 Petal.L~ setosa   versic~    50    50      5.86 4.55e- 9 9.09e- 9 ****        
2 Petal.L~ setosa   virgin~    50    50     11.4  3.38e-30 1.02e-29 ****        
3 Petal.L~ versico~ virgin~    50    50      5.56 2.77e- 8 2.77e- 8 ****  
Samet Sökel
  • 2,515
  • 6
  • 21