Try   HackMD

Summer 2022

Topics

Command-line/Unix intro

Intro reading: two articles on "command line bullshittery" (the original post by Philip Guo that introduced this term is no longer available, alas ) (Also see [1])

  • Jen
  • Ben

Windows resources

Sessions

  • covered in session 1: keyboard shortcuts (TAB/^C/^V), navigation, create/copy/remove, grep and basic find, basic pipes and filters. touch, wc, cat, head/tail, cut (briefly), nano/vi (briefly), man pages (briefly), less/more (briefly).
    SC shell introduction sections 1-4.
  • covered in session 2:
    • overview: shell as a language (vs R/Python/Perl ?)
    • simple scripts (. myscript vs ./myscript)
    • permissions and paths
    • running commands for many files:
      • globbing
      • $()
      • xargs
      • `` (capture result of command)
      • (find ... -exec)
      • for loops
    • shell and environment variables; command-line arguments

session 4:

  • screen, tmux etc.
  • misc: which

  • installing stuff
    • tarballs (.tar, .tar.gz, .tgz); tar, g(un)zip, configure/make/make install
    • apt/yum (Linux), homebrew/MacPorts/fink(MacOS), cygwin/WSL/? (Windows)

make (makestuff/shellpipes/pipeR)

other workflow tools

containers (Docker etc.)

  • Docker is a thin virtual machine (sort of): https://jsta.github.io/r-docker-tutorial/
  • Rocker is a set of R-oriented Docker images
  • twitter thread from Péter Sólymos about docker resources
  • Docker Desktop: a virtual machine + Docker layer for MacOS & Windows
  • starting a shell in a running docker (docker ps; docker exec -it <container_id or name> bash)
  • set permissions for Linux: sudo groupadd docker; sudo usermod -aG docker $USER; newgrp docker; (may need to log out & back in/start a new shell?)
  • Dockerfile for r-base/latest on Rocker
  • incantations:
    • docker run --rm -ti rocker/r-base (--rm cleans up, t == start a terminal, i == interactive)
      • if you get some message like the input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty', listen to this message and add this prefix winpty docker run --rm -ti rocker/r-base
    • docker run --rm -p 8787:8787 -e PASSWORD=definitelysecure rocker/verse followed by pointing browser to localhost:8787 or
  • Jonathan
  • Mikael, Steve

debugging in R

  • Michael
  • Mikael
  • Mike L. (not really, but it seemed a shame not to list him)

purrr

purrr is an R package, part of the tidyverse. It is the tidyverse's machinery for functional programming. The name "purrr" comes from the idea of "pure functions" (functions that take an argument and return a value and have no side effects), which are important in functional programming.

The main functions in purrr are map() and variations; "map" is a term from functional programming, which means "apply a function to a list of objects". map() is the equivalent of lapply() ("list apply") in base R. It also has a lot of other commands for working with lists (see the cheatsheet)

  • Jonathan
  • Bicko

Summer 2023

debugging in R

  • flow package
  • debug package (Bravington, archived
    • (remotes::install_version("debug", "1.3.1")
  • Wickham chapter 22
  • good old cat()
  • traceback(): understanding the call stack
  • debug(): debugging mode (also debugonce)
    • browser(): setting breakpoint
    • options(error = recover): debug on error
    • options(warn = 2): promote warnings to errors
    • setBreakpoint("filename#linenum") (front end to trace())
  • exiting: Q, undebug(), `options(error = NULL, warn = 1)
  • reproducible examples (reprex package)
  • debugging in weird environments (e.g. rmarkdown?)
  • debugging compiled (e.g. C++) code within R
  • annoyances: editing functions defined within functions, functions that are reassigned (thus losing the debug flag, etc.)

example from Advanced R

f <- function(a) g(a)
g <- function(b) h(b)
h <- function(c) i(c)
i <- function(d) {
  if (!is.numeric(d)) {
    stop("`d` must be numeric", call. = FALSE)
  }
  d + 10
}

a more annoying example

f <- function(a) {
   g <- function(b) {
      h <- function(c) {
         i <- function(d) {
              if (!is.numeric(d)) {
                 stop("`d` must be numeric", call. = FALSE)
              }
              d + 10
         }
         i(c)
      } 
      h(b)
   }
   g(a)
}

more generally

  • reading the error message
  • googling the error message
  • ChatGPT???
  • bisection (git )

testing

Primary reading: testing chapter from the Digital Science Center (DiSC) at Universität Innsbruck.

  • floating-point issues (all.equal etc.; tolerances)
  • waldo::compare
  • test cases
  • unit, integration, regression tests
  • refactoring (need for established tests)
  • testing frameworks: base-R/built-in, testthat, tinytest (see here), tinysnapshot
  • automation: GitHub Actions (and alternatives)

  1. and "In the Beginning was the Command Line", an optional, ancient, very long essay by Neal Stephenson ↩︎