1
#########################################################################/**
2
# @set "class=RspDocument"
3
# @RdocMethod toR
4
#
5
# @title "Translates the RSP document into R source code"
6
#
7
# \description{
8
#  @get "title".
9
# }
10
#
11
# @synopsis
12
#
13
# \arguments{
14
#   \item{factory}{A @see "RspSourceCodeFactory".}
15
#   \item{...}{Optional arguments passed to \code{toSourceCode()} for
16
#              the @see "RspSourceCodeFactory".}
17
# }
18
#
19
# \value{
20
#  Returns the R source code as an @see "RspRSourceCode".
21
# }
22
#
23
# @author
24
#
25
# \seealso{
26
#   @seeclass
27
# }
28
#*/#########################################################################
29
setMethodS3("toR", "RspDocument", function(object, factory=NULL, ...) {
30 1
  if (is.null(factory)) {
31 1
    language <- getMetadata(object, "language", default="R")
32 1
    language <- capitalize(tolower(language))
33 1
    className <- sprintf("Rsp%sSourceCodeFactory", language)
34 1
    ns <- getNamespace("R.rsp")
35 1
    clazz <- Class$forName(className, envir=ns)
36 1
    factory <- newInstance(clazz)
37
  }
38
  
39
  # Argument 'factory':
40 1
  factory <- Arguments$getInstanceOf(factory, "RspSourceCodeFactory")
41

42 1
  toSourceCode(factory, object, ...)
43
}) # toR()
44

45

46
#########################################################################/**
47
# @RdocMethod evaluate
48
#
49
# @title "Parses, translates, and evaluates the RSP document"
50
#
51
# \description{
52
#  @get "title".
53
# }
54
#
55
# @synopsis
56
#
57
# \arguments{
58
#   \item{envir}{The @environment where the RSP document is evaluated.}
59
#   \item{...}{Not used.}
60
# }
61
#
62
# \value{
63
#  Returns the last evaluated expression, iff any.
64
# }
65
#
66
# @author
67
#
68
# \seealso{
69
#   @seeclass
70
# }
71
#*/#########################################################################
72
setMethodS3("evaluate", "RspDocument", function(object, envir=parent.frame(), ...) {
73 0
  code <- toR(object)
74 0
  process(code, envir=envir, ...)
75
}, createGeneric=FALSE)

Read our documentation on viewing source code .

Loading