R/utils.R

Defines functions process_on_exit sexp_address create_duplicate reassign_function_body

reassign_function_body <- function(fun, body) {
    invisible(.Call(reassign_function_body_, fun, body))
}

#' @export
create_duplicate <- function(x) {
    .Call(create_duplicate_, x)
}

#' @export
sexp_address <- function(x) {
    .Call(sexp_address_, x)
}

## TODO: Fix implementation to properly handle the complete call signature of on.exit
process_on_exit <- function(expr) {
    if(typeof(expr) == "language") {
        if(expr[[1]] == "on.exit") {
            expr[[3]] <- TRUE
            expr[[4]] <- FALSE
        }
        else {
            l <- length(expr)
            for(i in 1:l) {
                ## NOTE: expr[[i]] is used inplace to avoid missingness
                ##       errors in expressions of the form x[,i]
                if(typeof(expr[[i]]) == "language") {
                    expr[[i]] <- process_on_exit(expr[[i]])
                }
            }
        }
    }
    expr
}
PRL-PRG/injectr documentation built on July 7, 2020, 6:44 p.m.