I have two functions that start pretty similarly. Hence I wonder if this is the right moment to dive into inheritance in R.
firstfunc <- function(table,pattern="^Variable") {
dframe <- get(table)
cn <- colnames(get(table))
qs <- subset(cn, cn %in% grep(pattern, cn, value=TRUE))
.....
}
secondfunc <- function(table,pattern="^stat"){
dframe <- get(table)
cn <- colnames(get(table))
qs <- subset(cn, cn %in% grep(pattern, cn, value=TRUE))
....
}
There will be more than two functions and two patterns. My tables contains a lot of variables, which can be easily grouped by their names, which is why I use these pattern identification. It works well so far and c&p these few lines is not that much of an effort. However, is it reasonable to write these lines into one function / method and let the others inherit?
Most help I read on OO in R so far used examples that assigned attributes to data and then used generic functions. Unfortunately I did not understand yet if this can help my case too.
Thx for any suggestions, pointers to a good head first start into this!