I’m getting to the very end of this package tryout exercise, and I suspect this will be the last post (other than perhaps a wrap up on Friday). It’s been a mildly annoying morning: I’ve done something to my foot, I’ve been awake since 4am, and somehow my twitter feed was full of people talking about Jordan Peterson 😒 Sigh. I probably should have just blocked or muted everyone talking about him rather than engage, but what’s done is done and I’d like to enjoy the rest of my morning.
To make myself feel better, I’ve been playing around with the keypress package. It’s really simple: it provides a function
keypress() that pauses execution until the user presses a key, and then returns that keypress as a string. It only works in the terminal, so if you’re calling from within RStudio or similar then your code needs a backup plan (e.g.,
readlines()). I was thinking about this for some substantive use cases (e.g., it could be handy for designing experiments), but in all honesty the most fun I had was in designing a silly text based computer game. This was based on a request my kids made last night… they wanted a computer game with rabbits and monsters, and this was the best I could do in an hour!
You are a rabbit trying to get to the carrot, but there are a bunch of “fire devils” that you need to avoid. Use w/a/s/d keys to navigate or q to quit. The fire devils are stupid and move randomly; when they bump into each other they merge together so you can wait them out easily. The script to run it is here. I wrote it in a hurry so it’s conceptually a bit off a mess but it seems to do the job. I’ve only tested it on RStudio and in the Mac OS terminal, and I’ve no idea if it would work on other platforms. Fun though! 🎉