Skip to content

Create function for newdata alert #525

Description

@EmilHvitfeldt

Should the following code be wrapped up in an exported helper function?

parsnip/R/linear_reg.R

Lines 236 to 237 in 37b07cb

if (any(names(enquos(...)) == "newdata"))
rlang::abort("Did you mean to use `new_data` instead of `newdata`?")

It is used a couple of handfuls of times in this package along with other add-on packages.

newdata_abort <- function(...) {
  if (any(names(rlang::enquos(...)) == "newdata")) 
   rlang::abort("Did you mean to use `new_data` instead of `newdata`?") 
}

test <- function(...) {
  newdata_abort(...)
  list(...)
}

test(new_data = "hello")
#> $new_data
#> [1] "hello"


test(newdata = "hello")
#> Error: Did you mean to use `new_data` instead of `newdata`?

Created on 2021-07-03 by the reprex package (v2.0.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancement

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions