I'm experimenting with gWidgetsWWW and encountered a strange error. I created a button with a handler to knit2html a report which used the data.table assignment operator ":=". The report came back with this error:
Error: := is defined for use in j only, and (currently) only once; i.e., DT[i,col:=1L] and DT[,newcol:=sum(colB),by=colA] are ok, but not DT[i,col]:=1L, not DT[i]$col:=1L and not DT[,{newcol1:=1L;newcol2:=2L}]. Please see help(":="). Check is.data.table(DT) is TRUE.
The report generates as expected using knit2html directly and also through RStudio's "Knit HTML" button, so I'm unsure why it fails when knit2html is called by the handler.
Here is a gWidgetsWWW window "test_gui.R":
library(gWidgetsWWW)
library(knitr)
w<-gwindow("Test Window")
g<-ggroup(horizontal=F,cont=w)
b<-gbutton("Report Button",cont=g,handler=function(h,...){
knit2html("test_report.Rmd")
localServerOpen("test_report.html")
})
visible(w)<-T
Here is an example R Markdown Doc which produces the error:
Test Report
===========
```{r test_chunk}
library(data.table)
df<-data.frame(State=rownames(USArrests),USArrests)
data.table(df)[,State:=tolower(State)]
```
Not sure why, but when I call localServerOpen("test_gui.R") and click the button, I get the error...
Any ideas?
See Question&Answers more detail:os