I obtained this from an open source repo on git. This shows the writing of generic and methods for S3 classes. But I do not understand the notations or conventions that the functions are being assigned to. The following are my questions:
- The use backticks
``
to define the function name. Usually we wouldn't use backticks or even double quotes to assign variables/functions but I see this happening a lot of times. Is this a naming convention? - Why is the
.
included before the blob name? Usually wouldn't it just be called blob and a method would be method.blob? - Why are there
[
brackets there? Especially,[<-
and[[<-
. Are we performing some sort of double asigning?
Hopefully someone will be able to shed some light on what is ha
#' @export
`[.blob` <- function(x, i, ...) {
new_blob(NextMethod())
}
#' @export
`[<-.blob` <- function(x, i, ..., value) {
if (!is_raw_list(value)) {
stop("RHS must be list of raw vectors", call. = FALSE)
}
NextMethod()
}
#' @export
`[[<-.blob` <- function(x, i, ..., value) {
if (!is.raw(value) && !is.null(value)) {
stop("RHS must be raw vector or NULL", call. = FALSE)
}
if (is.null(value)) {
x[i] <- list(NULL)
x
} else {
NextMethod()
}
}