The R Project SVN R

Rev

Rev 5281 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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