Menu
  • HOME
  • TAGS

Making subclass of list

r,r-s3

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...

Variable scope in S3 generics

r,scope,r-s3

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...

How to use S3 methods from another package which uses export rather than S3method in its namespace without using Depends or library()

r,package,r-package,r-s3

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...

How do I re-register S3 method inside R package?

r,namespaces,r-s3

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!" ...

Proper way to implement S3 dispatch on R6 classes

r,r-s3,r6

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.

Get list of datatypes with S3 generic function

r,generics,types,r-s3

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...