## = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = ## This is a self-contained R script generated from an RSP document. ## It may be evaluated using source() as is. ## = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = ## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ## Local RSP utility functions ## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ## RSP metadata function .rmeta <- list( ) rmeta <- function(...) { args <- list(...) if (length(args) == 0) return(.rmeta) names <- names(args) if (length(names) > 0) { for (name in names) .rmeta[[name]] <<- args[[name]] } else { names <- unlist(args, use.names=FALSE) if (length(names) == 1) .rmeta[[names]] else .rmeta[names] } } ## Look up 'base' function once (faster) if (getRversion() < "2.15.0") { .base_paste <- base::paste .base_paste0 <- function(...) .base_paste(..., sep="") } else { .base_paste0 <- base::paste0 } .base_cat <- base::cat ## RSP output function .rout <- function(x) .base_cat(.base_paste0(x)) ## RSP output function for inline RSP constructs .rout0 <- function(x) .base_cat(rpaste(x)) ## The output of inline RSP constructs is controlled by ## generic function rpaste(). rpaste <- function(...) UseMethod("rpaste") setInlineRsp <- function(class, fun, envir=parent.frame()) { name <- sprintf("rpaste.%s", class) assign(name, fun, envir=envir) ## FIXME: How to register an S3 method at run-time? /HB 2018-04-06 ## registerS3method("rpaste", class = class, method = name, envir = envir) } ## The default is to coerce to character and collapse without ## a separator. It is possible to override the default in an ## RSP code expression. setInlineRsp("default", function(x, ...) .base_paste0(x, collapse="")) ## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ## RSP source code script [BEGIN] ## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - .rout("Line #1\nLine #2\n") a <- 2 b <- 3 .rout("Line #3\n") ## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ## RSP source code script [END] ## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -