The problem is that the generic [ method is stripping off the class attribute. To avoid this, you could just define your own generic for mysubclass, i.e. ## Answer suggested by Petr Matousu ## Based on simple.list method '[.mysubclass' = function(x, i, ...) { structure(NextMethod("["), class = class(x)) } Or...
The description of this behavior can be found in the ?UseMethod help page UseMethod creates a new function call with arguments matched as they came in to the generic. Any local variables defined before the call to UseMethod are retained Thus any local variables defined in the function calling UseMethod...
The key here is to import the specific methods in addition to the generic you want to use. Here is how you can get it to work for the default method. Note: this assumes that the test.h5 file already exists. #' @importFrom rhdf5 h5write.default #' @importFrom rhdf5 h5write #' @export...
Have you tried assignInNamespace()? printAOV <- function(x, ...) print("replaced function!") assignInNamespace("print.aov", printAOV, ns = asNamespace("stats")) print(aov(yield ~ block + N * P + K, npk)) # [1] "replaced function!" ...
I asked Winston Chang, the author of R6, about this on Github. According to him, the code provided in Question 1 above is the correct way of writing S3 methods for R6 classes.
The first argument of apply must be a matrix-like object (i.e., a matrix, array or data.frame). Otherwise you get this error: apply(1, 1, mean) #Error in apply(1, 1, mean) : dim(X) must have a positive length You are passing a list to apply, which can't work because you tell apply...