Resources

Amanda Gadrow | Lessons about R I learned from my cat | RStudio (2020)

Forming good development habits for R projects is pretty straight-forward if you follow the lessons I've learned from my cat, whose advice includes "be lazy", "keep your claws sharp", and "land on your feet". Attendees of this talk will learn how to make life easier on colleagues and their future selves by using simple software engineering best practices to build their current projects. Each point will come with cat photos and code samples, the two best parts of the Internet!

image: thumbnail.jpg

Transcript#

This transcript was generated automatically and may contain errors.

Thank you. This is Reese's Pieces. We named her that because her orange and brown spots reminded us of the candy. And I work from home, so Reese and I get to hang out a lot. And whenever I get stuck on a particularly thorny R problem, I talk to her. She's kind of my sounding board, and she invariably gives me some sage advice. And the very biggest piece she gives me is to be lazy. This is actually how she sleeps. It's kind of ridiculous.

So what I mean by being lazy is, you want to make it as easy as possible for future you to do as little work as possible to understand what you're writing today. So this describes a lot of different things. You're basically trying to be consistent with your own work. You're trying to have some patterns that you follow all the time, so it makes it really intuitive for you to figure out what you're doing next.

So what I mean by being lazy is, you want to make it as easy as possible for future you to do as little work as possible to understand what you're writing today.

Project structure

And this starts with the project structure. So unfortunately, this is a little smaller than I'd hoped. I'm sorry. This is an example of a very small project, but it does have some problems. I don't know if you can see it, but there's a file called monolith.r. It's enormous. Imagine in four months from now, you're trying to find a function in this enormous file. It would be pretty difficult. And there are data files in here that have names that are completely nonintuitive. If you come back to this later, are you going to be able to tell what's going on? Probably not. You will be sad.

So in the interest of future laziness, you can reorganize this just a little bit, do a couple minutes of work to save yourself possibly hours of work later. So what I've done here is split up that big R file so that you can tell where the global functions are, where the helper functions are, where the main analysis is. And just by the names of these files, you can kind of tell where you might go to find something if you're looking to update or add new data. I have also added a new data structure here, and I've renamed all the files so that the names themselves will give you a clue as to what's in them. You don't have to remember what this strange esoteric file name is if you name your files in a way that it's easy to tell what's in there without having to explore them automatically.

So just this little bit of work today is going to make your life a lot easier later, which is exactly what my cat had suggested. In addition to that, to that being at the structure level for your projects, you also want to do that within your individual files. You can pick the structure that works for you as long as you're consistent so that you can tell later kind of what you meant, and if you always structure it in the same way or you almost order it in the same way, you're going to remember what all this means. My preferred way is to have library statements at the top, then source statements, object definitions, function definitions, and then the code at the bottom. Obviously I'm going to be creating objects and functions along the way, but the global ones go at the top so I can find them easily later.

And then at the statement level, you want to make these human readable as well. So a machine can read either of these equally well, but a human being going back and needing to alter something, the second one is a whole lot easier to read. So for the rest of this presentation, my cat was so lazy that she wouldn't pose for me, so the rest of this has beautiful images from the internet, so please enjoy.

More lessons from the cat

So, more bits of advice that she's given me. I don't know if you guys have seen this before, this is my favorite GIF ever. Try things. It's not always going to work, as you know, but try them anyway, and if they don't work, try to land on your feet. Learn from it, walk away like a boss, you meant to do that.

Ask for help if you need it. These are some of my favorite resources. Google is obviously a great first place to go as well. If you have a local R users group or a local R ladies group, you can actually ask in person as well. Keep your claws sharp. Learn new things at all times. Again, lots of resources here. I definitely recommend R ladies and R users groups to learn these in person, because then you can ask questions and things like that. Try to learn new things, try to keep on top of trends, and it could make your life a lot easier. Hang out with your friends. Again, I'm going to plug for R ladies, it's my favorite group, but there are lots of places to do so online as well.

And finally, bask in the sun. Enjoy the fact that future you is going to be much more happy if you've arranged for current you to design your projects in a meaningful way. Thank you very much.