Another way to possibly() purrr

1. Another way to possibly() purrr

While safely() is great for pinpointing where the issue is, and what the issue is with messy data, possibly() helps us get past it and get on with our day. It is a good idea to diagnose your a problem with safely() and then replace it with possibly() once the issue is resolved so that you can get the output you want and keep working.

2. safely() then possibly()

This is the same code we looked at in the previous lesson; we are using safely() to figure out what and where the issue is. We have used NA underscore real underscore as the otherwise argument in the safely() function to replace element that throw an error with an NA. In this case, having an NA for element 2 is the result that we want, and now we want to move onto using these values for our analysis. That means we don't need the error elements, we just need the results. Let's see what happens when we switch out possibly() for safely() on the next slide.

3. possibly()

This is the same code as the previous slide, with one difference. We have replaced safely() with possibly(). The arguments inside the function stay the same; only the name of the function changes. We still need the otherwise argument, since possibly() is going to do the same things safely() did; it just gives a simpler output, with just the results, and none of the error messages. This can be a great way of dealing with messy data in lists.

4. Let's purrr-actice!

Now it's your turn.