1
###########################################################################/**
2
# @RdocClass RspSourceCode
3
#
4
# @title "The RspSourceCode class"
5
#
6
# \description{
7
#  @classhierarchy
8
#
9
#  An RspSourceCode object is a @character @vector holding RSP generated
10
#  source code for a particular programming language.
11
# }
12
#
13
# @synopsis
14
#
15
# \arguments{
16
#   \item{code}{@character @vector.}
17
#   \item{...}{Additional arguments passed to the @see "RspProduct"
18
#     constructor.}
19
# }
20
#
21
# \section{Fields and Methods}{
22
#  @allmethods
23
# }
24
#
25
# @author
26
#
27
# @keyword internal
28
#*/###########################################################################
29
setConstructorS3("RspSourceCode", function(code=character(), ...) {
30 1
  extend(RspProduct(code, ...), "RspSourceCode")
31
})
32

33

34
setMethodS3("print", "RspSourceCode", function(x, ...) {
35 1
  code <- x
36 1
  code <- paste(code, collapse="\n")
37 1
  cat(code)
38 1
  cat("\n")
39
})
40

41

42

43
#########################################################################/**
44
# @RdocMethod evaluate
45
#
46
# @title "Evaluates the source code"
47
#
48
# \description{
49
#  @get "title".
50
# }
51
#
52
# @synopsis
53
#
54
# \arguments{
55
#   \item{...}{Not used.}
56
# }
57
#
58
# \value{
59
#  Returns the last evaluated expression, iff any.
60
# }
61
#
62
# @author
63
#
64
# \seealso{
65
#   @seeclass
66
# }
67
#*/#########################################################################
68
setMethodS3("evaluate", "RspSourceCode", abstract=TRUE, createGeneric=FALSE)
69

70

71

72
#########################################################################/**
73
# @RdocMethod tangle
74
# @alias tangle.RspRSourceCode
75
#
76
# @title "Drops all text-outputting calls from the source code"
77
#
78
# \description{
79
#  @get "title".
80
# }
81
#
82
# @synopsis
83
#
84
# \arguments{
85
#   \item{...}{Not used.}
86
# }
87
#
88
# \value{
89
#  Returns a @see "RspSourceCode" objects.
90
# }
91
#
92
# @author
93
#
94
# \seealso{
95
#   @seeclass
96
# }
97
#*/#########################################################################
98
setMethodS3("tangle", "RspSourceCode", abstract=TRUE)
99

100

101
#########################################################################/**
102
# @RdocMethod tidy
103
# @alias tidy.RspRSourceCode
104
#
105
# @title "Tidy up the RSP source code"
106
#
107
# \description{
108
#  @get "title".
109
# }
110
#
111
# @synopsis
112
#
113
# \arguments{
114
#   \item{format}{A @character string specifying how the source code
115
#     should be tidied.}
116
#   \item{collapse}{How source code lines should be collapsed.}
117
#   \item{...}{Not used.}
118
# }
119
#
120
# \value{
121
#  Returns an @RspSourceCode of the same class as the input source code.
122
# }
123
#
124
# @author
125
#
126
# \seealso{
127
#   @seeclass
128
# }
129
#*/#########################################################################
130
setMethodS3("tidy", "RspSourceCode", function(object, format=c("asis"), collapse="\n", ...) {
131
  # Argument 'format':
132 0
  format <- match.arg(format)
133

134
  # Record attributes
135 0
  attrs <- attributes(object)
136

137
  # Collapse?
138 0
  if (!is.null(collapse)) {
139 0
    object <- paste(object, collapse=collapse)
140
  }
141

142
  # Restore attributes (if lost above)
143 0
  attributes(object) <- attrs
144

145 0
  object
146
})

Read our documentation on viewing source code .

Loading