Rmd notebook fails to show table with `difftime` column and zero rows

56 Views Asked by At

I've discovered that Rmd yields an error when you try to print table with zero rows and column with difftime class. Here's an example of Rmd file:
(I've inserted backslash in end of the chunks so it would be one code block, so delete them locally, please)

---
title: "R Notebook"
output: html_notebook
---

```{r}
library(dplyr)
\```

```{r}
foo <- tibble(
    time_1 = as.Date("2020-04-28"),
    time_2 = as.Date("2020-04-27")
) %>%
    mutate(time_diff = time_1 - time_2)
\```

```{r}
foo
\```


```{r}
foo %>% slice(0)
# Error:
# Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE,  : 
# arguments imply differing number of rows: 0, 1
\```

Do you know how to avoid that?
For now I've just converted it to numeric, but difftime is more convenient.

Thank you in advance!

0

There are 0 best solutions below