I would like to create an R function called "test" with a single argument "object" which can be either a data frame or a list of data frames :
- if object is a data frame, test() must return the name of the data frame as a string
- if object is a list, test() must return a vector of strings where each element is the name of the data frames.
I would like test() to work with pipes %>% and |>.
What I tried :
test <- function(object) {
return(deparse(substitute(object)))
}
# must return "iris"
iris |> test()
# must return "iris" "mtcars"
list(iris,mtcars) |> test()
Unfortunately with my test, it gives this :
> list(iris,mtcars) |> essai()
[1] "list(iris, mtcars)"