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

print.data.table warns when options(datatable.show.indices=TRUE) and an index exists #6806

Open
aitap opened this issue Feb 9, 2025 · 4 comments

Comments

@aitap
Copy link
Contributor

aitap commented Feb 9, 2025

Observed while reading the source("data.table-Ex") output for translation purposes; taken from example(print.data.table):

library(data.table)
options(warn = 2, datatable.show.indices=TRUE)
NN <- 200
DT = data.table(grp1 = sample(100, NN, TRUE), grp2 = sample(90, NN, TRUE), grp3 = sample(80, NN, TRUE))
setindex(DT, grp1, grp3) # will warn during printing after this but not before
DT
# Index: <grp1__grp3>
# Error in rbind(abbs, toprint) : 
#   (converted from warning) number of columns of result is not a multiple of vector length (arg 1)

The warning most likely originates here:

toprint = rbind(abbs, toprint)

May be a good exercise in finding the emergency exit from R Inferno. If not, will debug myself soon.

@PradeepFSTdhane123
Copy link

@aitap I am excited to get involved and help with this bug issue. Could you assign it to me? I am looking forward to contributing and collaborating with the team. Thank you!"

@aitap
Copy link
Contributor Author

aitap commented Feb 9, 2025

@PradeepFSTdhane123 You are absolutely welcome to try your hand at preventing the warning. Good luck! Start by reproducing the warning with options(warn=2, error=recover) set.

@aitap aitap changed the title print.data.table may warn when key and index are both present print.data.table may warn when an index is present Feb 9, 2025
@Mukulyadav2004
Copy link

Mukulyadav2004 commented Feb 10, 2025

Hi , i was checking out this issue , i am not able to reproduce it .

> NN = 200
> options(warn = 2, error = recover)
> DT = data.table(grp1 = sample(100, NN, TRUE),grp2 = sample(90, NN, TRUE),grp3 = sample(80, NN, TRUE))
> setkey(DT, grp1, grp2)
> setindex(DT, grp1, grp3) 
> DT
Key: <grp1, grp2>
Index: <grp1__grp3>
      grp1  grp2  grp3
     <int> <int> <int>
  1:     1    72    17
  2:     1    78    59
  3:     2    60    14
  4:     3    15    12
  5:     3    48     6
 ---                  
196:    98    57    25
197:    99    55    80
198:    99    65    70
199:   100     2    80
200:   100     9    46

can you please explain.

@aitap
Copy link
Contributor Author

aitap commented Feb 10, 2025 via email

@aitap aitap changed the title print.data.table may warn when an index is present print.data.table warns when options(datatable.show.indices=TRUE) and an index exists Feb 10, 2025
@aitap aitap changed the title print.data.table warns when options(datatable.show.indices=TRUE) and an index exists print.data.table warns when options(datatable.show.indices=TRUE) and an index exists Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants