假设我在knitr chunk中有以下对象:
df <- as.Date(c("2013-10-01", "2013-10-02", "2013-10-03"))
现在,当我尝试运行时:
`r min(df)` # that would be \Sexpr{min(df)} for a TeX file
我收到以下错误:
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
这是一个错误吗?我该如何解决它?
答案 0 :(得分: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))`.