How do you identify the class of variable in a quasiquotation context?

Hi All,

I was wondering if it was possible to identify what the class of a variable is within a quasiquotation context.

At present, the only way I can think to do this is to pull it into a vector, and then identify it. But this seems a bit messy and long-winded.

Maybe there is a function in rlang to do this??

Thanks!

library(tidyverse)

what_class <- function(data, x_var) {
  x_var <- rlang::enquo(x_var) 

# function to identify the class of x_var here
} 

what_class(iris, Species)

Hi, this is how I would do that:

library(tidyverse)

what_class <- function(data, x_var) {
  extracted_xvar <- pull(data, {{x_var}})
  class(extracted_xvar)
} 

what_class(iris, Species)
#> [1] "factor"
2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.