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

test() should get an options= argument to transparently & temporarily set options for a test #5842

Closed
MichaelChirico opened this issue Dec 20, 2023 · 2 comments · Fixed by #5996 · May be fixed by #5845
Closed

test() should get an options= argument to transparently & temporarily set options for a test #5842

MichaelChirico opened this issue Dec 20, 2023 · 2 comments · Fixed by #5996 · May be fixed by #5845
Labels

Comments

@MichaelChirico
Copy link
Member

test = function(num,x,y=TRUE,error=NULL,warning=NULL,message=NULL,output=NULL,notOutput=NULL,ignore.warning=NULL) {

Now, we set options sporadically in the text, e.g.

options(datatable.verbose=TRUE)

options(datatable.verbose=FALSE)

Having the option set 50, 100, or more lines away from where the value is needed harms readability. It's much better to set the options transparently in the call to test().

Proposed API:

test(..., options = list(key1 = "val1", ..., keyn = "valn"))

# impl
test <- function(..., options = NULL) {
  if (!is.null(options)) {
    old <- do.call("options", options)
    on.exit(options(old), add = TRUE)
  }
  ...
}

Possibly tmp_options= is a better name so as not to clash with options(), then we can do do.call(options, tmp_options).

@MichaelChirico
Copy link
Member Author

This would supersede #5429.

@jangorecki
Copy link
Member

+10!

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