It is the same as previously solved issue (https://github.com/Rdatatable/data.table/issues/505)
It was supposedly solved in v1.9.5. But issue is still reproducible in v1.9.6
library(data.table)
cars <- data.table(cars)
cars[ , test := rnorm(50)]
This should not get printed in knitr, but it does.
See demonstration: http://rpubs.com/Keell/230348
Related (although I don't have printr loaded): https://github.com/Rdatatable/data.table/issues/1326
It's related to rmarkdown package I guess, see the issue here:
I just commented here : http://stackoverflow.com/questions/15267018/knitr-gets-tricked-by-data-table-assignment/15268392?noredirect=1#comment68916947_15268392
Thanks. Here's the passing test in data.table. As far as I can see it covers yours. What's the difference? Your example does not seem to be reproducible in the sense that I can run it with R --vanilla. https://github.com/Rdatatable/data.table/blob/master/tests/knitr.Rmd
Here is the .save output that R CMD check compares to : https://github.com/Rdatatable/data.table/blob/master/tests/knitr.Rout.save
Hi,
I have checked the test. It fails for me in RStudio knit button but passes with R --vanilla.
Further checks shows that it is indeed connected to rmarkdown (As mentioned by shrektan)
Simple modification for the knitr.Rmd file, proves it.
(Adding require(rmarkdown) at the beginning of the code)
```{r test_id, message=FALSE, results="show", echo=TRUE, warning=FALSE}
require(rmarkdown)
require(data.table) # print?
DT = data.table(x=1:3, y=4:6) # no
DT # yes
DT[, z := 7:9] # no
print(DT[, z := 10:12]) # yes
if (1 < 2) DT[, a := 1L] # no
DT # yes
```
Some text.
```{r}
sessionInfo()
```
Notice failure at DT[, z := 7:9]. This is with R --vanilla
> source("knitr.R")
Loading required package: knitr
Loading required package: rmarkdown
Loading required package: data.table
data.table 1.9.6 For help type ?data.table or https://github.com/Rdatatable/data.table/wiki
The fastest way to learn (by data.table authors): https://www.datacamp.com/courses/data-analysis-the-data-table-way
```r
require(rmarkdown)
require(data.table) # print?
DT = data.table(x=1:3, y=4:6) # no
DT # yes
```
```
## x y
## 1: 1 4
## 2: 2 5
## 3: 3 6
```
```r
DT[, z := 7:9] # no
```
```
## x y z
## 1: 1 4 7
## 2: 2 5 8
## 3: 3 6 9
```
```r
print(DT[, z := 10:12]) # yes
```
```
## x y z
## 1: 1 4 10
## 2: 2 5 11
## 3: 3 6 12
```
```r
if (1 < 2) DT[, a := 1L] # no
```
```
## x y z a
## 1: 1 4 10 1
## 2: 2 5 11 1
## 3: 3 6 12 1
```
```r
DT # yes
```
```
## x y z a
## 1: 1 4 10 1
## 2: 2 5 11 1
## 3: 3 6 12 1
```
Some text.
```r
sessionInfo()
```
```
## R version 3.3.1 (2016-06-21)
## Platform: x86_64-apple-darwin15.0.0 (64-bit)
## Running under: OS X 10.12.1 (Sierra)
##
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] data.table_1.9.6 rmarkdown_1.2 knitr_1.15.1
##
## loaded via a namespace (and not attached):
## [1] backports_1.0.4 magrittr_1.5 rprojroot_1.1 htmltools_0.3.5
## [5] tools_3.3.1 Rcpp_0.12.8 stringi_1.1.2 digest_0.6.10
## [9] stringr_1.1.0 chron_2.3-47 evaluate_0.10
```
@Javdat Yes, it's very annoying, honestly speaking! Now I use invisible(dt[i, j:=expr]) in all my rmarkdown files...
This is reproducible in 1.10.0.
I use the same trick as @shrektan (although at times dt <- dt[i, j:=expr]) is more readable) i
Same problem here. Thanks @shrektan , the invisible workaround saved my documnet from a monstruous 7M-rows table :/ [I couldn't figure out why the knit seemed stuck and R was unresponsive, as everywhere := says it returns the result invisibly].
Is fixed in development version of rmarkdown
See: https://github.com/rstudio/rmarkdown/issues/829
devtools::install_github("rstudio/rmarkdown")
@Javdat if I'm not mistaken, that version has now been pushed to CRAN as well:
https://cran.r-project.org/web/packages/rmarkdown/index.html
It has, updating RMarkdown via RStudio pointed at default CRAN to version 1.4 instantaneously fixed the issue. Thanks.
Most helpful comment
Is fixed in development version of
rmarkdownSee: https://github.com/rstudio/rmarkdown/issues/829
devtools::install_github("rstudio/rmarkdown")