I am creating an RC class and while trying to print(.self$something)
within a class method I am getting:
Error in print(.self$something) : unused argument (.self$something)
I am sort of new to R, so am I missing something here? This is for an assignment which asks us to use RC classes, using R6 is not an option.
myclass <- setRefClass("myclass",
fields = list (
formula = "formula",
data = "data.frame",
something = "numeric"
),
methods = list (
initialize = function(formula, data) {
...
},
print = function() {
...
print(.self$something)
},
)
)
a <- myclass$new(formula,data)
a$print()
> Error in print(.self$something) : unused argument (.self$something)
Edit: Extra info, if I try a$something
I get what I should get.
As @Mohammed mentions, this happened because I was in printing within my own print environment. Though cat()
could be an option, later I faced other issues in which cat did not print the object (that could be a thread on its own so I will not go deeper on that here).
What I ended up doing was calling the print function for that specific data type. For instance, if something
was a data.frame
I called print.data.frame(.self$something)
and worked as expected.