Skip to content

parenthesis operator overloading when portable=FALSE #295

@kalle573

Description

@kalle573

Hi,

this code

library(R6)
R6_matrix <-
  R6::R6Class(
        "R6_matrix",
        portable=FALSE,
        public=list(
          data_=matrix(0,0,0),
          data=function(){return(self$data_)},
          initialize=function(nrow,ncol,val){
            self$data_ <- matrix(val,nrow,ncol)
          },
          `[`=function(row,col){
            return(self$data_[row,col])
          },
          `[<-`=function(row,col,value){
            self$data_[row,col] <- value
            invisible(self)
          }
        )
      )
`[.R6_matrix`    <- function(obj,...) obj$`[`(...)
`[<-.R6_matrix`  <- function(obj,...) obj$`[<-`(...)
x <- R6_matrix$new(5,5,4)
x[1,1]
x[1,1] <- 2

throws an error

> x[1,1]
Error in self$data_[row, col] (from #12) : unused argument (col)
> x[1,1] <- 2
Error in `[<-`(`*tmp*`, row, col, value = 2) (from #15) : unused argument (col)
>

which can only be avoid by setting portable=TRUE

Is this a bug or an unavoidable limitation of the operator overloading in R6?

Thank you!!

ND:
OS: Linux, kernel 6.12
R: 4.4.2
R6: 2.5.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions