0

I want to create a function, that computes reliability estimates groupy by a factor variable. Therefore I wrote this not working function:

 notworkingfunction <- function(dat, grvar){  

   reldat <- dat%>%
     group_by_(grvar)%>%
     do_(data.frame(alpha = MBESS::ci.reliability(data.frame(dplyr::select_(., quote(-grvar))))))

   return(reldat)

 }

notworkingfunction(iris, "Species")

It seems to me, that the NSE of select_() causes the problems. Every hints are welcome!

sammerk
  • 1,143
  • 1
  • 9
  • 23

1 Answers1

2

As you had already noticed, select_ is a quirky function. To use select_ for dropping columns, you need to use the form paste("-", grvar) (See how to drop columns by passing variable name with dplyr?)

Once this is done, you don't need to use do_ anymore. You can use do as usual

newfunction  <- function(dat, grvar){  

  reldat <- dat%>%
    group_by_(grvar)%>%
    do(data.frame(alpha = MBESS::ci.reliability(data.frame(dplyr::select_(., paste("-", grvar))))))

  return(reldat)
  }
Community
  • 1
  • 1
Juan Bosco
  • 1,420
  • 5
  • 19
  • 23