R CMD Test non-S3 methods with dots in the name, where the part of the name to the point matches the common in utils

This question is related to the export of non-S3 methods with dots in the name using roxygen2 v4 . From this post, I learned what to use @export function.nameto correctly record NAMESPACE using roxygen. I did this and NAMESPACE is spelled correctly.

My problem arises when I do R CMD Check. I have legacy code with a function tail.g(). R CMD Check throws a NOTE, noting that the visible S3 method has been exported but not registered.

The following is a reproducible example. Note that it xxxx.gdoes NOT have a NOTE, which makes me think that since it tailis common in the utils package, I need a special job. I would prefer not to rename tail.g to tail_g, because it's legacy code. I want to exclude all notes for successful submission of CRAN.

library(roxygen2)
package.skeleton("test")
writeLines(
  "#' Check an argument 
  #' 
  #' Checks an argument.
  #' @param ... Some arguments.
  #' @return A value.
  #' @export tail.g
  tail.g <- function(...) 0",
  "test/R/tail.g.R"
)
writeLines(
  "#' Check an argument 
  #' 
  #' Checks an argument.
  #' @param ... Some arguments.
  #' @return A value.
  #' @export xxxx.g
  xxxx.g <- function(...) 0",
  "test/R/xxxx.g.R"
)
roxygenise("test")
setwd("./test")
devtools::check(document=FALSE)

Gives NOTE:

checking S3 generic/method consistency ... NOTE
Found the following apparent S3 methods exported but not registered:
  tail.g

How to delete a note for tail.g () without renaming?

+4
source share
1 answer

This is a dirty hack, but it works: just register functions as methods, in addition to exporting .

So yours NAMESPACEcan have two lines:

export(tail.g)
S3method(tail, g)

, , CRAN. , , - , methods(class="g") methods("tail"). .

roxygen2 @rawNamespace, NAMESPACE S3method:

writeLines(
  "#' Check an argument 
  #' 
  #' Checks an argument.
  #' @param ... Some arguments.
  #' @return A value.
  #' @export tail.g
  #' @rawNamespace S3method(tail, g)
  tail.g <- function(...) 0",
  "test/R/tail.g.R"
)
+1

Source: https://habr.com/ru/post/1663268/


All Articles