1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
###########################################################################/**
# @RdocClass RspSourceCode
#
# @title "The RspSourceCode class"
#
# \description{
# @classhierarchy
#
# An RspSourceCode object is a @character @vector holding RSP generated
# source code for a particular programming language.
# }
#
# @synopsis
#
# \arguments{
# \item{code}{@character @vector.}
# \item{...}{Additional arguments passed to the @see "RspProduct"
# constructor.}
# }
#
# \section{Fields and Methods}{
# @allmethods
# }
#
# @author
#
# @keyword internal
#*/###########################################################################
setConstructorS3("RspSourceCode", function(code=character(), ...) {
extend(RspProduct(code, ...), "RspSourceCode")
})
setMethodS3("print", "RspSourceCode", function(x, ...) {
code <- x
code <- paste(code, collapse="\n")
cat(code)
cat("\n")
})
#########################################################################/**
# @RdocMethod evaluate
#
# @title "Evaluates the source code"
#
# \description{
# @get "title".
# }
#
# @synopsis
#
# \arguments{
# \item{...}{Not used.}
# }
#
# \value{
# Returns the last evaluated expression, iff any.
# }
#
# @author
#
# \seealso{
# @seeclass
# }
#*/#########################################################################
setMethodS3("evaluate", "RspSourceCode", abstract=TRUE, createGeneric=FALSE)
#########################################################################/**
# @RdocMethod tangle
# @alias tangle.RspRSourceCode
#
# @title "Drops all text-outputting calls from the source code"
#
# \description{
# @get "title".
# }
#
# @synopsis
#
# \arguments{
# \item{...}{Not used.}
# }
#
# \value{
# Returns a @see "RspSourceCode" objects.
# }
#
# @author
#
# \seealso{
# @seeclass
# }
#*/#########################################################################
setMethodS3("tangle", "RspSourceCode", abstract=TRUE)
#########################################################################/**
# @RdocMethod tidy
# @alias tidy.RspRSourceCode
#
# @title "Tidy up the RSP source code"
#
# \description{
# @get "title".
# }
#
# @synopsis
#
# \arguments{
# \item{format}{A @character string specifying how the source code
# should be tidied.}
# \item{collapse}{How source code lines should be collapsed.}
# \item{...}{Not used.}
# }
#
# \value{
# Returns an @RspSourceCode of the same class as the input source code.
# }
#
# @author
#
# \seealso{
# @seeclass
# }
#*/#########################################################################
setMethodS3("tidy", "RspSourceCode", function(object, format=c("asis"), collapse="\n", ...) {
# Argument 'format':
format <- match.arg(format)
# Record attributes
attrs <- attributes(object)
# Collapse?
if (!is.null(collapse)) {
object <- paste(object, collapse=collapse)
}
# Restore attributes (if lost above)
attributes(object) <- attrs
object
})
|