Exercise

Extract log information (5)

Have another look at logs, that is still available in your workspace. Have you noticed that the details element of each log entry differs between logs indicating success and failure? For successes, it's a list with a message element. For failures, it's a list with two elements: message and location. We've printed out str(logs) for you below. See the differences in structures between a successful log and an unsuccessful log:

At first sight, our function only allows the selection of log entry information on the first level, such as success and details. To get information that's deeper inside the log entries, such as message, we'll need another function, right? Nope, your function will work just fine. To select elements from embedded lists, you can use chained selection. The following code chunk uses chained selection to return the value 2:

x <- list(a = 1, b = list(r = 2, s = 3))
x[[c("b", "r")]]

Instructions

100xp

Use extract_info() to build a vector containing the message elements of all log entries, irrespective of whether they indicate a failure or not.

Use extract_info() to build a vector containing the location information for log entries indicating a failure. This means you have to set include_all = FALSE now!