I am trying to include the following ggplot2 helper function in a package [it wraps labels in grid_facet(.~variable, labeller = "plot.label.wrap")]:
#' Label wrapper for ggplot
#'
#' Include in the facet_grid option of ggplot.
#' @param variable
#' @param value
#' @return wrapper
#' @export
plot.label.wrap <- function(variable, value) {
lapply(strwrap(as.character(value), width=15, simplify=FALSE),
paste, collapse="\n")
}
My DESCRIPTION file includes: Imports: ggplot2. The scripts that uses the function includes: library(ggplot2).
The package builds, reloads and gives the documentation upon ?plot.label.wrap. It can be found:
> getAnywhere(plot.label.wrap)
A single object matching ‘plot.label.wrap’ was found
It was found in the following places
registered S3 method for plot from namespace mypackage
namespace:mypackage
with value
function(variable, value) {
lapply(strwrap(as.character(value), width=15, simplify=FALSE),
paste, collapse="\n")
}
<environment: namespace:mypackage>
However:
> plot.label.wrap
Error: object 'plot.label.wrap' not found
So my question is, why is this function found in the namespace of mypackage but not on the command line itself?
#' @export plot.label.wrap- rawrplotmethod forlabel.wrapobjects. Just rename the function to e.g.plot_label_wrapand it should work. - shadow