R is a game engine, fight me

A crudely drawn image of the buttons from a Nintendo SNES controller, but the A, B, X and Y labels have all been changed to R.

tl;dr

R is ‘a free software environment for statistical computing and graphics’. Ahahaha, no it’s not, it’s a game engine. I’ve created a ‘splendid’ list of games you can play—written in R—to prove it. Help expand it.

Stats only!

R is not a general, multi-purpose programming language. It was written to do statistical analysis and make charts. You are literally not allowed to do anything else with it. You should use <LANGUAGE> instead, which is much more suited to your specific use case. R is a joke language for nerds.

You should not read beyond this point if you think, quite rightly, that mirth and frivolity are unsuited to an R session.

Stats only?

Unity. Unreal. GameMaker. Godot. All of these videogame engines are now obsolete.

It is R—humble R!—that represents the future of gaming.

To prove it, I’ve created a list of ‘splendid R games’ in a GitHub repo1 that you are welcome to contribute to.2

Yes, R can be used for fun. Do not tell R Core.

Wait, he’s serious?

I think there’s three kinds of ‘platform’ for games written in R:

  1. For the console
  2. In Shiny
  3. Ported

Games played in the console are pretty straightforward and probably most common. You can run some code, or a function from a package, to launch some code in the R console that you can interact with. A simple option for this might involve use of readline() to receive user input, for example, like Giora Simchoni’s excellent text-based puzzler, Castle of R.

Screenshot of R running in the terminal. A text interface asks the user to identify their skill in R. The user has typed option '4', which corresponds to the text 'what is R?'. The resulting text says 'welcome to the Castle of R' and explains its purpose.

Giora’s Castle of R running in the terminal.

Shiny can give you a little more flexibility when it comes to graphics and user input, at the expense of needing to host the app and maybe some extra JavaScript skills. A great example of this is Pedro Silva’s winning entry (app, source) to the Posit Shiny contest in 2020.

A screenshot of a game that shows a world map with face, building and tree emojis on it. There are meters labelled 'wealth', 'opinion' and 'environment' and another with a halo on one end and devil horns the other. Text at the bottom says 'swipe left or right on the card to start'.

A still from Pedro’s Shiny Decisions app.

The third category is a little more boundary-pushing. Imagine if R was powerful enough to let you port existing games. Well, surprise, ya boi Mike Cheng (aka coolbutuseless) has pushed hard on expanding the capabilities of R to run fast enough and with realtime user input,3 porting the classic Another World (1991) to R, which was showcased at 2022’s Posit conference (source, video, blog).

A screenshot of the game with the main character apparently waving to a shadowy silhouette in the foreground. The overalid title says 'moonshot' and text at the bottom is a quote by Mike Cheng saying 'i will commit myself to achieving the goal, before the year is out, of writing and playing a videogame in R'.

A still from Mike’s rstudio::conf(2022) presentation, featuring Another World.

Of course, within these ‘platforms’ are genres like word games, arcade games, puzzle games, etc. Will you be the first to create an MMORPG (a massively-multiplayer online R-powered game)?

I am an indie game dev now

I’ve always been interested in how videogames are coded,4 wishing that I could do the same myself. Of course I could simply learn ‘real’ programming languages.

Except that’s blasphemy. Of course I’d rather break my own mind and spirit in an attempt to make R achieve 0.1% of what might be possible in P*thon.

Case in point, I’ve made a few R packages containing some little toys (in order of gooddest to baddest):

  • {r.oguelike} (source, blogs) for a procedural-dungeon explorer with enemy pathfinding and inventory
  • {tamRgo} (source, blog) for a cyber pet in your R console that persists between sessions
  • {safar6} (source, blog) for a text-based re-make of the Safari Zone from the first generation of Pokémon games
  • {ActionSquirrel} (source, blog) for a tile-based, turn-based minigame in the R console
  • {hokey} (source, blog) for minigames that use direct keypress inputs with {keypress}
Screenshot of R running in the terminal. The get_stats and see_pet functions from the tamRgo package have been run. The first prints some output showing characteristics and status of a cyber pet. The latter prints an image of the pet to the browser. The pet is called Kevin and is 139 in age. It appears to be unalive.

Hint when playing {tamRgo}: do not forget about your pet for 138 days. RIP Kevin XVIII.

I’ve got something in the pipeline that involves extremely rudimentary physics in the R console. Wow! For release in 2023 (because game launches never go wrong).

Ready Player 2

The splendid list must be missing a bunch of games. Please leave an issue or pull request in the splendid-r-games repo to add more examples.

Next stop: letting people run R games in the browser without an installed copy of R. This is already possible with a service like Binder, which can spin up an instance of RStudio with packages pre-installed I did this for {r.oguelike}).

RStudio running a browser on a mobile phone playing the tile-based game from the r.oguelike package.

Just like the Nokia N-Gage, amirite?

But soon you might be able to use WebR to play games in the browser without even spinning up RStudio, ooh. So look out for an R version of itch.io in future, lol.


Session info
## ─ Session info ───────────────────────────────────────────────────────────────
##  setting  value
##  version  R version 4.2.0 (2022-04-22)
##  os       macOS Big Sur/Monterey 10.16
##  system   x86_64, darwin17.0
##  ui       X11
##  language (EN)
##  collate  en_US.UTF-8
##  ctype    en_US.UTF-8
##  tz       Europe/London
##  date     2023-04-18
##  pandoc   2.19.2 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown)
## 
## ─ Packages ───────────────────────────────────────────────────────────────────
##  package     * version date (UTC) lib source
##  blogdown      1.9     2022-03-28 [1] CRAN (R 4.2.0)
##  bookdown      0.26    2022-04-15 [1] CRAN (R 4.2.0)
##  bslib         0.3.1   2021-10-06 [1] CRAN (R 4.2.0)
##  cli           3.6.0   2023-01-09 [1] CRAN (R 4.2.0)
##  digest        0.6.31  2022-12-11 [1] CRAN (R 4.2.0)
##  evaluate      0.20    2023-01-17 [1] CRAN (R 4.2.0)
##  fastmap       1.1.0   2021-01-25 [1] CRAN (R 4.2.0)
##  htmltools     0.5.2   2021-08-25 [1] CRAN (R 4.2.0)
##  jquerylib     0.1.4   2021-04-26 [1] CRAN (R 4.2.0)
##  jsonlite      1.8.4   2022-12-06 [1] CRAN (R 4.2.0)
##  knitr         1.42    2023-01-25 [1] CRAN (R 4.2.0)
##  R6            2.5.1   2021-08-19 [1] CRAN (R 4.2.0)
##  rlang         1.0.6   2022-09-24 [1] CRAN (R 4.2.0)
##  rmarkdown     2.14    2022-04-25 [1] CRAN (R 4.2.0)
##  rstudioapi    0.14    2022-08-22 [1] CRAN (R 4.2.0)
##  sass          0.4.1   2022-03-23 [1] CRAN (R 4.2.0)
##  sessioninfo   1.2.2   2021-12-06 [1] CRAN (R 4.2.0)
##  xfun          0.37    2023-01-31 [1] CRAN (R 4.2.0)
##  yaml          2.3.7   2023-01-23 [1] CRAN (R 4.2.0)
## 
##  [1] /Library/Frameworks/R.framework/Versions/4.2/Resources/library
## 
## ──────────────────────────────────────────────────────────────────────────────

  1. I originally labelled the GitHub repo as an ‘awesome’ repo, which I later learned has a very specific meaning. You might have seen awesome lists before, like the awesome-quarto repo by Mickaël, or the new awesome-webr list by Nan Xiao. ‘Splendid’ is much more of a Bri’ish word than ‘awesome’, so it feels more natural anyway.↩︎

  2. Note that I have carefully released this post just after April fool’s day, which means I am super, super serious. As usual.↩︎

  3. See the {nara} and {eventloop} packages in particular.↩︎

  4. I like YouTube devlogs by folks like Seb Lague, ThinMatrix, SquidGod, Jonas, TanTan and others. R can never achieve what they’re up to, but I like listening through the logic of what they’re doing.↩︎