avalencia
avalencia

Reputation: 63

unused argument error when printing from RC class method

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.

Upvotes: 0

Views: 273

Answers (2)

avalencia
avalencia

Reputation: 63

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.

Upvotes: 0

Mohammed
Mohammed

Reputation: 311

Try to use cat in your print function, you are now in your local print function environment and trying to call your system "print" function. I suggest you use cat as follows:

cat(.self$something)

It will do the job

Upvotes: 0

Related Questions