Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parenthesis operator overloading when portable=FALSE #295

Open
kalle573 opened this issue Dec 1, 2024 · 0 comments
Open

parenthesis operator overloading when portable=FALSE #295

kalle573 opened this issue Dec 1, 2024 · 0 comments

Comments

@kalle573
Copy link

kalle573 commented Dec 1, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant