2025-02-13

Navigating Rstudio

Window focus

  • Toggle code and console
    • ctrl + 1, 2, etc.
  • Maximize windows
    • ctrl + shift + 1, 2, etc.

Vertical selection

  • alt+ vertical selection

Code folding

  • alt+L to fold
  • shift+alt+L to unfold

Coding shortcuts

Common commands

  • Rename scope (ctrl+shift+alt+m)
    • Compare to ctrl+F replace
  • Insert arrow (alt+-)
  • Insert pipe (ctrl+shift+m)
  • Insert section name (ctrl+shift+r)
    • multi level outlines
  • Format indents (ctrl+i)

Specific functions

Reading zipped files

Tidyverse packages can often read directly from .zips

  • csv
  • shp
  • gdb

Piping column selection

  • matrittr %$% nrow(x)
  • Equal to base R df %>% with(nrow(x))

Purrr functions and list objects

  • map(df, ~ {ggplot() + geom_point() })
  • list2env(list, envir = .GlobalEnv)

Other functions

  • select (contains vs matches)
    • contains: a literal string “.zip”
    • matches: a regex “\.zip$”
  • garbage collection gc()
    • frees RAM
    • one step further than rm()