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

NEWS.  See NEWS file.

INSTALLATION

To use any of these utilities just make sure that they are either
in the current directory you are using or else are anywhere in your
PATH.  No installation is necessary.  The utilities are all 
written in Windows batch or javascript as HTA files and have
no dependencies.

Note that R.bat, Rcmd.bat, Rscript.bat, Rgui.bat, JGR.bat and RguiStart.bat
are actually all the same file.  When any of them are run they check what
name is was called by to determine what to do.  Similarly Sweave.bat and
Stangle.bat are the same file.

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

0. Rtools.bat
1. R.bat, Rcmd.bat, Rscript.bat, Rgui.bat, JGR.bat
2. #Rscript.bat
3. RguiStart.bat
4. Sweave.bat and Stangle.bat
5. Rversions.hta
6. copydir.bat
7. movedir.bat
6. Rversions.bat


0. Rtools.bat.  Sets path to what Rcmd.bat and others use internally.
This only sets the path for the current command shell instance.

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).  Then they look for Rtools and
MiKTeX and if found they add them temporarily to the path.  (Rtools and MiKTeX
are needed when building R packages from source but are not needed for just
running R nor are they need to download and install binary packages from CRAN.)
Then they run 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 run R.
- you don't have to modify your path to build R packages from source.
- when you upgrade R they automatically work without change
  since they will pick up the new version of R from the registry
  automatically.
- Sweave.bat and Stangle.bat, unlike, Rcmd Sweave and Rcmd Stangle
  do not depend on rtools.

You can put Rgui.bat on your desktop and associate a Windows
ShortCut key (http://support.microsoft.com/kb/310417) with
it 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.
It assumes you have placed el.js, Rcmd.bat and Rgui.bat in
your path.  el cmd spawns a command console with Administrator
rights.  This is needed to build HTML help but you can omit
the el command if you don't need that.

    el cmd
	Rcmd check mypackage 
	Rcmd build mypackage
	Rcmd build mypackage --binary
	Rcmd INSTALL mypackage_1.0-0.tar.gz
	Rcmd INSTALL mypackage_1.0-0.tar.gz -l library
	Rscript myprog.R < mydata.dat
	Rgui

(When installing packages on Vista it is recommended that
you do this from within a console session that has Administrator
rights.  It will typically work even without that; however, the
HTML help will not be created.)

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 and Stangle.bat - will run Sweave, then pdflatex and then
display latex file.  Stangle.bat will run Stangle producing an R file.
Unlike Rcmd Sweave and Rcmd Stangle these do not depend on rtools.
Sweave.bat and Stangle.bat are actually the same file.  The file determines
what to do by looking at the name by which it was called.

      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 Sweave'd 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.

You may need to copy Sweave.sty to the directory containing
your .Rnw sweave file to use sweave.bat .

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.

DEPRECATED AND CHANGED

- There was previously one perl program, toggleDoc.pl,
  provided in the collection which is no longer distributed
  but is still available with older distributions of
  batchfiles.  It adds a "Show All" toggle box to the
  00Index.html file of each package.


- 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.

