Qaswed
Qaswed

Reputation: 3879

How to export functions starting not whith a letter using roxygen?

I have a follow up question on this question. Suppose I want an own + function for my class expo. On my normal R session the following works perfectly

'+.expo' <- function(a, b) a ^ b
r <- 2; class(r) <- "expo"
s <- 3; class(s) <- "expo"
r + s # gives 8

But running devtools::document() gives me the Skipping invalid path: .expo.Rd message. If I understand this question correctly, '+.expo' is an invalid name for a function as each function has to start with a (small or capital) letter. Now I wonder how can ggplot2 provide a function '+.gg'? And more importantly: how can my package provide a class-specific + functions?

Upvotes: 2

Views: 71

Answers (1)

Qaswed
Qaswed

Reputation: 3879

R allows functions to start with something else then a letter, but roxygen per default does not. But you can use the argument @rdname to give such functions an alternative name used in the documentation. So, your .R-file might look like

#' @param a first object
#' @param b second object
#' @return exponential result
#' @export
#' @rdname expo-add
'+.expo' <- function(a, b) a ^ b

The .R-File to the mentioned ggplot2 function '+.gg' can be found here.

Upvotes: 2

Related Questions