I wish to create a user function in R which merges multiple tables that uses regular expression to find these tables. In my situation, I want to merge all the tables in my environment starting with "m_".
This produces exactly what I want:
Reduce(function(...) merge(..., all = TRUE), mget(apropos("^m_")))
But it doesn't work when I attempt to transform this code into a user function:
multi.merge <- function(...){
x <- Reduce(function(...) merge(..., all = TRUE), mget(apropos(...))
return(x)
}
dt <- multi.merge("^m_")
Error: value for ‘m_table1’ not found
I have tried using different functions such as get0
or syms
, and different syntax just ends up with the same error. I suspect it's just something to do with a problem in the structure of the function that I don't understand.
Is there any way to make this work?