No applicable method for 'function'
Closed this issue · 1 comments
pedroliman commented
Hi, I'm trying to use this package, but I can't seem to make it work.
To reproduce what I'm seeing, create a new R project with a MyClass.R
file with the following:
#' R6 Class representing somethin
#'
#' A class representing a model.
MyClass <- R6::R6Class(
classname = "MyClass",
public = list(
#' @field a something
a = 1,
#' @description
#' prints
hello_world = function() {
cat("Hello!")
},
#' @description
#' summarizes
summary = function() {
cat("Summary!", self$a)
}
)
)
#' Creates a new model
#'
#' @return a new model
#' @export
#'
#' @examples
#' a <- my_class()
my_class <- function() {
MyClass$new()
}
Also create a zzz.R file:
# Exports public methods as S3 methods.
R62S3::R62S3(R6Class = MyClass, assignEnvir = topenv())
Then, try to run the following tests:
Restarting R session...
> devtools::load_all()
ℹ Loading testpackage
> a <- MyClass$new()
> a$hello_world()
Hello!
> hello_world.MyClass(a)
Hello!
> hello_world(a)
Error in UseMethod("hello_world", object) :
no applicable method for 'hello_world' applied to an object of class "c('MyClass', 'R6')"
> summary(a)
Error in object[[i]] : wrong arguments for subsetting an environment
So, it seems the generic is created, but it doesn't work.
RaphaelS1 commented
Does it work with R62Fun
? To be honest I had actually thought I had archived this repo, I'm not planning on actively maintaining it (though it has generally worked for me in the past)