How does Roxygen handle infix binary operators (e.g.% to%)?

As a simple, concrete example:

#' Inverse Value Matching #' #' Complement of \code{%in%}. Returns the elements of \code{x} that are #' not in \code{y}. #' @usage x %nin% y #' @param xa vector #' @param ya vector #' @export "%nin%" <- function(x, y) { return( !(x %in% y) ) } 

However, when I try to create a package, the function seems to be ignored and no documentation is created.

There seems to be a one-line ad unit about infix binary functions at http://cran.r-project.org/doc/manuals/r-release/R-exts.html#Documenting-functions , but it's hard for me to parse it, and what is it will mean for Roxygen documentation.

+4
source share
2 answers

You need to avoid % in the usage section. Also, I think you might need to specify rdname

 #' Inverse Value Matching #' #' Complement of \code{%in%}. Returns the elements of \code{x} that are #' not in \code{y}. #' @usage x \%nin\% y #' @param xa vector #' @param ya vector #' @export #' @rdname nin "%nin%" <- function(x, y) { return( !(x %in% y) ) } 

Here is the function that I have in my personal package. I don’t think I have ever used this function, but roxygenize creates a help file and the package passes the R CMD check .

 #' percent in #' #' calculate the percentage of elements of \code{table} that are in \code{x} #' #' @param x vector or NULL: the values to be matched #' @param table vector or NULL: the values to be matched against #' @return percentage of elements of \code{x} that are in \code{table} #' @author gsee #' @usage x \%pctin\% table #' @examples #' letters[1:10] %pctin% letters[1:3] # 30% of the second arg ar in the first #' @export #' @rdname PctIn "%pctin%" <- function(x, table) length(x[x %in% table])/length(x) 
+6
source

It was difficult for roxygen with roxygen (speaking about roxygen not roxygen2 ) and infix operations. This is what worked with my setup ( R 2.15.1, roxygen 0.1-3).

First solution: edit the Rd file of each infix operator (it should be grapes ... grapes.Rd ) and exit with baskslash each % in the parts \alias , \usage and \name .

Second solution: specify the tags @name and @usage in the documentation of the infix operator and exit % . Here is an example:

 ##' Concatenates two strings ##' ##' @name \%+\% ##' @usage \%+\%(x, y) ##' @title Concatenation operator. ##' @param a String. ##' @param b String. ##' @return Same as paste0(a, b). "%+%" <- function(a, b) paste(a, b, sep = "") 
+1
source

All Articles