Skip to content

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

Description

@MichaelChirico

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).

Activity

  1. MichaelChirico commented on Dec 20, 2023

    @MichaelChirico
    MemberAuthor

    This would supersede #5429.

  2. jangorecki commented on Dec 20, 2023

    @jangorecki
    Member

    +10!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions