Вопрос

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.

Это было полезно?

Решение

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
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top