Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
388 views
in Technique[技术] by (71.8m points)

r - Exporting non-S3-methods with dots in the name using roxygen2 v4

Since roxygen2 version 4.0.0, the @S3method tag has been deprecated in favour of using @export.

The package now tries to detect if a function is an S3 method, and automatically adds the line S3method(function,class) to the NAMESPACE file if it think it is one.

The problem is that if a function is not an S3 method but its name contains a . then roxygen sometimes makes a mistake and adds the line when it shouldn't.

Is there a way to tell roxygen that a function is not an S3 method?


As requested, here's a reproducible example.

I have a package that imports R.oo, with a function named check.arg.

library(roxygen2)
package.skeleton("test")
cat("Imports: R.oo
", file = "test/DESCRIPTION", append = TRUE)
writeLines(
  "#' Check an argument 
#' 
#' Checks an argument.
#' @param ... Some arguments.
#' @return A value.
#' @export
check.arg <- function(...) 0",
  "test/R/check.arg.R"
)
roxygenise("test")

Now the namespace contains the line S3method(check,arg).

check is an S3 generic in R.oo, so roxygen is trying to be smart and guessing that I want check.arg to be an S3 method. Unfortunately, these functions are unrelated, so I don't.

(To preempt suggestions that I just rename check.arg: this is legacy code written by others, and I've created a checkArg replacement, but I need to leave check.arg as a deprecated function for compatibility.)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As Mr Flick commented, appending the full function name to the roxygen line works correctly. If I change the line to:

#' @export check.arg

then the NAMESPACE file contains:

export(check.arg)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...