retrieve character name of function argument

I feel like this should be simple, but I can't figure it out.

I want to be able to pass an object to a function, use the object for some operations, and get the named value of the object to name output with glue strings.

Something like

get_name <- function(df){
  
  # some expression here....
  df_name <- 
  return(df_name)

  }

get_name(faithful) should return "faithful"

I'm guessing this isn't strictly under the tidyeval scope, I just don't have the vocabulary to describe it otherwise!

get_name <- function(df) {

  # some expression here....
  df_name <- rlang::as_label(rlang::ensym(df))
  return(df_name)
}


get_name(faithful)
#> [1] "faithful"

Created on 2021-04-11 by the reprex package (v2.0.0)

1 Like

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.