Skip to content

Instantly share code, notes, and snippets.

def decorator(fn):
def f():
return "dec" + fn()
f.decorated=True
f.original_func = fn
return f
def decorator_override(fn):
def f():
if fn.decorated:
def decorator(f):
def f_new():
print "pre"
f()
print "post"
try:
f.decorated
return f
except AttributeError:
f_new.decorated=True
require(dplyr) # version 0.4.3
f1 <- function(x, y) { if (x < 5) y else if (x >= 5) y + 10 }
f2 <- function(x, y) { if (x < 5) y + 0 else if (x >= 5) y + 10 }
d <- data.frame(x=1:10, y=1:10)
d %>% rowwise() %>% mutate(z=f1(x, y))
# Error: incompatible types, expecting a integer vector
d %>% rowwise() %>% mutate(z=f2(x, y))
# Source: local data frame [10 x 3]
# Groups: <by row>