Base slaps!

matt-dray.github.io/nhs-r-2023

Matt Dray, October 2023

Polite notice: this is not a flamewar 🔥

What is ‘base R’? 🤔

It’s some packages

> (attached <- sessionInfo()$base |> sort())
[1] "base"      "datasets"  "graphics"  "grDevices" "methods"   "stats"    
[7] "utils"    
> extent <- installed.packages(priority = "base") |> row.names()
> setdiff(extent, attached)
[1] "compiler" "grid"     "parallel" "splines"  "stats4"   "tcltk"    "tools"   

Basic data handling

> x <- head(mtcars)
> (y <- x[x$wt > 3, c("hp", "cyl")])
                   hp cyl
Hornet 4 Drive    110   6
Hornet Sportabout 175   8
Valiant           105   6
> (y$hp_per_cyl <- round(y$hp / y$cyl))
[1] 18 22 18
> (z <- y[order(-y$hp_per_cyl), ])
                   hp cyl hp_per_cyl
Hornet Sportabout 175   8         22
Hornet 4 Drive    110   6         18
Valiant           105   6         18
> sapply(z, mean)
        hp        cyl hp_per_cyl 
130.000000   6.666667  19.333333 

  1. Stability
  2. Dependency
  3. Modernity

  1. Stability
A painting of two horseshoe crabs just kicking back underwater. The artist, Heinrich Harder, has signed the piece.

  1. Dependency
Comic from xkcd. Lots of blocks are stacked on top of each other. One small block near the bottom is indicated. Th eimplicatinois that removing the one small block will bring the whole thing down. THe stack is labelled 'your dependencies', the small block is labelled 'some package' and the big stable blocks underneath it are labelled 'base'.

  1. Modernity
The old R logo morphs into the new R logo. The old has bevels, highlights and shadows. The new one is simpler with peak 'flat' design.

The Modern Base Aesthetic 🧐

|>, _, \(), r"{}"

String literals

> paths <- c(
+   r"{C:\nonsense\trash 2021v1.txt}",
+   r"{C:\nonsense\bilge-2020-"new".txt}",
+   r"{C:\nonsense\rubbish2023_final.txt}"
+ )

Pipes and lambdas

> r"(20\d{2})" |> 
+   gregexpr(paths) |> 
+   regmatches(paths, m = _) |> 
+   sapply(\(yr) yr == "2023")
 

String literals

> paths <- c(
+   r"{C:\nonsense\trash 2021v1.txt}",
+   r"{C:\nonsense\bilge-2020-"new".txt}",
+   r"{C:\nonsense\rubbish2023_final.txt}"
+ )

Pipes and lambdas

> r"(20\d{2})" |> 
+   gregexpr(paths) |> 
+   regmatches(paths, m = _) |> 
+   sapply(\(yr) yr == "2023")
 

String literals

> paths <- c(
+   r"{C:\nonsense\trash 2021v1.txt}",
+   r"{C:\nonsense\bilge-2020-"new".txt}",
+   r"{C:\nonsense\rubbish2023_final.txt}"
+ )

Pipes and lambdas

> r"(20\d{2})" |> 
+   gregexpr(paths) |> 
+   regmatches(paths, m = _) |> 
+   sapply(\(yr) yr == "2023")
[1] FALSE FALSE  TRUE

Bonus: base did what? 🙃

locator() in {pixeltrix}
Demo of the 'pixeltrix' package in RStudio. A function has been run and the plot window displays a grid of squares. They're coloured to look like Mario from Super Mario. The user hits the escape key and is returned a matrix representation of the character they made, including colour values as an attribute.

readline() in {r.oguelike}
Gif demonstration of the 'r.oguelike' package in the RStudio console. The 'start_game' function is run. The console clears and a text-based tile-based dungeon map appears. Below is an inventory that includes health, money and food counters. Below is a prompt asking the user to type the W, A, S or D key and hit enter to move. The user does this and their player character moves around the dungeon space, collects an apple, battles an enemy and then eats the apple to restore health.

R_user_dir() in {tamRgo}
Demo of the 'tamRgo' package in the RStudio console. On the left, the 'tamRgo' package is loaded, which tells the user that their pet, 'Kevin', is pleased to see them and also provides some prompts for interacting with the pet. The user uses the 'get_stats' function for a printout showing the pet's status, like its age and how hungry it is. On the right, the user uses the 'see_pet' function' and a blocky character is printed to the console, along with a blocky poop. The user runs the 'clean' function and reinspects the pet and a message says that 'dirty' status value is now set to zero.

Base slaps!

Stability, dependency, modernity… oddity!
A QR code that links to where these slides exist on the web.

matt-dray.github.io/nhs-r-2023

Matt Dray

Links 🔗

Credits 👏