| 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 |
|
|
|
9 |
## Should work WHEREVER this is called from :
|
|
|
10 |
(cd `dirname $0`/..
|
| 5290 |
hornik |
11 |
R_HOME=`pwd`; export R_HOME
|
| 2686 |
hornik |
12 |
)
|
| 4580 |
hornik |
13 |
R_HOME=`cd ${R_HOME}; pwd` # absolute
|
| 2686 |
hornik |
14 |
|
| 5290 |
hornik |
15 |
PKG=${1}; shift; FILES="${@}"
|
| 2686 |
hornik |
16 |
|
|
|
17 |
## 1) ---- Header ----
|
|
|
18 |
(cat <<_EOF_
|
| 5290 |
hornik |
19 |
attach(NULL, name = "CheckExEnv")
|
|
|
20 |
assign(".CheckExEnv", pos.to.env(2), pos = length(search()))
|
|
|
21 |
assign("ptime", proc.time(), env = .CheckExEnv)
|
|
|
22 |
postscript("PKG-Examples.ps")
|
|
|
23 |
assign("par.postscript", par(no.readonly = TRUE), env = .CheckExEnv)
|
|
|
24 |
options(contrasts = c(unordered = "contr.treatment", ordered = "contr.poly"))
|
| 2686 |
hornik |
25 |
_EOF_
|
|
|
26 |
) | sed "s/PKG/${PKG}/"
|
| 5290 |
hornik |
27 |
if [ "${PKG}" != "base" ]; then echo "library('${PKG}')" ; fi
|
| 2686 |
hornik |
28 |
|
|
|
29 |
## 2) ---- edit a few of these files:
|
| 5290 |
hornik |
30 |
for file in ${FILES}
|
| 2686 |
hornik |
31 |
do
|
| 5290 |
hornik |
32 |
bf=`basename $file .R`
|
|
|
33 |
if test -n "`grep '_ Examples _' $file`"; then
|
|
|
34 |
echo "rm(list = ls(all = TRUE)); .Random.seed <- c(0,rep(7654,3))"
|
|
|
35 |
fi
|
| 2686 |
hornik |
36 |
|
| 5290 |
hornik |
37 |
cat ${file}
|
| 2686 |
hornik |
38 |
|
| 5290 |
hornik |
39 |
if test -n "`grep 'par(' ${file}`"; then
|
| 2686 |
hornik |
40 |
## if there were 'par(..)' calls, now reset them:
|
| 5290 |
hornik |
41 |
echo 'par(get("par.postscript", env = .CheckExEnv))'
|
|
|
42 |
fi
|
|
|
43 |
if test -n "`grep 'options(contrasts' ${file}`"; then
|
| 4562 |
pd |
44 |
## if contrasts were set, now reset them:
|
| 5290 |
hornik |
45 |
echo 'options(contrasts = c(unordered = "contr.treatment", ordered = "contr.poly"))'
|
|
|
46 |
fi
|
| 2686 |
hornik |
47 |
done
|
| 5290 |
hornik |
48 |
|
| 2686 |
hornik |
49 |
## 3) ---- Footer ----
|
|
|
50 |
cat <<_EOF_
|
| 5290 |
hornik |
51 |
cat("Time elapsed: ", proc.time() - get("ptime", env = .CheckExEnv),"\n")
|
| 2686 |
hornik |
52 |
dev.off(); quit('no')
|
|
|
53 |
_EOF_
|
| 7218 |
hornik |
54 |
|
|
|
55 |
### Local Variables: ***
|
|
|
56 |
### mode: sh ***
|
|
|
57 |
### sh-indentation: 2 ***
|
|
|
58 |
### End: ***
|