Inherit Roxygen2 documentation for multiple arguments in R package
Asked Answered
C

2

10

I'm writing an R package and want to inherit the documentation for two arguments (say x and y) from an old function (say old()) to a new function, new(). The twist is that these two arguments share the same argument description. That is, in old(), function, they were documented in a single line and separated by commas like this:

#' @param x,y Two arguments with the same description

I used the following for new() to inherit these arguments:

#' @inheritParams old

However, when I build the package, the documentation for new() lists x but not y.

Is there a way to inherit multiple arguments like these?

Cautionary answered 29/9, 2016 at 5:55 Comment(0)
C
11

In case anyone else stumbles across this, the answer is that you cannot do this.

This comes from the roxygen2 creator, Hadley Wickham.

Cautionary answered 13/3, 2017 at 2:27 Comment(1)
Hadley himself has done this in dplyr::slice_*(). The documentation has n, prop listed together with the same argument.Wesla
D
5

It seems that in version 6.1.1 you can with the only drawback that the two variables in new() will have the same description but will be listed separately. I tried to write a reproducible example just in case.

# roxygen 6.1.1, devtools 2.0.1, usethis 1.4.0
# Select a project folder and do setwd(<project_folder>)
usethis::create_package("inheritanceTest")
setwd("./inheritanceTest")

t = "
#' Hello
#'
#' @param x,y some stuff
#'
#' @return other stuff
#' @export
test_inherit_parent = function(x,y){
  print('Hello')
}

#' Hello2
#'
#' @inheritParams test_inherit_parent
#'
#' @return other stuff2
#' @export
test_inherit_child = function(x,y){
  print('Hello2')
}
"
fileConn = file("./R/functions.R")
writeLines(t, fileConn)
close(fileConn)
devtools::document()
devtools::load_all(".")
?test_inherit_parent
?test_inherit_child
Doublepark answered 28/3, 2019 at 15:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.