batchfiles contains batch and GUI files for installing and maintaing R.  

NEWS.  See NEWS file.

INSTALLATION

To install these utilities, note that all these commands have
no dependencies so just copy all the .bat and .hta (or just the ones
you want) to any directory in your PATH.  The Windows console 
command

   path

after which you will be able to run them by just issuing their
name and any arguments.

BATCH & JAVASCRIPT PROGRAMS (also see separate section for perl programs)

0. runR.bat
1. R.bat, Rcmd.bat, Rscript.bat, Rgui.bat, JGR.bat
2. #Rscript.bat
3. RguiStart.bat
4. sweave.bat
5. Rversions.hta
6. copydir.bat
7. movedir.bat
6. Rversions.bat


0. runR.bat.  If this file is copied to myfile.bat then running 
myfile (possibly with arguments) will run myfile.R with those same
arguments.

1. R.bat, Rcmd.bat, Rscript.bat, Rgui.bat, Rscript.bat,
JGR.bat - are front ends to  the corresponding .exe files.
They locate R in the registry (and also look in a few other
places if not found there) and then run the found R.exe,
Rcmd.exe, Rscript.exe, Rgui.exe or JGR.exe with the same
arguments.    They are actually all the same file just
renamed.  (RguiStart.bat described separately is also the
same file and all the code from this file is also at the end
of sweave.bat, also described separately.)  The file checks
what name it was called by and acts accordingly.

Their main advantages are:
- you don't have to modify your path just to use R.
- when you upgrade R they automatically work without change
  since they will pick up the new version from the registry
  automatically.

You can put Rgui.bat on your desktop and associate a Windows
ShortCut key (http://support.microsoft.com/kb/310417) with
it such as R so that you can just press the Windows key and
R, say, to activate R.

Here are some examples of using them from the command line:

	Rcmd INSTALL mypackage
	Rcmd INSTALL mypackage -l library
	Rcmd check mypackage 
	Rcmd build mypackage
	Rcmd build mypackage --binary
	Rscript myprog.R < mydata.dat
	Rgui

Older version of the Rcmd BATCH command in R had problems
with spaces in pathnames so be sure you use a sufficiently
recent version of R.  If you are using an old version of R
that has problems use the short name corresponding to any
long name with spaces:

For example, suppose we have a file 
   C:\Documents and Settings\Administrator\myfile.R .
Then try this:

	cd \
	dir/x doc*
	Rcmd BATCH c:\docume~1\Administrator\myfile.R

where the dir/x command showed us the short name corresponding to
the longer space-embedded name: Documents and Settings.  

2. #Rscript.bat

#Rscript.bat can be used as the first line of an R script to make 
it callable as a batch file.  For example, if we have a myfile.R
file then we can create a myfile.bat file that looks like this:

#Rscript %0 %*
...R code from myfile.R goes here...

and now we can just issue the command myfile to run it.  We
no longer need myfile.R.

See the Rtidy.bat file for an example.  Note that it does have 
the disadvantage that the output of the R program starts off 
with the command itself.  R needs to be able to handle the 
perl/python/ruby -x switch.  In the meantime #Rscript.bat 
will mainly be useful for those scripts where the output does 
not go to the standard output or where the addition of this 
line is acceptable.

3. RguiStart.bat

This is like Rgui.bat except it intercepts the first argument
and interprets it as the folder in which to start R (or if its
an .Rdata file then it interprets it as the .Rdata file to start 
R with).  The main reason for its existence is so that you can 
place it in your SendTo folder.  On Vista do this:

  copy RguiStart.bat %APPDATA%\Microsoft\Windows\SendTo

Then, on Vista, when you are in Windows Explorer you can right click 
on any folder in your user area and choose SendTo.  From the SendTo
menu choose RGuiStart.bat to start up R in that folder.  If you 
right click on an .Rdata file rather than a folder then R will
start up with that file loaded (although in that case its probably
easier to just double click the .Rdata file provided you have
file type associations set up -- if you don't then the RguiStart.bat
will provide an alternative).

Another possibility is to just shift right click a folder in Windows
Explorer and choose Open Command Window Here and then when the command
window opens enter Rgui assuming you have placed Rgui.bat somewhere in
your path.

4. sweave.bat - will run sweave, then pdflatex and then
display latex file.  Requires Rterm.bat .  e.g.

      sweave mydoc.Rnw
   or
      sweave mydoc 

The script runs sweave, pdflatex and then displays the pdf
file (assuming the user has .pdf extension associated with a
pdf viewer).  If there is an error in sweave or the .tex
file is not newer than the sweaved file the script stops.
Similarly if there is an error in pdflatex or the .pdf is
not newer than the .tex file then the script stops.  Note
that _two_ .pdf files are generated.  They are identical
except one has a unique name created by suffixing the base
with the date and time and .bck.pdf.  The one with the unique name 
is the one viewed.  This overcomes problems of not being able to
view the .pdf if the .pdf from a prior run is current being
viewed (which would happen since by default the Acrobat viewer 
won't allow you to view two files of the same name concurrently).
Every so often the user should delete all *.bck.pdf files.

Try:

sweave

without arguments to see options and get more info.

Aside from using sweave from the command line, if you place
sweave.bat in your SendTo folder as discussed under
RguiStart.bat you can right click .Rnw files and choose
SendTo > sweave to sweave them.

5. Rversions.hta - This displays a GUI that lists all
versions of R on your system  and allows you to choose one
as your default, setting the  registry appropriately.  Just
run without arguments, .e.g.  

	Rversions.hta 

For example, suppose we want to check a package using two
different versions of R.  Then run 

	Rcmd check mypkg

	:: in next command set different version of R
	Rversions.hta 
	Rcmd check mypkg

	:: in next command reset to original version of R
	Rversions.hta 

5. Rversions.bat - similar to Rversions.hta but 
-- its batch whereas Rversions.hta is GUI
-- uses slightly different heuristic to find R versions
-- run without args to list versions available; run with any of
   the listed versions to set that as the new version
-- both forms work on XP; to run arg form on Vista run it elevated

Examples:

	:: list R versions
	rversions.bat

	:: check mypkg using R current version, 2.4.0, say
	Rcmd check mypkg

	:: switch to version R-2.5.0 and recheck
	rversions R-2.5.0
	Rcmd check mypkg

	:: reset back to version 2.4.0
	rversions.bat R-2.4.0

6. copydir.bat - can be used to copy the libraries from an
old version of R to your new one.  It will not overwrite any
libraries already there so it should be safe to use. e.g. to
upgrade R to a new version

  :: Example is for upgrading from R-2.4.1 to R-2.5.0

  :: first, download and install R-2.5.0, say
  :: now perform the next two commands at the Windows console
  cd \Program Files\R
  copydir R-2.4.1\library R-2.5.0\library

  :: next command only needed if you have *.site files
  copy R-2.4.0\etc\*.site R-2.5.0\etc

  :: ... now startup new version of R (R 2.5.0 in this example)
  # issue this command in R 2.5.0
  update.packages(checkBuilt = TRUE, ask = "graphics")
  # or (see note below)
  update.packages(ask = "graphics")

  :: press OK and it will update those packages as necessary

  # ... optionally check for deprecated packages
  # 1. first select all repositories that you use with menu:
  #    Packages | Repositories
  # 2. second check if there are any deprecated packages that
  #    were copied over but are not longer on CRAN or other repository
  dp <- setdiff(installed.packages()[,1], available.packages()[,1])
  # look at what we have
  dp
  # if you wish to remove them issue the remove.packages command:
  # remove.packages(dp)

  :: ... exit R and start it up again ...

Note that the checkBuilt=TRUE argument will potentially
cause all your packages to be downloaded again so you could
try leaving it off and then reissue the command with
checkBuilt=TRUE later only if you run into problems.  I
normally do it without the checkBuilt=TRUE.

It is anticipated that this command will ultimately be
superceded by functionality in the R setup procedure at
which time this will be deprecated.  Note that this method
of just copying libraries may not work depending on the
versions of R involved.  If its necessary to re-install most
packages it can be done by issuing the following R command
after performing the copydir.bat:
install.packages(installed.packages()[,1])
 
(Note that 2.8 of the R Windows FAQ

http://cran.r-project.org/bin/windows/base/rw-FAQ.html#What_0027s-the-best-way-to-upgrade_003f

refers to copying any installed package to the library
folder but does not address how to accomplish that.  That
omission is what copydir.bat addresses.)

An alternative to copydir is to reinstall all packages

	# Alternative to copydir.bat #1
	# this example is for moving from 2.4.1 to 2.5.0
	# run this in R 2.5.0
	setwd(R.home())
	ip <- installed.packages(lib.loc = "../R-2.4.1/library")
	ip <- ip[ip[,1]!="base" ,1]
	install.packages(ip)

The above is taken from:
https://www.stat.math.ethz.ch/pipermail/r-help/2007-May/131806.html
Note that you may still have to use movedir.bat or copydir.bat
after the above if it fails to install everything.  Since movedir.bat
and copydir.bat won't overwrite anything this should be safe.

	# Alternative to copydir.bat #2
	#---run in previous version, e.g. R 2.4.1
	packages <- installed.packages()[,"Package"]
	save(packages, file = "~/Rpackages")

	#---run in new version, e.g. R 2.5.0
	load("~/Rpackages")
	install.packages(setdiff(packages, installed.packages()[,"Package"]))

	file.remove("~/Rpackages")

This copydir alternative is based on:
https://www.stat.math.ethz.ch/pipermail/r-help/2007-May/131131.html

7. movedir - same arguments as copydir.  Only difference is
that it moves the directories rather than copying them.  This
can be used if you are no longer interested in using the
packages with the old version of R other than by
reinstalling them.)  This has the advantage that its much
faster than copydir.  The example under copydir works with
movedir too.  Just replace copydir with movedir in that
example.  Comments under copydir.bat apply here too.  I
mostly use movedir.bat myself instead of copydir.bat since
its so much faster.

PERL PROGRAMS

There is one perl program, toggleDoc.pl, provided in this collection.

The perl program is independent of all other programs in this
collection.  It does not depend on any other program here
and no other program here depends on it.

Unlike the other programs in this collection, this program 
requires perl to run and has a dependency on toggleDoc.js.  

toggleDoc.pl - Modifies the 00Index.html file of every
package in .../library adding a "Show All" toggle box to
each 00Index.html file.  When this box is unchecked it will
collapse and reduce similar lines into a single line.  Look at:

 http://www.menne-biomed.de/download/toggleDoc/00Index.html

The web page displayed is an example of the web pages output
from toggleDoc.pl.  Try checking and unchecking the Show all
box to get a better idea of what it does.  toggleDoc.txt has
additional documentation.  To run this program requires that
you install perl.  After that place toggleDoc.pl and
toggleDoc.js in your R .../library folder, change directory
to the .../library folder and run toggleDoc.pl without
arguments: 

perl toggleDoc.pl 

toggleDoc was contributed by Dieter Menne 
<dieter.menne@menne-biomed.de>

DEPRECATED AND CHANGED

- Rfind.bat, makepkg.bat and Rversions.bat are no longer
  distributed in the batchfiles collection but are still
  available in version 0.2-3 of batchfiles if you want them.
  It is unknown whether they work with Vista and recent
  versions of R.  (I have not used them in some time so
  am no longer maintaining them.)  If you used Rversions.bat
  before you can still use Rversions.hta, the GUI version
  of the program -- that one is still part of the collection.

ADDITIONAL FILES

1. RESOURCES - additional information on writing Windows XP batch files.

2. COPYRIGHT and COPYING - this is free software subject to the GPL license 
   as described.

3. THANKS - acknowledgments.

