Summary
If you create a new object in R for which you want to use "different" subsets and assignments, you must create related methods for these operations.
. works as you expect - submitting a method
[.blob overrides the operator of the subset S3 [
[<-.bloboverrides operator S3 [<-(i.e. assignment of a vector subset)
[[<-.bloboverrides operator S3 [[<-(i.e. list assignment)
(, , , , ) "". , backticks, . A B A B <- 1, `A B` <- 1 (credit @r2evans)
[.blob , blob.
blob <- 1:5
attr(blob, "class") <- "blob"
`[.blob` <- function(x, i, j, ...) NextMethod()
, R-
blob[3]
# [1] 3
, , , 1-
`[.blob` <- function(x, i, j, ...) { i = 1; NextMethod() }
blob 1- .
blob[1]
# [1] 1
blob[2]
# [1] 1
blob[3]
# [1] 1
, [<-
`[<-.blob` <- function(x, i, j, ...) { i = 5; NextMethod() }
5- blob
blob[1] <- 100
blob
# [1] 1 2 3 4 100
# attr(,"class")
# [1] "blob"
, / .
, [
[ <- 1:5
# Error: unexpected '[' in "["
( )
`[` <- 1:5
`[`