メモ:正規表現でreplacement functionを使いたいときはbaseの関数が便利っぽい
formatRのコードを読んでいると、こんな箇所がありました。
m = gregexpr(mat.comment, text.mask) regmatches(text.mask, m) = lapply(regmatches(text.mask, m), restore_bs)
(https://github.com/yihui/formatR/blob/022da8c1be2c04c8374d19907c41bacd5d0ecfcc/R/tidy.R#L107-L108)
続きを読むRとウェブAPIに関する本をちょっと書きました。
メモ:dplyrのselect(data, col1:colN)みたいなやつはどう実現しているのか
select()
は内部的にはselect_vars()
を使っている。select_vars()
はさらに内部ではlazyeval::lazy_eval()
を呼び出している。
メモ:formulaはそのエンクロージング環境を捕捉している
とかかれているのをふと見かけてなるほどなあと思ったのでメモ。
# formulas automatically capture their enclosing environment foo <- function(x) { y <- 10 ~ x + y }
(https://github.com/hadley/rlang/blob/84a63a1a660cebff373b9db02ac37e04c934dbde/R/tidy-eval.R#L30-L34)
※rlangはlazyevalの後継のパッケージ
続きを読む