R/put.R

Defines functions put

# Assign inside dplyr chain
# http://jepusto.github.io/assigning-after-dplyr
# https://stackoverflow.com/questions/25975827
put <- function(x, name, where = NULL) {
    name_string <- deparse(substitute(name))
    if (is.null(where)) {
        sys_calls <- sys.calls()
        put_calls <- grepl("\\<put\\(", sys_calls) & !grepl("\\<put\\(\\.",sys_calls)
        where <- sys.frame(max(which(put_calls)) - 1)
    }
    assign(name_string, value = x, pos = where)
}
MikhaelManurung/mdmisc documentation built on March 19, 2020, 1:12 a.m.