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

ROBUSTNESS: Use defaults for unset datatable.* options #5375

Open
HenrikBengtsson opened this issue Apr 28, 2022 · 0 comments
Open

ROBUSTNESS: Use defaults for unset datatable.* options #5375

HenrikBengtsson opened this issue Apr 28, 2022 · 0 comments

Comments

@HenrikBengtsson
Copy link

HenrikBengtsson commented Apr 28, 2022

Issue

If some functions, own or third-party, resets all R options to what they were prior to loading data.table, then some data.table functions fail because querying those options result in NULL values. Imagine a function that reset all R options using on.exit() to protect against side effects from some rough function call setting, say, options(warn = 2).

Reproducible example

library(data.table)

## data.table options
names <- grep("^datatable", names(options()), value = TRUE)
dtopts <- options()[names]

a <- data.table()

## remove data.table options
reset <- setNames(vector("list", length = length(dtopts)), names(dtopts))
options(reset)

b <- data.table()
#> Error in setalloccol(ans) : verbose must be TRUE or FALSE

Troubleshooting

The problem is that data.table::setalloccol() assumes that these R options are always set. For example,

args(data.table::setalloccol)
#> function (DT, n = getOption("datatable.alloccol"), verbose = getOption("datatable.verbose")) 
#> NULL

Suggestion

I'd like to argue that code should not make assumptions about R options being set, even for "internal" R options. My suggestions is to add defaults to all getOption(), e.g.

args(data.table::setalloccol)
#> function (DT, n = getOption("datatable.alloccol", 1024L), verbose = getOption("datatable.verbose", FALSE)) 
#> NULL

FWIW, from:

> options(datatable.verbose = FALSE)
> b <- data.table()
Error in setalloccol(ans) : 
  Has getOption('datatable.alloccol') somehow become unset? It should be a number, by default 1024.

it's clear your aware of this potential problem. Maybe this has already been discussion previously.

Session info

> sessionInfo()
R version 4.2.0 (2022-04-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.4 LTS

Matrix products: default
BLAS:   /home/hb/shared/software/CBI/R-4.2.0-gcc9/lib/R/lib/libRblas.so
LAPACK: /home/hb/shared/software/CBI/R-4.2.0-gcc9/lib/R/lib/libRlapack.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

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

loaded via a namespace (and not attached):
[1] compiler_4.2.0
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

1 participant