I have the following function where there is only one parameter, df. df is dataframe:
test_function <- function(df) {
df_name <- df #get name of dataframe (does not work)
df_name
}
test_function(mtcars)
How do I return name of the dataset from this function? For test_function(mtcars) I need to assign string mtcars to df_name.
You can use the combo substitute + deparse
test_function <- function(df)
deparse(substitute(df))
test_function(mtcars)
##[1] "mtcars"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With