简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM