'Is there a way to return the name of a piped dataframe

I have a function that takes a data frame as input. I would like to create a column containing the name of the data frame. Like in the following example:

the_df <- tibble(a=c(1,2,3),
                 b=c(1,2,3))

func <- function(df){
  df <- df %>% mutate(dataframe = "name_of_df")
  return(df)
}

func(the_df)

Is this doable?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source