I have the following method part of a package (the code itself is not important):
#' Improved vector subsetting
#'
#' @param x a composer_vector
#' @param i standard indices used to subset
#' @param ... predicate subsetting functions applied on top off subset by indices
#' @export
#' @examples
#' vec <- co("A hello", "B hi")
#' vec[,~startsWith(.,"A")]
#' vec[1:2, ~startsWith(.,"A")]
#' vec[startsWith ="A"]
`[.composer_vector` <- function(x, i, ...) {
x <- unco(x)
if (!missing(i)) x <- x[i]
fs <- list(...)
if (length(fs)) {
fs <- harmonize_funs(fs,NULL)
x <- x[purrr::reduce(fs,~.y(x) & .x, .init = TRUE)]
}
co(x)
}
I can document, build and install the package without issue, using:
devtools::document()
pkg_path <- devtools::build()
install.packages(pkg_path, repos = NULL, type="source",clean=TRUE)
but when I attach the package, the method is not exported (not accessible with ::, though accessible with :::), and is not called when I use it on an object of the appropriate class.
If I rename it to foo all goes well and foo is exported.
I have the same issue when defining a method for [[.
If it works for data.table , why doesn't it work for me?
the full package code is on github and this code in particular is located in brackets.R