Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Arguments descriptions order in .Rd file when using the roxygen2 tag @inheritParams

Tags:

r

roxygen2

Let's say I am writing a small R package including two functions with exaclty the same arguments except one. Here is an example:

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

In my roxygen2 documentation of the first 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 function fct2 presents the arguments in the following order: p, r, K. I would like them to be in the same order than in the usage section, that is: r, p, K. How can I get this order without manually changing the .Rd file?

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

Thanks!

like image 972
user1069707 Avatar asked Nov 28 '11 16:11

user1069707


1 Answers

I have the same problem. For now I use little trick to avoid wrong arguments order.

Use code (e.g. in seperate .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 complicated examples U can use many blocks of this code (separate block for every type of arguments). Maybe it is not so simple way but you do not repeat the same code anywhere. I store that block in seperate args.R file so every inherit arguments is in one file.

Another way is using templates but this method is not flexible and for every block you must create separate .R file. So I advice u to use simmilary blocks of code.

like image 182
michu Avatar answered Nov 15 '22 08:11

michu