cat_line <- function(...) {
cat(..., "\n", sep = "")
}
`[.telescope`<- function(x, i) {
message("[")
cat_line("i = ", deparse1(i))
cat_line("x = ", deparse1(unclass(x)))
out <- NextMethod()
cat_line("out = ", deparse1(unclass(out)))
cat_line("[ end")
structure(out, class = "telescope")
}
`[<-.telescope`<- function(x, i, value) {
message("[<-")
cat_line("i = ", deparse1(i))
cat_line("x = ", deparse1(unclass(x)))
cat_line("`*tmp*` = ", deparse1(unclass(`*tmp*`)))
cat_line("value = ", deparse1(unclass(value)))
out <- NextMethod()
cat_line("out = ", deparse1(unclass(out)))
cat_line("[<- end")
structure(out, class = "telescope")
}
x <- structure(2:4, class = "telescope")
x[2:3][2] <- 5
## [
## i = 2:3
## x = 2:4
## out = 3:4
## [ end
## [<-
## i = 2
## x = 3:4
## `*tmp*` = 3:4
## value = 5
## out = c(3, 5)
## [<- end
## [<-
## i = 2:3
## x = 2:4
## `*tmp*` = 2:4
## value = c(3, 5)
## out = c(2, 3, 5)
## [<- end
unclass(x)
## [1] 2 3 5
x <- structure(2:4, class = "telescope")
x[3:1][2:3][2] <- 5
## [
## i = 3:1
## x = 2:4
## out = 4:2
## [ end
## [
## i = 2:3
## x = 4:2
## out = 3:2
## [ end
## [<-
## i = 2
## x = 3:2
## `*tmp*` = 3:2
## value = 5
## out = c(3, 5)
## [<- end
## [<-
## i = 2:3
## x = 4:2
## `*tmp*` = 4:2
## value = c(3, 5)
## out = c(4, 3, 5)
## [<- end
## [<-
## i = 3:1
## x = 2:4
## `*tmp*` = 2:4
## value = c(4, 3, 5)
## out = c(5, 3, 4)
## [<- end
unclass(x)
## [1] 5 3 4
x <- structure(2:4, class = "telescope")
x[3:1][3:2][2:1][2] <- 5
## [
## i = 3:1
## x = 2:4
## out = 4:2
## [ end
## [
## i = 3:2
## x = 4:2
## out = 2:3
## [ end
## [
## i = 2:1
## x = 2:3
## out = 3:2
## [ end
## [<-
## i = 2
## x = 3:2
## `*tmp*` = 3:2
## value = 5
## out = c(3, 5)
## [<- end
## [<-
## i = 2:1
## x = 2:3
## `*tmp*` = 2:3
## value = c(3, 5)
## out = c(5, 3)
## [<- end
## [<-
## i = 3:2
## x = 4:2
## `*tmp*` = 4:2
## value = c(5, 3)
## out = c(4, 3, 5)
## [<- end
## [<-
## i = 3:1
## x = 2:4
## `*tmp*` = 2:4
## value = c(4, 3, 5)
## out = c(5, 3, 4)
## [<- end
unclass(x)
## [1] 5 3 4