powered by
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.
registerS3method()
setMethod()
Learn more about mocking in vignette("mocking").
vignette("mocking")
local_mocked_s3_method(generic, signature, definition, frame = caller_env())local_mocked_s4_method(generic, signature, definition, frame = caller_env())
local_mocked_s4_method(generic, signature, definition, frame = caller_env())
A string giving the name of the generic.
A character vector giving the signature of the method.
A function providing the method definition.
Calling frame which determines the scope of the mock. Only needed when wrapping in another local helper.
x <- as.POSIXlt(Sys.time()) local({ local_mocked_s3_method("length", "POSIXlt", function(x) 42) length(x) }) length(x)
Run the code above in your browser using DataLab