R package development - function aliases
I found this answer because also ran into the problem where foo <- bar <- function(x)...
would fail to export bar
because I was using royxgen2
. I went straight to the royxgen2
source code and found their approach:
#' Title
#'
#' @param x
#'
#' @return
#' @export
#'
#' @examples
#' foo("hello")
foo <- function(x) {
print(x)
}
#' @rdname foo
#' @examples bar("hello")
#' @export
bar <- foo
This will automatically do three things:
- Add
bar
as an alias offoo
(so no need to use@alias
tag). - Add
bar
to the Usage section of?foo
(so no need to add@usage
tag). - If you provide
@examples
(note the plural) for the alias, it will add the examples to?foo
.
You could just define bar
when you define foo
.
foo <- bar <- function(x, y, z) {
# function body goes here
}