문제

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