Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG(?): Function with class attribute set becomes \keyword{datasets} Rd document #455

Closed
HenrikBengtsson opened this issue Feb 23, 2016 · 0 comments

Comments

@HenrikBengtsson
Copy link
Contributor

@HenrikBengtsson HenrikBengtsson commented Feb 23, 2016

Problem

I'm trying to add a class attribute to a function, but when I do, roxygen2 5.0.1 gets confused and documents it as an R object. For example:

#' Foo function
#'
#' @export
foo <- function() TRUE
class(foo) <- "foo"

generates

% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/foo.R
\docType{data}
\name{foo}
\alias{foo}
\title{Foo function}
\format{An object of class \code{foo} of length 1.}
\usage{
foo
}
\description{
Foo function
}
\keyword{datasets}

Workaround

By making sure the class attribute also contains "function", it seems to work, e.g.

#' Foo function
#'
#' @export
foo <- function() TRUE
class(foo) <- c("foo", "function")

becomes

% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/foo.R
\name{foo}
\alias{foo}
\title{Foo function}
\usage{
foo()
}
\description{
Foo function
}

Troubleshooting

Could it be that roxygen2 identifies functions using inherits(x, "function") rather than is.function(x)? For example:

> foo <- function() TRUE; class(foo) <- "foo"
> inherits(foo, "function")
[1] FALSE
> is.function(foo)
[1] TRUE
@hadley hadley closed this in f18b396 Aug 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant