with_mocked_responses | R Documentation |
Mocking allows you to selectively and temporarily replace the response you would typically receive from a request with your own code. It's primarily used for testing.
with_mocked_responses(mock, code)
local_mocked_responses(mock, env = caller_env())
mock |
A function, a list, or
|
code |
Code to execute in the temporary environment. |
env |
Environment to use for scoping changes. |
with_mock()
returns the result of evaluating code
.
# This function should perform a response against google.com:
google <- function() {
request("http://google.com") |>
req_perform()
}
# But I can use a mock to instead return my own made up response:
my_mock <- function(req) {
response(status_code = 403)
}
try(with_mock(my_mock, google()))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.