My favorites | Sign in
Project Logo
       
Code license: GNU General Public License v2
Labels: R, Windows, batch

batchfiles contains batch (.bat) and javascript (.hta and .js) files useful in conjuction with R and R packages on Microsoft Windows. There is no formal installation, each consists of a single file and is independent of the others so just place any or all of them anywhere in your Windows path and you will be able to access them in any Windows console session. A list of the utilities is given below.

Version 0.5-0 on CRAN works with XP, Vista, Windows 7 and 32 and 64 bit Windows. (The older version 0.4-3, also on CRAN works on Vista only and an even older version 0.3-2, also on CRAN, works on XP only.)

Below on this page are sections on:

NEWS

In addition to the news listed here there is a NEWS file in the package with additional news. Also there is a README file in the package with documentation and a RESOURCES file in the package with general information on Windows batch files.

May 31/09. clip2r.js added to development area. This utility is typically called from a vim macro which places the buffer into the clipboard and then launches clip2r.js. It then pastes the clipboard into R. See comments in file for using it from vim.

May 26/09. #Rscript.bat with bug fixes was uploaded to the development area. It test.bat is an R file with #Rscript.bat $0 $* as the first line it can be run from the Windows cmd console as test, as test.bat or can be double clicked from Windows Explorer whereas previously some but not all of these worked and which ones worked varied. Thanks to Nicholas Hirschey for pointing this out and testing.

May 25/09. batchfiles_0.5-0.zip is now on CRAN and should appear on the mirrors shortly. The new features are listed here, a list of included programs is shown here and further documentation can be found in the README here.

May 23/09. Batch files in devel version now work with Windows XP, Vista, Windows 7 and both 32 and 64 bit Windows. Thanks to Nicholas Hirschey for testing and contributions.

May 23/09. In the devel version jgr.bat automatically locates both R and that R library holding the JGR package and passes their paths to jgr.exe. Thus jgr installation only involves placing jgr.exe anywhere on the Windows PATH and installing the JGR R package (and optionally setting the version of java using jselect.exe). Note that jgr.bat is still in development and is not currently recommended for use.

May 7/09. Added Q8 to Troubleshooting FAQ below.

Jan 22/09. Rversions.hta now sets the .RData association as well. Also RExcelVersion.hta is like Rversions.hta but has some visual enhancements and testing so it works on XP as well (both thanks to Erich Neuwirth). RExcelVersion.hta is intended for use with the RExcel Excel addin but there is nothing specific to RExcel so it can be used apart from it as well. RExcelVersion.hta may eventually replace Rversions.hta; however, there may still be some development on it prior to that so for the moment its being kept separate.

Dec 12/08. New command find-miktex.hta to display path of the MiKTeX bin directory. Call from Windows console with no arguments or double click from Windows explorer and it will display the path to the MiKTeX executables in a browser-like window. (Internally this command uses the MiKTeX SDK to find MiKTeX. This is in contrast to the other utilities in this collection that use a heuristic.)

Dec 6/08. In the Modifying Path HOWTO we added information on setenv.exe, a free setx clone.

Nov 26/08. Added information on Windows 7 in the HOWTO section.

Oct 29/08. Added Q6 and Q7 to troubleshooting section.

Sep 27/08. Added information on Vista Run Commands (most work in XP too) in the HOWTO section.

August 2/08. Added information on Vista SP1 Performance Tuning in the HOWTO section below.

July 18/08. This message on r-devel discusses a number of reasons not to set PATH yourself but, instead, use batch files.

July 10/08. New file, show-svn-info.hta added. When run from a Tortoise SVN folder (version 1.5 or higher) it shows some information about it.

July 5/08. batchfiles 0.4-3 is now on CRAN. It fixes a bug in Sweave.bat and Stangle.bat .

June 25/08. Came across (1) this presentation by Andrej Blejec (in Slovenian), (2) this Sweave guide by Ista Zahn on the TeX User Group site and (3) these Lyx support files in the CRAN Other Software section that all mention Sweave.bat .

June 23/08. As toggleDoc was the only perl program in batchfiles it has been removed from the development source to maintain the integrity of the collection. After batchfiles 0.4-2 it will no longer be distributed with batchfiles; however, it can still be found in batchfiles_0.4-2.zip as it and all past versions of batchfiles are archived on CRAN.

June 15/08. batchfiles_0.4-2.zip has been uploaded to CRAN. Details in ANNOUNCE and README.

June 13/08. Stangle.bat and Sweave.bat have been made to be the same file. Each queries the name it was called by to determine which to run.

June 9/08. Stangle.bat added. Like Sweave.bat (version 0.3-2 and later), Stangle.bat does not depend on rtools/cygwin/sh.exe .

June 9/08. sweave.bat is now Sweave.bat in the svn. This should not make any difference as Windows is case insensitive to file names.

May 20/08. New facility in the development Source in which the various batchfiles first search for rbatchfilesrc.bat in current directory and then in %userprofile% and then in same directory as the batchfile itself and use first one found, if any. If one is found then it may contain set statements for R_HOME, R_TOOLS and R_MIKTEX (or a subset of those) and it will use those in place of the registry and its MiKTeX heuristic. That will allow use of batchfiles without setting any environment variables outside of the batchfiles and without registry access. It also allows different directories to easily and automatically use different versions of R. More info is available in the NEWS file. It is anticipated that most users will not use this facility nor the closely related environment variable facility since its easier just to let the batchfiles automatically determine the various paths by allowing it to access the registry but for some users who wish to set up certain custom installations this may be a useful alternative. Note that if one does not use this facility or the environment variables provided then the registry is only read, not written with one exception: That one exception is Rversions.hta (and in batchfiles 0.3-2 also rversions.bat) which can set in the registry which version of R is the current one. It does that by calling RSetReg.exe which is a program that is included with every version of R.

May 19/08. Added a new question to the Troubleshooting Section below.

May 15/08. Added a workaround for a bug in R in which Sweave.sty is not found when sweaving a file.

Mar 5/08. Added a Troubleshooting section below.

May 4/08. batchfiles 0.4-1 has been uploaded to CRAN. It eliminates the need to set the PATH when building R packaes -- previous versions of batchfiles eliminated it only for running R but not building packages. Also new rtools.bat and el.js utilities. Details in NEWS, ANNOUNCE and README.

Apr 30/08. The development source for Rcmd.bat and similar batch files now automatically find rtools in the registry (and they look for MiKTeX heuristically in a few places) so not only does one not have to set the PATH variable for running R but one does not have to set it for building R packages either.

Apr 30/08. The XP HowTo's are being moved from the box to the right to their own section on this page below. A new one on a free utility, SetEnv, is added too.

Mar 20/08. Added two new Vista HowTo's. The Vista HowTo's are now below in the HowTo section while the XP HowTo's (some of which apply to Vista too) are in the Links box to the right.

Jan 16/08. batchfiles version 0.4-0 is now on CRAN. (Version 0.4-0 and all future versions will be tested on Vista. Reports from XP users using it are welcome. Version 0.3-2 was tested on XP so XP users can use that.)

Jan 12/08. sweave.bat has been made independent of Rterm.bat so now all batch and javascript files are standalone and do not depend on each other or on other external programs other than possibly R in some cases. (toggleDoc.pl that was just contributed does depend on perl and on toggleDoc.js so it is the only utility with non-R dependencies.)

Jan 12/08. Removed find-miktex.bat, Rfind.bat, makepkg.bat and withgs.bat from the development Source -- they are still available in batchfiles version 0.3-2.

Jan 12/08. Added toggleDoc.pl/toggleDoc.js, a perl program and associated file, that adds a toggle box to the 00Index.html file in each package in your library. When the toggle box is checked, it collapses similar HTML help lines into one. Try checking and unchecking the toggle box labeled Show All at this page to get the idea. Contributed by Dieter Menne.

Jan 2/08. There is a new file, RguiStart.bat, in the development Source that starts up Rgui.exe in the directory specified by its first argument. On Vista put RGuiStart.bat in the %APPDATA%\Microsoft\Windows\SendTo folder and then in Windows Explorer you can right click any folder > SendTo > RGuiStart.bat to start R in that folder. See comments in these r-help posts: https://stat.ethz.ch/pipermail/r-help/2008-January/149455.html and https://stat.ethz.ch/pipermail/r-help/2008-January/149458.html RGuiStart.bat is actually the same file as Rgui.bat, Rcmd.bat, R.bat, Rterm.bat, Rscript.bat, #Rscript.bat and Rjgr.bat. The common script queries what name it was called by to determine what to do.

Sep 9/07. In the development version of batchfiles there is a new Rversions.hta for Vista with some code cleanup and improved heuristic for locating R.

DOWNLOAD

Get the latest release from CRAN or the development source from the Source tab above. Version 0.4-0 and later have been tested on Vista only while version 0.3-2 and prior were tested on XP only.

TROUBLESHOOTING FAQ

Q1. Rcmd.bat and similar batch files do not find the rtools.

A1. Make sure you have the most recent version of rtools. Registry support was added to rtools in April or May of 2008 so with older versions of the rtools, the rtools may not be automatically located.

Q2. Rcmd BATCH does not work.

A2. In very old versions of R (prior to R 2.5.1) Rcmd.exe BATCH (which is, in turn, used by Rcmd.bat in batchfiles) had problems with pathnames with embedded spaces. If you are still using an R version that old its time to upgrade!

Q3. When running sweave.bat the Sweave.sty file is not found.

A3. This is a known problem with MiKTeX for which a workaround will likely be forthcoming in version 2.8.0 of R. In the meantime here are three different solutions: (1) put sweave.sty in the same directory as your Rnw file (or other place where MiKTeX can find it) and put this line in your .Rnw file: \usepackage{Sweave} (2) A more drastic solution, which is not recommended but has been reported to work, is to reinstall R into a directory whose pathname has no spaces in it. (3) Another solution (warning: I have not verified this one) is to set the SWEAVE_STYLEPATH_DEFAULT environment variable in Windows to FALSE. For more on SWEAVE_STYLEPATH_DEFAULT see the Sweave manual and this post. (There is information on setting environment variables in the HowTo section below.)

Q4. I understand that Rcmd.bat and the other tools look in the Windows registry to find R and the Rtools. Can I use Rcmd.bat and the others if I cannot or wish not to modify the registry?

A4. There are two alternatives to using the registry:

1. Set R_HOME, R_TOOLS and R_MIKTEX environment variables. In that case Rcmd.bat and the other tools will use the indicated paths rather than look in the registry. For example, do the following (or to do it permanently set the paths via the control panel or via the free Redmond Path utility):

set R_HOME=C:\Program Files\R\R-2.7.0
set R_TOOLS=C:\Rtools
set R_MIKTEX=C:\Program Files\MikTex 2.7\miktex\bin

(Note that MiKTeX is found via a heuristic, not the registry, so if you have placed MiKTeX in the usual place then you may not need to set R_MIKTEX.)

2. The other alternative is to create a file called rbatchfilesrc.bat that contains the three lines above or similar lines and place that file in the current directory, in %userprofile% or in the same directory as Rcmd.bat and other tools in which case it will search for it in the given order and temporarily set the environment variables as indicated but only while Rcmd.bat or other file from batchfiles is running.

Q5. Rcmd INSTALL ... does not work.

A5. This is a commonly caused by a problem in customizations you made to your Rprofile.site file. In R, this shows the path of that file:

file.path(R.home(), "etc", "Rprofile.site")

See this r-devel post for more info.

Q6. I created my own batch file which calls Rcmd.bat from the batchfiles distribution (or other bat file); however, after Rcmd runs it does not return to my batch file.

A6. In Windows, when one batch file invokes another by simply giving its name as in:

rem this is in a batch file
Rcmd.bat check %1

the called batch file does not return to the caller -- i.e. in this example Rcmd.bat would not return to the invoking batch file. In order to achieve automatic return the call batch command must be used:

:: if call were not used on 1st line processing would never reach: echo finished
call Rcmd.bat check %1
echo finished

This is a general aspect of Windows batch files and is not specific to Rcmd.bat .

Q7. As in R FAQ 2.8 I upgraded from one version of R to another, e.g. 2.7.2 to R 2.8.0, and then used

cd \Users\JoeDoe\Documents\R\win-library
movedir 2.7 2.8

(or used copydir) and then invoked the Packages | Update menu but now RGtk2 and packages depending on it do not work. (Although we know of no other packages to which this applies its possible that such exist. In that case use the analogous answer.)

A7. In 2.8.0 just reinstall RGtk2:

install.packages("RGtk2", dep = TRUE)

then exit and re-enter R.

R FAQ 2.8 actually recommends using update.packages(checkBuilt = TRUE, ask = FALSE) rather than the menu and its possible that that would have resolved the RGtk2 problem although it could also result in many packages being downloaded so it could add substantially to the time. Resolve whether using `checkBuilt` makes a difference.

Q8. I get an error message concerning a directory that seems unrelated to what I am doing.

A8. There is now defensive code included to automatically protect against bad paths but just in case it misses certain conditions check your PATH to see if it has a problem. For example, check if a directory is in your PATH but does not exist. The free Redmond Path utility can be used to easily remove the offending directory from your path. Also note that there are length limits to the path. See this link to Microsoft's knowledge base article.

PROGRAM LIST

For more information on these commands see the README. Also those marked with (h) after them give help if run without arguments which is an easy way to get info on those. The scripts marked with (0) after them are normally used without arguments so you can just run it that way to see what it does.

Legend:
h = no args gives help
0 = common usage is to enter command name without arguments
d = in development

#Rscript.bat - put at top of R file to make it a batch file (h)
clip2r.js - pastes clipboard into Rgui.  See comments in file for use from vim. (0)(d)
copydir.bat - copy a library from one version of R to another (h)
el.js - run elevated - Vista and up, e.g. el Rgui  runs R elevated
find-miktex.hta - GUI to find MiKTeX (0)
jgr.bat - like jgr.exe but finds R from registry as well as JGR library (0)(d)
kopy.bat - copy Rcmd to other batch files (h)(d)
movedir.bat - move library from one version of R to another (h) 
R.bat - like R.exe but finds R from registry (0)
Rcmd.bat - like Rcmd.exe but finds R from registry (h)
RExcelVersion.hta - like Rversions.hta but also sets .RData association (0)
Rgui.bat - like Rgui.exe but finds R from registry (0)
RguiStart.bat - like Rgui.bat but arg1 defines folder to start R in
Rscript.bat - run .R script (h)
Rterm.bat - like rterm.exe but finds R from registry (h)
Rtidy.bat - reformat a .R file, e.g. Rtidy myfile.R > outfile.R (d)
Rtools.bat - place Rtools on path for remainder of console session (0)
Rversions.bat - list which versions of R are in registry (0)
Rversions.hta - GUI interface to RSetReg.  List and set R version (0)
show-svn-info.hta - show svn info if current folder is an svn checkout (0)
Stangle.bat - run arg1 through Stangle (h)
Sweave.bat - run arg1 through Sweave (h)

HOWTO

XP HowTo's are in the Links box to the above right. Some of these apply to Vista too. The following HowTo's are for Vista but some may work in XP too:

Upgrade from XP to Windows 7 See PC World article

Set Environment Variables Permanently through batch SetEnv

Install package from CRAN On your desktop, right click on R and choose Run As Administaror . Then when R starts choose the Packages | Install Package(s) menu item. Alternately, from the Windows command line use the elevation and Rgui batchfiles, el.js and Rgui.bat, to start R as shown below and then proceed to Packages menu, as before:

el Rgui

Another way to run R elevated is to click the Start button in the lower left of the screen (on a Vista machine) and enter cmd.exe into the Search box terminating it not with Enter but with Shift-Ctrl-Enter. That will give a command line which is elevated. Then run R from the command line using the batchfiles' Rgui command.

If despite doing the above that you get a message about packages.html not being writable then find the offending file in Windows Explorer and right-click that file's name choosing Properties > Security tab and reset the permissions appropriately. You may or may not also need to do the same thing on that file's folder.

Vista Performance Turning Microsoft has a free downloadable 14 page PDF document entitled Windows Vista Performance Tuning that discusses improving the performance of a Vista computer running the SP1 update. Also, ways to improve the performance of a Vista system (plus a link to an even longer list) was published in the NY Times Technology column October 9, 2008.

Am I Running Service Pack 1 (SP1) on Vista? Determine whether you are running SP1 of Vista or not. When reading this note that the original Vista is referred to by Microsoft as Build 6000 whereas the SP1 release is called Build 6001.

Modifying PATH Users of the batchfiles presented here are largely freed from having to modify the path in the first place; however, if you do need to do it then this is how. The PATH command from the Windows console will change the PATH for that session (PATH /? for more info). To permanently change the path (1) these instructions describe how to do it through the control panel or (2) one can use the setx command from the Windows resource kit (however, it does not come with Windows and costs extra but there is a free clone called setenv.exe) or (3) the free Redmond Path utility which makes it particularly easy to set your path by providing a gui editor into which it dumps your path, one component per line, so you can visually edit it and save it back. This PATH info all applies to XP as well.

Ready Boost Windows Vista allows one to use the storage on a USB key for extra cache space. This will improve performance, particularly if there was only a single hard drive and small main memory. Only USB keys with sufficiently fast storage will work. More information on this feature is available from:Tom Archer's MSDN blog and Tom Archer's FAQ.

Run Commands A long list of commands that can be entered in a Windows console: Run Commands

User Account Control and Other Tweaks Windows 7 has improvements to make UAC less annoying; however, even if you do not have it certain Windows 7 features can be simulated in XP and Vista as discusssed Get Windows 7 Features Right Now.

File Associations File associations are performed from the command line using the assoc and ftype commands in Windows. From the Windows console try help assoc and help ftype and also try issuing the two commands without arguments to view the present associations.

AutoHotKey Scripts There are AutoHotKey scripts by Jose Quesada to send code from the vim editor to R, to start R and to autoclose parentheses.

Suspending a Task DTaskManager is a free 2000/XP/Vista Windows utility that can be used to suspend tasks.

VISTA HACKS

These HowTo's are termed hacks since they are not recommended but are provided for the curious or frustrated.

Vista introduced the User Account Control (UAC) feature that essentially lets you run as a least authorized user rather than essentially as an Administrator the way you had to run in XP. This improves security but every so often you will get prompts asking you to elevate your level for a certain task. If you have upgraded to Vista SP1 then you won't get quite as many. Some people have described this as frustrating; however, for most people, in fact, it probably will not occur more than a few times a day. At any rate at the risk of compromising the security of your system, its possible to disable or partially disable UAC as discussed below. (Note that UAC problems should not be confused with file permission problems. For file permission problems right click the file in Windows Explorer and choose Properties and then the Security tab and adjust the settings appropriately.)

UAC For the best security leave UAC alone but it but if you feel you must disable or partially disable it then this article by Scott Lowe explains your options. These including turning it on and off via msconfig, the control panel, the registry or group policy, disabling prompts without disabling UAC entirely and running selected applications at Administrative level. Also see this article on how to disable UAC, this information on tweakUAC which makes it easy to turn UAC on and off and to run it in Quiet mode which eliminates prompts but only when you are running as Adminstrator. Also this link shows a 12 step procedure to Disable UAC for certain apps only using Microsoft's free Compatability Toolkit. Also see explanation by Greg Schultz. Another article on making UAC less annoying can be found at HowToGeek. You can also sign into an Adminstrator account to circumvent UAC as shown in this video.









Hosted by Google Code