Reference classes definitions can pile up quite some lines of code in R. When methods are defined inside a reference class a couple of methods plus the field definitions gives you a quite confusing class definition – at least it's hard to read at 300+ lines. And I have other issues:
roxygen2
documentation does not really work as out-of-the-box as for functions.- auto-suggest using the
$
operator works for functions and lists of functions, but not for methods in RC, just for field names - I don't know you I could possible split method definitions to several files. All code of my package resides in 2 or 3 files that contain the classes defintions
So speaking in code, why should I not do something like this?
someDummy <- setRefClass("someDummy", fields = list(df = "matrix",
multiplier = "numeric"))
test <- someDummy()
thingsYouCanDo <- function(){
rc <- NULL
mtrx <- NULL
multi <- NULL
populate <- function(rc,mtrx,multi){
rc$df <- mtrx
rc$multiplier <- multi
}
multiply <- function(rc){
out <- rc$df * rc$multiplier
out
}
return(list(populate = populate,
multiply = multiply))
}
te <- thingsYouCanDo()
te$populate(test,matrix(1:12,4,3),5)
test
te$multiply(test)
Are there any well written packages on CRAN that make use of RC and are documented well? Speaking of documentation, I do not mean a neat website, but .Rd based documentation. What I have seen a lot lately in other people's source code is function that contain function or list of functions. Should I rather use that?