Suggestions for Making Your R Code Spookier

By Max Candocia

|

October 25, 2017

The air is getting colder, and sometimes you just want to add some pizzazz to your R code. Here are some tips for making it spookier this frightful season.

  1. Display your code using a black-and-orange font
    message <- 'Happy Halloween!'
    print(message)
    
    ## [1] "Happy Halloween!"
    
  2. Use the numbers 13 and 666 in your code when an arbitrary constant would do
    set.seed(13*666)
    
  3. Make aliases for common functions or values using spooky words
      scare <- split
      wearing <- 13
      a <- 3
      at <- 13
      children <- rnorm
      night <- factor
      mask <- 0.5
      with.a.knife <- rbinom
      #final result
      scare(children(at), night(with.a.knife(wearing,a,mask)))
    
    ## $`0`
    ## [1] -0.63227650  0.25124949  0.02002853
    ## 
    ## $`1`
    ## [1]  1.0604516 -0.8714481 -1.5192590 -0.1055185
    ## 
    ## $`2`
    ## [1] -0.3264258 -0.2820896 -1.3271632
    ## 
    ## $`3`
    ## [1] 0.6829790 0.2338166 0.7319324
    
  4. Even better, give people nightmares by using non-ASCII characters
    BÓO <- print
    BOOÓ  <- 'sp00ky'
    BØO <- paste0
    BØØ <- 4
    BØØØ <- 'me'
    #final result
    BÓO(BØO((BØØ+BØØ)/BØØ,BOOÓ,BØØ,BØØØ))
    
    ## [1] "2sp00ky4me"
    
  5. Secretly and silently assign aliases as global variables
    begin.haunting <- function(){eval(parse(text=paste(paste(letters[c(19,3,1,18,5)], collapse=''),'<<-','scale')))}
    begin.haunting()
    scare(children(wearing,a,mask))
    
    ##               [,1]
    ##  [1,]  1.593613953
    ##  [2,] -1.731931186
    ##  [3,]  0.399275593
    ##  [4,]  1.539873180
    ##  [5,] -0.777245280
    ##  [6,] -0.414935945
    ##  [7,] -0.418567316
    ##  [8,] -0.347359526
    ##  [9,]  0.374395222
    ## [10,]  0.472213043
    ## [11,]  0.007651959
    ## [12,]  0.712623270
    ## [13,] -1.409606969
    ## attr(,"scaled:center")
    ## [1] 2.950584
    ## attr(,"scaled:scale")
    ## [1] 0.4758116
    
  6. Combine all of these into obfuscated functions that produces non-iid random, complex variables, and then build a model using the real and imaginary components
    sp00ky <- function(reality, nightmare=0) complex(real=reality, imaginary=nightmare)
    BÓOÓO <- function(x, ...){eval(parse(text=paste0('BÓØ',x,'<<-',letters[1],letters[19],'sign')))}
    BÓOOÓO <- function(x, ...) ifelse(1:length(x) %% 2 == 1, BÓOÓ(x, ...), BOOÓ(x, ...))
    BÓOÓ <- function(x, ...) ifelse(x %% 2 ==1, 0, x)
    BOOÓ <- function(x, ...) ifelse(x %% 2 ==0, 0, x)
    BÓÓÓ <- function(x, ...) sp00ky(reality=BÓOOÓO(x), nightmare=sp00ky(reality=x)-BÓOOÓO(x))
    BÓÓOÓO <- function(x, ...) BØØØ(x)^2
    BÓØÓØ <- function(x) rep(1, length(x))
    BÓØ <- function(x, ...) ifelse(BÓØÓØ(x) * length(unique(x))==1, rep(0, length(x)), scale(x))
    BØØÓ <- function(x, ...){Ó = pmax(1e-12, abs(x)); sp00ky(reality=BÓØ(Re(x/Ó)), nightmare=BÓØ(Im(x/Ó)))}
    BØØØ  <- function(x, Ø, ...) {BÓØØ('ØØ',  BÓÓÓ(x) - sp00ky(reality=Ø)); BØØÓ(ØØ)}
    BØO <- function(x, a, r) {BÓØØ('n', length(x)); x[max(1,a-r):min(n,a+r)]}
    BØOO <- function(x, a, r, ...) {s = BØO(x, a, r, ...); y = ØO(1:length(x), a, r)-a; w=exp(-y^2/(2*r)); sum(s*w)/sum(w)}
    BØØO <- function(x, r, ...) {BÓØØ('n', length(x));m = numeric(n); for(a in 1:n){m[a] = BØOO(x, a, r) }; m}
    BÓØÓ <- function(x, r=3, v=1, ...) BØØO(BØØØ(x, ...)/BØØÓ(BÓÓÓ(x)), v)
    BÓOÓO('Ø')
    
    set.seed(13*666)
    i = rpois(2*13*13, 13)
    Ø = 13
    ÓÓ = BÓØÓ(i, Ø=Ø, v=Ø)
    sp00ky.df = data.frame(=Re(ÓÓ), BØØ=Im(ÓÓ))
    sp00ky.model = lm(BØØ ~ BØ, data=sp00ky.df)
    
    par(bg='black',col='orange',fg='orange',col.axis='orange',col.main='orange',col.lab='orange')
    plot(sp00ky.model$residuals, type='l',ylab='residual error', xlab='index', main='Residuals of Model Based on non-IID Variables')
    
    plot of chunk spooky5_image

Tags: 

Recommended Articles

Overlaying Density Heatmaps on Geographic Maps in R

In this example, I use noise complaint data from New York City to demonstrate how you can plot densities of events on a map, as well as how extreme the averages are.

The Community of Garlicoin, the New Meme Cryptocurrency

Garlicoin is the hottest new meme cryptocurrency. I surveyed about 200 of its enthusiasts to get a good idea of what the community looked like and what they thought about the cryptocurrency.