Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

creating a binary operator function within a package

Tags:

r

i'm trying to add a binary operator function to a package of mine, but it is not loading with the package. for example, i define this function and save it as a file named 'wo.R'

`%wo%` <- function(x, y) {
    x[!x %in% y]
}

and create the documentation file 'wo.Rd'

\name{\%wo\%}
\alias{\%wo\%}
\title{Without}
\description{Elements in one vector without matching elements in a second vector.}
\usage{x \%wo\% y}
\arguments{
  \item{x}{A vector.}
  \item{y}{A vector.}
}
\value{A vector.}
\author{me, based on example in the \code{\link{match}} function documentation.}
\examples{
(1:10) \%wo\% c(3,7,12)
}

when i run R CMD check myPackage it gives this error when checking the documentation example: Error: could not find function "%wo%" Execution halted. i can remove the example, and install my package successfully, but the %wo% function isn't loading with my package. i can source the 'wo.R' file in an R session and it works. i can also define the function as wo <- function(x, y) x[!x %in% y] and that seems to work fine. i poked around the source code for other packages, such as 'operators', and my source and documentation files seem consistent with them, but i'm obviously overlooking something.

like image 673
pistachionut Avatar asked Feb 10 '12 09:02

pistachionut


1 Answers

You need to export the function in your NAMESPACE.

Add an export statement to your documentation file:

export("%wo%")
like image 89
Andrie Avatar answered Oct 23 '22 23:10

Andrie