## = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = ## 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] ## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - oopts <- options(papersize="letter") # Just for reproducibility .rout("This text file illustrates how to use the RSP 'include' preprocessing\ndirective to include contents from other sources.\n\nThis includes a piece of text as is, which may\nnot be that exciting, but you can also include values of variable,\nR options and system environment variables. For instance, the\npaper size is set to 'letter' in R.\n\n") ps <- "letter" .rout("An RSP expression can contain preprocessing directives (but not the\nother way around). This can be used to assign R variables the value\nof preprocessing variables, e.g. papersize='") .rout0(ps) .rout("'.\n\nIt is also possible to include the contents of other files.\nFor instance, the file 'incl/include.txt.rsp', contains:\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \nThis paragraph was included via an RSP 'include' \npreprocessing directive!\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n\n<%@include file=\"birth.txt.rsp\"%>\n\n") date <- as.Date("2002-05-04") .rout("RSP first saw the light of day on ") .rout0(date) .rout(".\n") options(oopts) # undo ## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ## RSP source code script [END] ## - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -