The R Project SVN R

Rev

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

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