R/form.R

Defines functions form

Documented in form

form <- function(..., cat = TRUE, perl = "perl", form.options) {
    oo <- getOption("useFancyQuotes")
    options(useFancyQuotes = FALSE)
    on.exit(options(useFancyQuotes = oo))

    s <- list(...)
    vecs <- lengths(s) > 1L
    if (any(vecs)) {
        for (i in which(vecs)) {
            s[[i]] <- paste(as.character(s[[i]]), collapse = "\r")
        }
    }
    s <- unlist(s)
    cmd <- paste(dQuote(s), collapse = ",", sep = "")

    opts <- if (!missing(form.options)) {
                paste0("{",
                       paste(paste(names(form.options), "=>", dQuote(form.options)),
                             collapse = ", "),
                       "}, ")
            } else ""
                    
    cmd <- paste0("use Perl6::Form; print form ", opts, " ", cmd, ";")
    res <- system2(perl, args = paste("-e ", shQuote(cmd)), stdout = TRUE)
    if (cat) {
        cat(paste(res, collapse ="\n"), "\n")
        invisible(res)
    } else
        res
}
enricoschumann/Perl6.Form documentation built on Nov. 17, 2021, 6:55 a.m.