The R Project SVN R

Rev

Rev 9548 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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