Include ggplot2 function in package

I am trying to include the following helper function ggplot2 in the package [it wraps the 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: Import: ggplot2. Scripts that use this function include: library (ggplot2).

The package builds, reloads, and provides documentation at 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 mypackage namespace, but not on the command line itself?

+4
source share
1 answer

the decision in the comments should have been more specific regarding export as shown below

#' Label wrapper for ggplot
#'
#' Include in the facet_grid option of ggplot.
#' @param variable
#' @param value
#' @return wrapper
#' @export plot.label.wrap

plot.label.wrap <- function(variable, value) {

  lapply(strwrap(as.character(value), width=15, simplify=FALSE),
         paste, collapse="\n")
}

roxygen , @usage, @details @exports, , , , .

plot - S3, plot.someclass, x class "someclass" plot(x).

roxygen , someclass "label.wrap" plot.label.wrap S3, , , plot(x), class(x) - . wrap " plot.label.wrap , ( , ).

, @shadow, , , plot_label_wrap, plot_label.wrap, plot_labelwrap .. , , .

+3

All Articles