Skip to content

Instantly share code, notes, and snippets.

View johnbaums's full-sized avatar

John johnbaums

  • University of Melbourne
  • Melbourne
View GitHub Profile
@alexander-matz
alexander-matz / graphiq.Rscript
Created October 11, 2018 14:27
Nice Graph Colors from the Graphiq Blog
# Color palettes that actually look good from 1 .. 12 colors
# Taken from: https://blog.graphiq.com/finding-the-right-color-palettes-for-data-visualizations-fcd4e707a283
graphiq <- function (n, option = 'warm') {
if (n < 1 || n > 12) stop('colors only defined for n = 1..12');
if (option == 'warm') {
return(switch(n,
c("#FDB25F"),
c("#FFC96B", "#F47942"),
c("#FFC96B", "#F47942", "#AB412C"),
c("#FFD773", "#F99851", "#EF5833", "#923E2D"),
@johnbaums
johnbaums / get_namespaces.R
Last active February 8, 2022 14:02
Get the unique set of namespaces specified in an R script
get_namespaces <- function(file, as_imports=FALSE) {
require(stringi)
require(dplyr)
nm <- readLines(file) %>%
stringi::stri_extract_all(regex='[\\w_.]+::[\\w_.]+') %>%
unlist %>%
setdiff(NA) %>%
sort