Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assigning using := still prints while debugging via browser() #2319

Closed
romunov opened this issue Aug 24, 2017 · 1 comment
Closed

assigning using := still prints while debugging via browser() #2319

romunov opened this issue Aug 24, 2017 · 1 comment

Comments

@romunov
Copy link
Contributor

romunov commented Aug 24, 2017

As per FAQ 2.21 and 2.22, printing of DT when using := has been suppressed since 1.8.3. However, I noticed that this still happens in borderline case, e.g. when debugging via browser(). Notice that this happens when one manually runs the assignment line, and not through pressing c, n or Enter. I can reproduce this in Rgui and RStudio (some nightly build).

I can confirm the same behavior in 1.10.5.

> library(data.table)
data.table 1.10.4
  The fastest way to learn (by data.table authors): https://www.datacamp.com/courses/data-analysis-the-data-table-way
  Documentation: ?data.table, example(data.table) and browseVignettes("data.table")
  Release notes, videos and slides: http://r-datatable.com
DT <- data.table(a = 1:3, b = letters[1:3])
DT[, c := rnorm(3)] # doesn't print object

# is browser() somehow responsible?
browser()
Called from: top level 
Browse[1]> DT[, d := rnorm(3)] # doesn't print object
Browse[1]> Q # doesn't appear so
 
sapply(1:3, function(x) {
  DT <- data.table(a = 1:3, b = letters[1:3])
  browser()
  DT[, e := rnorm(3)] # run this manually
})
Called from: FUN(X[[i]], ...)
Browse[1]> DT[, e := rnorm(3)] # prints object
   a b          c          d          e
1: 1 a -0.9089834 -0.8720443 -1.0034940
2: 2 b  1.2618214 -0.9993842  0.3317130
3: 3 c -2.2171694  0.2251432 -0.2082159

Behavior is consistent in lapply as well but not in a for loop.

for(i in 1:3) {
  DT <- data.table(a = 1:3, b = letters[1:3])
  browser()
  DT[, e := rnorm(3)]
}

Called from: top level 
Browse[1]> DT[, e := rnorm(3)] # doesn't print
Browse[1]> 

This is not big deal, I rather like it because I'm curious about my objects when debugging, just something I thought I'd let you know.

> sessionInfo()
R version 3.3.3 (2017-03-06)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

locale:
[1] LC_COLLATE=Slovenian_Slovenia.1250  LC_CTYPE=Slovenian_Slovenia.1250   
[3] LC_MONETARY=Slovenian_Slovenia.1250 LC_NUMERIC=C                       
[5] LC_TIME=Slovenian_Slovenia.1250    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] data.table_1.10.4

loaded via a namespace (and not attached):
[1] tools_3.3.3 yaml_2.1.14
@MichaelChirico
Copy link
Member

The reason it prints from browser() at the top level is that the call stack is small:

[[1]]
(function (x, ...) 
UseMethod("print"))(x)

[[2]]
print.data.table(x)

Whereas in the lapply scenario we've got:

[[1]]
sapply(1:3, function(x) {
    DT <- data.table(a = 1:3, b = letters[1:3])
    browser()
    DT[, `:=`(e, rnorm(3))]
})

[[2]]
lapply(X = X, FUN = FUN, ...)

[[3]]
FUN(X[[i]], ...)

[[4]]
DT[, e := rnorm(3)]

[[5]]
print.data.table(x)

Which doesn't match any of the suppression rules. Whereas without browser() print is not invoked from within the loop:

debug(data.table:::print.data.table)
sapply(1:3, function(x) {
  DT <- data.table(a = 1:3, b = letters[1:3])
  DT[, e := rnorm(3)] # no call to print
})

I'm not sure how worth the effort it is to try and come up w a rule for this situation, as I don't know if it's possible to detect being inside browser().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants