5

Say I have the following object inside a knitr chunk:

df <- as.Date(c("2013-10-01", "2013-10-02", "2013-10-03"))

Now, when I try to run this:

`r min(df)`  # that would be \Sexpr{min(df)} for a TeX file

I get the following error:

Error in Math.Date(x) : abs not defined for "Date" objects
Calls: knit ... .inline.hook -> format_sci -> vapply -> FUN -> Math.Date

Execution halted

knitr terminated with status 1

Is this a bug? How can I work around it?

4

1 回答 1

5

我不知道这是否有资格作为答案,但是是的,这似乎确实是一个错误——我想知道其他哪些课程受到了影响!

一个简单但可能不方便的解决方法是首先将您的输出转换为“字符”。换句话说,尝试类似:

```{r}
df <- as.Date(c("2013-10-01", "2013-10-02", "2013-10-03"))
```

Here's a paragraph with `r as.character(min(df))`.
于 2013-10-03T19:00:08.033 回答