1

Is it possible to have loading a package modify base R functions, like redefining warnings? How? For example:

y = "string"
as.numeric(y)
[1] NA
Warning message:
NAs introduced by coercion 

The warning message tells something is not quite write, but it doesn't make it clear what is wrong, specially for begginers. How can I achieve something like this:

library(package)
y = "string"
as.numeric(y)
[1] NA
Warning message:
Can't convert character (example: "string") to numeric.
VFreguglia
  • 2,129
  • 4
  • 14
  • 35
  • 3
    Possible duplicate of [Overwrite method to extend it, using the original implementation](https://stackoverflow.com/questions/8077003/overwrite-method-to-extend-it-using-the-original-implementation). Once you re-write the function as shown there, just roll it into a package. See also a related question I answered recently [here](https://stackoverflow.com/a/48392351/8386140). PS: If you also need to know how to make a custom error message, try something like this: `as.numeric <- function(x){if ( condition ) { stop(custom_error_message) }; return(base::as.numeric(x)) }` – duckmayr Jan 28 '18 at 15:41

0 Answers0