roxygen2:@noRd 标记在记录内部函数时在 @rdname 标记存在的情况下无效

roxygen2: @noRd tag has no effect in presence of the @rdname tag in documenting internal functions

我正在使用 roxygen2 包来记录我的包。 As suggested by Hadley Wickham in section 7.8,

Internal functions should be documented with #' comments as per usual. Use the @noRd tag to prevent Rd files from being generated.

通常,我在一个 R 文件中有内部函数,因此使用 @rdname 标签。然而,如果我使用@noRd 标签,它没有任何效果。

例如,如果您 roxygenize() 这个名为“iloveAnimals”的文件位于一个包中:

#' @title Cats
#' @name iloveAnimals
#'
#' @description The following logical functions check if you love animals
#'
#' @param loveCats Logical; TRUE if you love Cats
#' @details
#'  loveCats: do you love cats
#' @rdname iloveAnimals
ilovecats <- function(loveCats){
  if(loveCats){
    print("you love cats")
  } else{
      print("you hate cats")
    }
}

#' @param loveBirds logical; TRUE if you love birds.
#' @details
#'  loveBirds: Do you love birds?
#' @rdname iloveAnimals
ilovebirds  <- function(loveBirds){
  if(loveBirds){
    print("you love birds")
  } else{
    print("you hate birds")
  }
}

#' @noRd

产量,一包内,

roxygen2::roxygenize()
Writing NAMESPACE
Writing NAMESPACE
Writing iloveAnimals.Rd

这令人惊讶,因为 Rd 文件不应写入。 Rd 文件被写成好像@noRd 标签没有作用一样。如果不使用@rdname,则@noRd 标签起作用并且不写入Rd 文件。有两个简单的解决方案:

  1. 注释掉内部函数或
  2. 每个文件有一个内部函数以避免使用@rdname 标签。

然而,这些解决方案违背了roxygen2的精神。

roxygen2github页面来回答这个问题。谢谢,@gaborcsardi。

https://github.com/r-lib/roxygen2/issues/1141#issuecomment-660612297