Description of argument descriptions in the .Rd file when using the roxygen2 @inheritParams tag

Say I am writing a small R package, including two functions with exaccty same arguments except one. Here is an example:

fct1 <- function(r, K){...} fct2 <- function(r, p, K){...} 

In my documentation on the first roxygen2 function, I use the following tags:

 #' @param r description of argument r #' @param K description of argument K 

For the second function, I use the following tags:

 #' @param p description of argument p #' @inheritParams fct1 

After processing my code with roxygenize, the .Rd file for the fct2 function presents the arguments in the following order: p, r, K. I would like them to be in the same order as in the usage section, that is: r, p , K. How can I get this order without manually modifying the .Rd file?

I insist on using @inheritParams to avoid copying and pasting.

Thanks!

+6
source share
1 answer

I have the same problem. Right now I'm using a little trick to avoid the wrong order of arguments.

Use code (for example, in a separate .R file):

 #' Function arguments #' #' @keywords integral #' #' @name fargs #' #' @param r .. #' @param p .. #' @param K .. #' #' NULL 

and use

 #' @inheritParams fargs 

for both functions.

In this case, it was easy, but in more complex examples, U can use many blocks of this code (a separate block for each type of argument). It may not be that simple, but you are not repeating the same code anywhere. I store this block in a separate args.R file, so each inherit argument is in a single file.

Another way is to use templates, but this method is not flexible, and for each block you must create a separate .R file. Therefore, I advise you to use simmilary blocks of code.

+2
source

Source: https://habr.com/ru/post/902577/


All Articles