Search code examples
rknitrsweavextable

Output of hints function from hints package in R


The following code has been taken from document of hints package. Last line of this code is throwing error.

library(hints)
m <- lm(BOD)
hints(m)
library(xtable)
xtable(hints(m))

The error is

Error in UseMethod("xtable") : 
  no applicable method for 'xtable' applied to an object of class "hints"

I wonder how to get hints function output to use in knitr or sweave document with xtable function.


Solution

  • It looks like xtable.hints is provided by the package but isn't properly exported so you can't actually use it. It's a fairly simple function though and the easiest solution would probably be to just copy the source and make your own function that does the exact same thing.

    xtable.hints <- function(x, align = "llll", ...){
        x <- as.data.frame(x$results[, c(2, 1, 3)])
        colnames(x) <- c("Package", "Function", "Task")
        xtable(x, align = align, ...)
    }
    
    x <- 1:10
    y <- rnorm(10)
    o <- lm(y~x)
    xtable(hints(o)) # now it works