File: RspDocument.toR.R

package info (click to toggle)
r-cran-r.rsp 0.46.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,472 kB
  • sloc: javascript: 612; tcl: 304; sh: 18; makefile: 16
file content (75 lines) | stat: -rw-r--r-- 1,840 bytes parent folder | download | duplicates (2)
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
#########################################################################/**
# @set "class=RspDocument"
# @RdocMethod toR
#
# @title "Translates the RSP document into R source code"
#
# \description{
#  @get "title".
# }
#
# @synopsis
#
# \arguments{
#   \item{factory}{A @see "RspSourceCodeFactory".}
#   \item{...}{Optional arguments passed to \code{toSourceCode()} for
#              the @see "RspSourceCodeFactory".}
# }
#
# \value{
#  Returns the R source code as an @see "RspRSourceCode".
# }
#
# @author
#
# \seealso{
#   @seeclass
# }
#*/#########################################################################
setMethodS3("toR", "RspDocument", function(object, factory=NULL, ...) {
  if (is.null(factory)) {
    language <- getMetadata(object, "language", default="R")
    language <- capitalize(tolower(language))
    className <- sprintf("Rsp%sSourceCodeFactory", language)
    ns <- getNamespace("R.rsp")
    clazz <- Class$forName(className, envir=ns)
    factory <- newInstance(clazz)
  }
  
  # Argument 'factory':
  factory <- Arguments$getInstanceOf(factory, "RspSourceCodeFactory")

  toSourceCode(factory, object, ...)
}) # toR()


#########################################################################/**
# @RdocMethod evaluate
#
# @title "Parses, translates, and evaluates the RSP document"
#
# \description{
#  @get "title".
# }
#
# @synopsis
#
# \arguments{
#   \item{envir}{The @environment where the RSP document is evaluated.}
#   \item{...}{Not used.}
# }
#
# \value{
#  Returns the last evaluated expression, iff any.
# }
#
# @author
#
# \seealso{
#   @seeclass
# }
#*/#########################################################################
setMethodS3("evaluate", "RspDocument", function(object, envir=parent.frame(), ...) {
  code <- toR(object)
  process(code, envir=envir, ...)
}, createGeneric=FALSE)