The R Project SVN R

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2686 hornik 1
#!/bin/sh
2
##--- NEW: ----------
3
##
4
## Given a list of files of the form    .../.../<name>.R,
5
##
6
## Produce one large file, i.e. write to  stdout
7
##  'cat'ting the files together with
8
##  1) Putting   a HEADER in front
9
##  2) Wrapping every file in order to be more order independent
10
##  3) appending a FOOTER ...
11
 
12
## Should work WHEREVER this is called from :
13
(cd `dirname $0`/..
4580 hornik 14
 R_HOME=`pwd`; export R_HOME
2686 hornik 15
)
4580 hornik 16
R_HOME=`cd ${R_HOME}; pwd`	# absolute
2686 hornik 17
 
18
PKG=$1; shift;
19
FILES="$@"
20
 
4580 hornik 21
#Dbg> echo "R_HOME=$R_HOME"; echo
2686 hornik 22
#Dbg> echo "FILES=$FILES"; echo ; echo; exit
23
 
24
## 1) ---- Header ----
25
(cat <<_EOF_
26
.ptime <- proc.time()
27
postscript('PKG-Examples.ps')
28
.par.postscript <- par(no.readonly = TRUE)
2825 maechler 29
options(contrasts = c(unordered = "contr.treatment", ordered =  "contr.poly"))
2686 hornik 30
_EOF_
31
) | sed "s/PKG/${PKG}/"
32
if [ "$PKG" != "base" ]; then echo "library('$PKG')" ; fi
33
 
34
## 2) ---- edit a few of these files:
35
for file in $FILES
36
do
37
 bf=`basename $file .R`
38
 if [ -n "`grep '_ Examples _' $file`" ]
39
 then
3076 pd 40
    echo '.Random.seed <- c(0,rep(7654,3)); rm(list = ls())'
2686 hornik 41
 else
42
    if [ "$USER" = maechler ];then
43
	## Remind certain people to upgrade the online help
44
	echo "'$bf' has no Examples.." >& 2
45
    fi
46
 fi
47
 
48
 cat $file
49
 
50
 if [ -n "`grep 'par(' $file`" ];then
51
    ## if there were 'par(..)' calls, now reset them:
52
    echo 'par(.par.postscript)'
53
 fi
4562 pd 54
 if [ -n "`grep 'options(contrasts' $file`" ];then
55
    ## if contrasts were set, now reset them:
56
    echo 'options(contrasts = c(unordered = "contr.treatment", ordered =  "contr.poly"))'
57
 fi
2686 hornik 58
done
59
## 3) ---- Footer ----
60
cat <<_EOF_
61
cat("Time elapsed: ", proc.time() - .ptime,"\n")
62
dev.off(); quit('no')
63
_EOF_