2

when i try to add (data.table/ggplot2)code in slidify, i got error. Here is my code in slidify:

## data.table
```{r}
library(data.table)
DT = data.table(x = 1:5, y=6:10)
setkey(DT, x)
DT[J(1)] # Error: No J function
```
---
## ggplot2
```{r}
library(ggplot2)
a = b = shape = 1:5
ggplot(data=DT, aes(a, b, col=shape)) + geom_point() # Error: can not find object a
```

All the code can run outside slidify, so i guess there is something about variable namespace wrong with slidify.

I also find this link:data.table error when used through knitr, gWidgetsWWW which might be similar with my problem, but still don't know how to fix.

Community
  • 1
  • 1
yalei du
  • 697
  • 7
  • 13
  • Could you please give the [current development version](https://github.com/Rdatatable/data.table) a try? – Arun Sep 13 '14 at 01:18
  • To my surprise, it works. I thought it was slidify's problem, cause the ggplot2 command can not run either. Thanks! – yalei du Sep 13 '14 at 02:13
  • Interesting: I can run the first part. But the ggplot command throws the error ## Error: Continuous value supplied to discrete scale – JerryWho Sep 15 '14 at 06:38
  • The first part was fixed in data.table 1.9.3 version. The ggplot part,caould you try this command "ggplot(data=DT, aes(a, b, col=shape)) + geom_point()"? – yalei du Sep 15 '14 at 08:21
  • BTW, "Continuous value supplied to discrete scale" this error message came from ggplot2, maybe you need update your package? my ggplot2 version is 1.0.0. – yalei du Sep 15 '14 at 08:25
  • @yalei du: I do use ggplot2 version 1.0.0.... – JerryWho Sep 16 '14 at 11:57

1 Answers1

0

Just to add an answer to follow up on the comments on the question. The dev version of data.table fixed it and is now on CRAN (data.table v1.9.4). But this broke kable() in knitr which knitr v1.7 (on CRAN too) fixes.

So basically, upgrade to latest CRAN versions of knitr and data.table and you should be fine. Please let us know if not.


More detail for the curious ...

I've made another change to data.table in v1.9.5 to make it more robust for packages that evaluate user code (like knitr, slidify and gWidgetsWWW) but don't know about data.table themselves. So that they don't need to know in future. Here is the item :

knitr::kable() works again without needing to upgrade from knitr v1.6 to v1.7. Packages which evaluate user code and don't wish to import data.table need to be added to data.table:::cedta.pkgEvalsUserCode and now only the eval part is made data.table-aware (the rest of such package's code is left data.table-unaware). data.table:::cedta.override is now empty and will be deprecated if no need for it arises.

And here is the item in v1.9.4 that was a little too over-reaching and broke knitr::kable in knitr v1.6 and knitr v1.7 fixes (but shouldn't have needed to) :

Added shiny, rmarkdown and knitr to the data.table whitelist. Packages which take user code as input and run it in their own environment (so do not Depend or Import data.table themselves) either need to be added here, or they can define a variable .datatable.aware <- TRUE in their namepace, so that data.table can work correctly in those packages. Users can also add to data.table's whitelist themselves using assignInNamespace() but these additions upstream remove the need to do that for these packages.

Matt Dowle
  • 58,872
  • 22
  • 166
  • 224