if (FALSE) {
# Example: Capturing output, messages, warnings, and errors
captured <- capture({
print("Hello, world!")
message("This is a message.")
warning("This is a warning.")
42 # Final value returned
})
# Display the captured components
print(captured$output) # Printed output
print(captured$messages) # Messages
print(captured$warnings) # Warnings
print(captured$error) # Error message (if any)
print(captured$value) # The evaluated result (42 in this example)
}
Run the code above in your browser using DataLab