Reputation: 28274
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.$
operator works for functions and lists of functions, but not for methods in RC, just for field namesSo 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?
Upvotes: 2
Views: 119
Reputation: 28274
I have found part of an answer to my own question: the lme4
packages uses quite some RC classes and also documents them using .Rd
Upvotes: 1