R/fixupCall.R

Defines functions `fixupCall`

## Non-exported function that can be used to fix up elements of a call
`fixupCall` <- function(object, element, value) {
    ## element must be character! Try to coerce
    element <- as.character(element)     ## Fails if not coercible
    .call <- getElement(object, "call")  ## get call from object
    .ll <- as.list(.call)                ## convert to a list to manipulate
    names(.ll) <- names(.call)           ## set names on the list
    ## if element not in names need to create it
    if (! element %in% names(.ll)) {
        new <- list(value)
        names(new) <- element
        .ll <- c(.ll, new)
    } else {
        ## otherwise just update it
        .ll[[element]] <- value              ## set element to value
    }
    .call <- as.call(.ll)                ## convert back to a call
    object$call <- .call                 ## push back into object
    object
}

Try the permute package in your browser

Any scripts or data that you put into this service are public.

permute documentation built on March 18, 2022, 7:36 p.m.