Re: [R] unwanted as.integer

From: Sundar Dorai-Raj <sundar.dorai-raj_at_pdf.com>
Date: Fri 30 Jul 2004 - 08:06:41 EST

Jack Tanner wrote:
> > a <- sqlQuery(irrdb, "select count(field) from mytable where field = 1")
> > print(a)
> count(field)
> 1 8
> > paste(a)
> [1] "as.integer(8)"
>
> Why the as.integer() representation? I later pass the result into this
> write.html.table(), and what I get is rows of as.integer()... when all I
> want is the integer itself.
>
> as.integer(31) as.integer(21) as.integer(34) as.integer(86)
> as.integer(7) as.integer(6) as.integer(15) as.integer(28)
>
>
> write.html.table <- function(t, file= "", capt= "The Default Title",
> append = FALSE) {
> head <- paste("<table>\n<caption>", capt, "</caption>\n")
> cat(head, file= file, append= append)
> if (is.null(rownames(t))) {
> rownames(t) <- rep("", nrow(t))
> }
> tp <- rbind(c("<tr><td></td>", colnames(t)),
> cbind(unlist(lapply(rownames(t), function(x) {
> paste("<tr><td>", x)})), t))
> write.table(tp, sep= "<td>", file= file, , eol= "</tr>\n",
> row.names=FALSE,
> col.names=FALSE,
> append=TRUE, quote=FALSE)
> cat("</tr>\n</table>\n", file= file, append= TRUE)
> }
>

Not sure about what sqlQuery is doing but you can wrap your return value in a eval(parse(text = x)) to evaluate the "as.integer(.)" string. As in,

a <- eval(parse(text = a))

HTH,
--sundar



R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Fri Jul 30 08:12:24 2004

This archive was generated by hypermail 2.1.8 : Fri 18 Mar 2005 - 02:41:20 EST