I'm creating a package which will contain a new ggplot2 Statistic.
I'm using the ggplot2::ggproto
to create the new Statistic, but I'm having problems with the documentation with roxygen2. After running devtools::document()
, I got:
mypackagename-ggproto.Rd is missing name/title. Skipping
I tried to follow other packages' examples (such as here, here, and here) but I got the same problem. As a minimal reproducible example, I provide the following content of my stat-test.R file:
#' @title My Statistic
#'
#' @description blah blah
#'
#' @param ... other arguments.
#' @param na.rm a logical value indicating ...
#'
#' @export
#'
stat_test <- function(mapping = NULL, data = NULL, geom = "segment",
position = "identity", na.rm = FALSE,
linetype="dotted", show.legend = NA,
inherit.aes = TRUE, ...) {
ggplot2::layer(
stat = StatTEST,
data = data,
mapping = mapping,
geom = geom,
position = position,
show.legend = show.legend,
inherit.aes = inherit.aes,
params = list(na.rm = na.rm, linetype = linetype, ...)
)
}
#' @rdname mypackagename-ggproto
#' @format NULL
#' @usage NULL
#' @export
StatTEST <- ggplot2::ggproto("StatTEST", ggplot2::Stat,
compute_group = function(data, scales, ...) {
## Compute the line segment endpoints
data[nrow(data), c("from", "to")] <-
c(
data[1, "from"], data[1, "to"]
)
x = data[data$from, 1]
y = data[data$from, 2]
xend = data[data$to, 1]
yend = data[data$to, 2]
data.frame(x=x, y=y, xend=xend, yend=yend)
},
required_aes = c("x", "y", "from", "to")
)
I read the roxygen2 Generating Rd Files vignette as well, but I couldn't find a solution. I can't figure out why #' @rdname mypackagename-ggproto
is not producing my mypackagename-ggproto.Rd
file.
I would appreciate any help.
Seesion Info:
R version 3.5.1 (2018-07-02)
Platform: x86_64-suse-linux-gnu (64-bit)
Running under: openSUSE Leap 15.0
Matrix products: default
BLAS: /usr/lib64/R/lib/libRblas.so
LAPACK: /usr/lib64/R/lib/libRlapack.so
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
LC_MONETARY=en_US.UTF-8
[6] LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8 LC_NAME=C
LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] emstreeR_1.0
loaded via a namespace (and not attached):
[1] Rcpp_0.12.18 pillar_1.3.0 compiler_3.5.1
plyr_1.8.4 bindr_0.1.1 tools_3.5.1
digest_0.6.15
[8] memoise_1.1.0 tibble_1.4.2 gtable_0.2.0
pkgconfig_2.0.1 rlang_0.2.1 rstudioapi_0.7
commonmark_1.5
[15] yaml_2.2.0 bindrcpp_0.2.2 withr_2.1.2
dplyr_0.7.6 stringr_1.3.1 roxygen2_6.1.0 xml2_1.2.0
[22] desc_1.2.0 devtools_1.13.6 rprojroot_1.3-2
grid_3.5.1 tidyselect_0.2.4 scatterplot3d_0.3-41 glue_1.3.0
[29] R6_2.2.2 ggplot2_3.0.0 purrr_0.2.5
magrittr_1.5 backports_1.1.2 scales_0.5.0
assertthat_0.2.0
[36] colorspace_1.3-2 stringi_1.2.4 lazyeval_0.2.1
munsell_0.5.0 crayon_1.3.4
The @rdname
tag associates a function's documentation with a doc file that already exists, but cannot be used to create a new one. If you look at the Generating Rd Files Vignette you'll see that they always use @rdname
to link a function's documentation to an existing file:
In the below example, the add
function is documented normally. By using @rdname add
, the times
function will be documented in the same file as add
#' Basic arithmetic
#'
#' @param x,y numeric vectors.
add <- function(x, y) x + y
#' @rdname add
times <- function(x, y) x * y
If you don't want to build a documentation file around a single function, you still need to create the file before using @rdname
to associate functions with it. You can do this by creating and documenting a dummy function using the @name
tag. Then you can use @rdname
to document functions in that same dummy file:
#' Basic arithmetic
#'
#' @param x,y numeric vectors.
#' @name arith
NULL
#' @rdname arith
add <- function(x, y) x + y
#' @rdname arith
times <- function(x, y) x * y