File: environments%2Cfunctions.R

package info (click to toggle)
r-cran-r.rsp 0.45.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,568 kB
  • sloc: javascript: 612; tcl: 304; sh: 18; makefile: 16
file content (46 lines) | stat: -rw-r--r-- 666 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
library("R.rsp")

## Report template
report <- function() {
  cat("Report:\n")
  cat(sprintf("a=%g\n", a))
  cat("------\n")
} # report()


## 1. Generate report()
a <- 1
s <- rstring(report)
cat(s)
a <- 2
rcat(report)
a <- 3
dummy <- rfile(report, output="")


## 2. Generate report() in custom environment
env <- new.env()
env$a <- 1
s <- rstring(report, envir=env)
cat(s)

env$a <- 2
rcat(report, envir=env)

env$a <- 3
dummy <- rfile(report, output="", envir=env)



## 3. Generate report() within another function
foo <- function() {
  a <- 1
  s <- rstring(report)
  cat(s)
  a <- 2
  rcat(report)
  a <- 3
  dummy <- rfile(report, output="")
} # foo()

foo()