I retrieve all dataframes from environment and then do some stuff:
dfs <- Filter(function(x) is(x, "data.frame"), mget(ls()))
names(dfs)
"customers"
"sales"
"campaigns"
First thing I need to extract is object name inside a loop:
for (df in dfs) {
df_name <- deparse(substitute(df))
# do some stuff
# do some more stuff
print(df_name)
}
But instead data frame names to operate I get:
"df"
"df"
"df"
I've tested a function inside the loop too:
find_name <- function(df) {
df_name_is <- substitute(df)
return(df_name_is)
}
But the output is:
df
df
df
looping through names of df gets me the colnames of every df, not the df name itself.
any hint will be much appreciated
print(df)returns the complete content for every df but I just need the name