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
> 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)
>
Hi,
this code
throws an error
which can only be avoid by setting
portable=TRUEIs 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