Question

I have a generic print function that I think I've set up correctly based on Generic functions (LINK, admittedly a bit hard for me to grasp) and this question(LINK). However, it still throws up a warning in the check. Below is a mock function, print method, roxygen documentation and the error from the check. For background on what the print function is doing; basically I want the output to not look like it is classes but it still carries a class for handling of that object by subsequent functions. How can I make the warning go away (and keep the print function)?

FUN <- function(x) {
    class(x) <- "full_matrix"
    x
}

#' Prints a fuul_matrix object
#' 
#' prints a test object
#' 
#' @param full_matrix The full_matrix object
#' @method print full_matrix
#' @S3method print full_matrix
print.full_matrix <- function(full_matrix) {
    x <- full_matrix
    class(x) <- NULL
    print(x)
}

x <- FUN(mtcars)
x
class(x)

Warning:

* checking S3 generic/method consistency ... WARNING
print:
  function(x, ...)
print.full_matrix:
  function(full_matrix)

print:
  function(x, ...)
print.incomplete_matrix:
  function(incomplete_matrix)

See section 'Generic functions and methods' of the 'Writing R
Extensions' manual.
Was it helpful?

Solution

From Writing R Extensions

A method must have all the arguments of the generic, including ... if the generic does.

Your method has neither x nor ...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top