r-lib / roxygen2

Generate R package documentation from inline R comments
https://roxygen2.r-lib.org
Other
590 stars 232 forks source link

Alias collision when documenting package which contains a function with the same name. #1160

Closed brendanf closed 9 months ago

brendanf commented 3 years ago

There seems to have been a reversion sometime since this Stack Exchange answer was given; now when I make a new package hello using

hello/R/hello.R:

#' hello
#'
#' This is a mostly empty package to learn roxygen documentation.
#'
#' Hello allows me to learn how to write documentation in comment blocks
#' co-located with code.
"_PACKAGE"

#' hello
#'
#' This function returns "Hello, world!".
#' @export
#' @examples
#' hello()

hello <- function() {
  print("Hello, world!")
}

and hello/DESCRIPTION:

Package: hello
Type: Package
Title: A mostly empty package
Version: 0.1
Date: 2016-06-21
Authors@R: person("Some", "Person", email = "fake@madeup.org", role = c("aut", "cre"))
Description: More about what it does (maybe more than one line)
License: MIT
LazyData: TRUE
RoxygenNote: 7.1.0

and then build documentation, I get the following hello/man/hello-package.Rd:

% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/hello.R
\docType{package}
\name{hello-package}
\alias{hello}
\alias{hello-package}
\title{hello}
\description{
This is a mostly empty package to learn roxygen documentation.
}
\details{
Hello allows me to learn how to write documentation in comment blocks
co-located with code.
}
\author{
\strong{Maintainer}: Some Person \email{fake@madeup.org}

}

The \alias{hello} line conflicts with documentation for hello(), resulting in the R CMD check warning Rd files with duplicated alias 'hello': ‘hello-package.Rd’ ‘hello.Rd’

hadley commented 3 years ago

Use @aliases hello-package to override

maelle commented 3 years ago

Came here via https://github.com/r-lib/pkgdown/issues/1414

maelle commented 3 years ago

So should the fix be documentation of the tip above or something else?

hadley commented 3 years ago

I think it should be fixed in roxygen2.

ellessenne commented 3 years ago

Hi all, I also just experienced the same issue and solved it by following David's comment here: https://github.com/tidymodels/hardhat/issues/130#issuecomment-622438758

hadley commented 9 months ago

Fixing this is going to require some thought, because we currently add the default aliases in object_defaults.package, where the full set of aliases used by the package isn't know.

I think we'd need to add something to roclet_process.roclet_rd that gets all aliases across topics, and then adds aliases to the package doc if they're otherwise missing.