if (FALSE) {
# implementing a new field called "first_letter" that is consistently derived
# across all pkg_ref objects:
pkg_ref_cache.first_letter <- function(x, name, ...) {
substring(x$name, 1, 1)
}
x <- pkg_ref("riskmetric")
x$first_letter
# implementing a new field called "subclass_enum" that dispatches on
# the subclass of the pkg_ref object:
pkg_ref_cache.subclass_enum <- function(x, name, ...) {
UseMethod("pkg_ref_cache.subclass_enum")
}
pkg_ref_cache.subclass_enum.pkg_ref <- function(x, name, ...) {
0
}
pkg_ref_cache.subclass_enum.pkg_install <- function(x, name, ...) {
1
}
x$subclass_enum
}
Run the code above in your browser using DataLab