Duplicate capability of function that captures quosure when called from another function that only has access to the string version of the expression.

In the below code, I would like to use a function that reads in an argument as a quosure (i.e. testFun), but do so from another function (i.e. testFun2). In the below, how can I get the output of testFun2("attitude$rating") to be identical to the output of testfun(attitude$rating).

If possible, I prefer to only modify testFun2 and not testFun. I am having trouble finding the right tidyeval recipe to do this, so any help is very much appreciated. Thanks!!

testFun = function(data = NULL) {

    # capture data as quosure
    dataQuo = rlang::enquo(data) ##capture as quosure to get env
    dataString = ifelse(is.null(data),NA,rlang::quo_name(dataQuo))
    
    return(dataString)
}

testFun2 = function(textString) {
  z = testFun(textString)
  return(z)
}

### I want the output from testFun2 (below)
### to be identical to the output of testFun (below)
testFun(attitude$rating)
testFun2("attitude$rating")

This topic was automatically closed 21 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.