-
Notifications
You must be signed in to change notification settings - Fork 238
Closed
Description
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] TRUEMetadata
Metadata
Assignees
Labels
No labels