yihui / printr

Some (magical) printing methods for knitr
https://yihui.org/printr/
118 stars 24 forks source link

compatibility with microbenchmark #8

Closed ignacio82 closed 9 years ago

ignacio82 commented 9 years ago

I cannot make printr and microbenchmark work well together. For example:


---
title: "test"
author: "Ignacio"
output: html_document

---

```{r}
library(printr)
library(microbenchmark)
a1 <- a2 <- a3 <- a4 <- numeric(0)

res <- microbenchmark(a1 <- c(a1, 1),
                      a2 <- append(a2, 1),
                      a3[length(a3) + 1] <- 1,
                      a4[[length(a4) + 1]] <- 1,
                      times=100L)
tbl<-print(res)
tbl

Prints the table twice, once with good formatting and one without. If i change

tbl<-print(res) tbl


to just

print(res)



I get the table without formatting.

Thanks!
yihui commented 9 years ago

Use summary() instead, which returns a data frame without printing it:

---
title: "test"
author: "Ignacio"
output: html_document
---

```{r}
library(printr)
library(microbenchmark)
a1 <- a2 <- a3 <- a4 <- numeric(0)

res <- microbenchmark(a1 <- c(a1, 1),
                      a2 <- append(a2, 1),
                      a3[length(a3) + 1] <- 1,
                      a4[[length(a4) + 1]] <- 1,
                      times=100L)
summary(res)
ignacio82 commented 9 years ago

Thanks!