简体   繁体   中英

Inherit Roxygen2 documentation for multiple arguments in R package

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?

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

This comes from the roxygen2 creator, Hadley Wickham.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM