These functions allow you to temporarily override S3 and S4 methods that
already exist. It works by using registerS3method()
/setMethod()
to
temporarily replace the original definition.
Usage
local_mocked_s3_method(generic, signature, definition, frame = caller_env())
local_mocked_s4_method(generic, signature, definition, frame = caller_env())
Examples
x <- as.POSIXlt(Sys.time())
local({
local_mocked_s3_method("length", "POSIXlt", function(x) 42)
length(x)
})
#> [1] 42
length(x)
#> [1] 1