| 2686 |
hornik |
1 |
#!/bin/sh
|
| 5290 |
hornik |
2 |
## R_HOME/bin/massage-Examples
|
|
|
3 |
## Given a list of files of the form .../.../<name>.R, produce one large
|
|
|
4 |
## file, i.e. write to stdout, `cat'ting the files together with
|
|
|
5 |
## 1) Putting a HEADER in front
|
|
|
6 |
## 2) Wrapping every file in order to be more order independent
|
|
|
7 |
## 3) appending a FOOTER ...
|
| 2686 |
hornik |
8 |
|
| 5290 |
hornik |
9 |
PKG=${1}; shift; FILES="${@}"
|
| 2686 |
hornik |
10 |
|
|
|
11 |
## 1) ---- Header ----
|
|
|
12 |
(cat <<_EOF_
|
| 5290 |
hornik |
13 |
attach(NULL, name = "CheckExEnv")
|
|
|
14 |
assign(".CheckExEnv", pos.to.env(2), pos = length(search()))
|
|
|
15 |
assign("ptime", proc.time(), env = .CheckExEnv)
|
|
|
16 |
postscript("PKG-Examples.ps")
|
|
|
17 |
assign("par.postscript", par(no.readonly = TRUE), env = .CheckExEnv)
|
|
|
18 |
options(contrasts = c(unordered = "contr.treatment", ordered = "contr.poly"))
|
| 2686 |
hornik |
19 |
_EOF_
|
|
|
20 |
) | sed "s/PKG/${PKG}/"
|
| 9548 |
ripley |
21 |
if [ "${PKG}" = "tcltk" ]; then
|
|
|
22 |
echo "require('tcltk') || q()"
|
|
|
23 |
else
|
|
|
24 |
if [ "${PKG}" != "base" ]; then echo "library('${PKG}')" ; fi
|
|
|
25 |
fi
|
| 2686 |
hornik |
26 |
|
|
|
27 |
## 2) ---- edit a few of these files:
|
| 5290 |
hornik |
28 |
for file in ${FILES}
|
| 2686 |
hornik |
29 |
do
|
| 5290 |
hornik |
30 |
bf=`basename $file .R`
|
|
|
31 |
if test -n "`grep '_ Examples _' $file`"; then
|
|
|
32 |
echo "rm(list = ls(all = TRUE)); .Random.seed <- c(0,rep(7654,3))"
|
|
|
33 |
fi
|
| 2686 |
hornik |
34 |
|
| 5290 |
hornik |
35 |
cat ${file}
|
| 2686 |
hornik |
36 |
|
| 5290 |
hornik |
37 |
if test -n "`grep 'par(' ${file}`"; then
|
| 2686 |
hornik |
38 |
## if there were 'par(..)' calls, now reset them:
|
| 5290 |
hornik |
39 |
echo 'par(get("par.postscript", env = .CheckExEnv))'
|
|
|
40 |
fi
|
|
|
41 |
if test -n "`grep 'options(contrasts' ${file}`"; then
|
| 4562 |
pd |
42 |
## if contrasts were set, now reset them:
|
| 5290 |
hornik |
43 |
echo 'options(contrasts = c(unordered = "contr.treatment", ordered = "contr.poly"))'
|
|
|
44 |
fi
|
| 2686 |
hornik |
45 |
done
|
| 5290 |
hornik |
46 |
|
| 2686 |
hornik |
47 |
## 3) ---- Footer ----
|
|
|
48 |
cat <<_EOF_
|
| 5290 |
hornik |
49 |
cat("Time elapsed: ", proc.time() - get("ptime", env = .CheckExEnv),"\n")
|
| 2686 |
hornik |
50 |
dev.off(); quit('no')
|
|
|
51 |
_EOF_
|
| 7218 |
hornik |
52 |
|
|
|
53 |
### Local Variables: ***
|
|
|
54 |
### mode: sh ***
|
|
|
55 |
### sh-indentation: 2 ***
|
|
|
56 |
### End: ***
|