README 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. batchfiles contains GPL-2 batch files for installing and maintaining R.
  2. Each is self contained, independent of the others and need no installation.
  3. Just place it anywhere on your path.
  4. ---
  5. PROGRAM LIST
  6. Legend:
  7. h = no args gives help
  8. 0 = common usage is to enter command name without arguments
  9. d = in development
  10. 2.11 = only works with R 2.11
  11. * = all files marked with one star are the same. Program checks name by which its called to determine action.
  12. ** = all files marked with two stars are the same. Program checks name by which its called to determine action.
  13. #Rscript.bat - put at top of R file to make it a batch file (h) (*)
  14. clip2r.js - pastes clipboard into Rgui. See comments in file for use from vim. (0)(d)
  15. copydir.bat - copy a library from one version of R to another (h)
  16. el.js - run elevated - Vista and up, e.g. el Rgui runs R elevated
  17. find-miktex.hta - GUI to find MiKTeX (0)
  18. kopy.bat - copy Rcmd to other batch files (h)(d)
  19. movedir.bat - move library from one version of R to another (h)
  20. R.bat - like R.exe but finds R from registry (0) (*)
  21. Rcmd.bat - like Rcmd.exe but finds R from registry (h) (*)
  22. Rgui.bat - like Rgui.exe but finds R from registry (0) (*)
  23. RguiStart.bat - like Rgui.bat but arg1 defines folder to start R in (*)
  24. Rscript.bat - run .R script (h) (*)
  25. Rterm.bat - like rterm.exe but finds R from registry (h) (*)
  26. Rtidy.bat - reformat a .R file, e.g. Rtidy myfile.R > outfile.R (d)
  27. Rtools.bat - place Rtools on path for remainder of console session (0) (*)
  28. Rversions.bat - list R and set R version in registry, e.g. on Vista: el cmd/c Rversions R-2.10.1 (0)
  29. Rversions.hta - GUI interface to RSetReg. List and set R version, e.g. on Vista: el cmd /c Rversions.hta (0)(2.11)
  30. show-svn-info.hta - show svn info if current folder is an svn checkout (0)
  31. Stangle.bat - run arg1 through Stangle (h) (**)
  32. Sweave.bat - run arg1 through Sweave (h) (**)
  33. ---
  34. DESCRIPTIONS
  35. R.bat, Rcmd.bat, Rscript.bat, Rgui.bat, and RguiStart.bat are all the same
  36. file. They query the name by which they were called to determine what they do.
  37. Similarly Sweave.bat and Stangle.bat are the same file.
  38. The home page and NEWS file provide more info.
  39. BATCH PROGRAMS
  40. 0. Rtools.bat
  41. 1. R.bat, Rcmd.bat, Rscript.bat, Rgui.bat
  42. 2. #Rscript.bat
  43. 3. RguiStart.bat
  44. 4. Sweave.bat and Stangle.bat
  45. 5. copydir.bat
  46. 6. movedir.bat
  47. 7. find-miktex.hta
  48. 0. Rtools.bat. Sets path to what Rcmd.bat and others use internally.
  49. This only sets the path for the current command shell instance.
  50. 1. R.bat, Rcmd.bat, Rscript.bat, Rgui.bat, Rscript.bat - are front
  51. ends to the corresponding .exe files. They locate R in the registry (and also
  52. look in a few other places if not found there). Then they look for Rtools and
  53. MiKTeX and if found they add them temporarily to the path. (Rtools and MiKTeX
  54. are needed when building R packages from source but are not needed for just
  55. running R nor are they need to download and install binary packages from CRAN.)
  56. Then they run R.exe, Rcmd.exe, Rscript.exe, Rgui.exe or JGR.exe with the same
  57. arguments. They are actually all the same file just renamed. (RguiStart.bat
  58. described separately is also the same file and all the code from this file is
  59. also at the end of Sweave.bat, also described separately.) The file checks
  60. what name it was called by and acts accordingly.
  61. Their main advantages are:
  62. - you don't have to modify your path just to run R.
  63. - you don't have to modify your path to build R packages from source.
  64. - when you upgrade R they automatically work without change
  65. since they will pick up the new version of R from the registry
  66. automatically.
  67. - Sweave.bat and Stangle.bat, unlike, Rcmd Sweave and Rcmd Stangle
  68. do not depend on rtools.
  69. You can put Rgui.bat on your desktop and associate a Windows
  70. ShortCut key (http://support.microsoft.com/kb/310417) with
  71. it so that you can just press the Windows key and
  72. R, say, to activate R.
  73. Here are some examples of using them from the command line.
  74. It assumes you have placed el.js, Rcmd.bat and Rgui.bat in
  75. your path. el cmd spawns a command console with Administrator
  76. rights. This is needed to build HTML help but you can omit
  77. the el command if you don't need that.
  78. el cmd
  79. Rcmd check mypackage
  80. Rcmd build mypackage
  81. Rcmd build mypackage --binary
  82. Rcmd INSTALL mypackage_1.0-0.tar.gz
  83. Rcmd INSTALL mypackage_1.0-0.tar.gz -l library
  84. Rscript myprog.R < mydata.dat
  85. Rgui
  86. (When installing packages on Vista it is recommended that
  87. you do this from within a console session that has Administrator
  88. rights. It will typically work even without that; however, the
  89. HTML help will not be created.)
  90. Older version of the Rcmd BATCH command in R had problems
  91. with spaces in pathnames so be sure you use a sufficiently
  92. recent version of R. If you are using an old version of R
  93. that has problems use the short name corresponding to any
  94. long name with spaces:
  95. For example, suppose we have a file
  96. C:\Documents and Settings\Administrator\myfile.R .
  97. Then try this:
  98. cd \
  99. dir/x doc*
  100. Rcmd BATCH c:\docume~1\Administrator\myfile.R
  101. where the dir/x command showed us the short name corresponding to
  102. the longer space-embedded name: Documents and Settings.
  103. 2. #Rscript.bat
  104. #Rscript.bat can be used as the first line of an R script to make
  105. it callable as a batch file. For example, if we have a myfile.R
  106. file then we can create a myfile.bat file that looks like this:
  107. #Rscript %0 %*
  108. ...R code from myfile.R goes here...
  109. and now we can just issue the command myfile to run it. We
  110. no longer need myfile.R.
  111. See the Rtidy.bat file for an example. Note that it does have
  112. the disadvantage that the output of the R program starts off
  113. with the command itself. R needs to be able to handle the
  114. perl/python/ruby -x switch. In the meantime #Rscript.bat
  115. will mainly be useful for those scripts where the output does
  116. not go to the standard output or where the addition of this
  117. line is acceptable.
  118. 3. RguiStart.bat
  119. This is like Rgui.bat except it intercepts the first argument
  120. and interprets it as the folder in which to start R (or if its
  121. an .Rdata file then it interprets it as the .Rdata file to start
  122. R with). The main reason for its existence is so that you can
  123. place it in your SendTo folder. On Vista do this:
  124. copy RguiStart.bat %APPDATA%\Microsoft\Windows\SendTo
  125. (or to locate locate the SendTo folder in Windows Explorer on Vista
  126. enter shell:sendto into the Windows Explorer address bar and copy
  127. your RguiStart.bat file there.)
  128. Then, on Vista, when you are in Windows Explorer you can right click
  129. on any folder in your user area and choose SendTo. From the SendTo
  130. menu choose RGuiStart.bat to start up R in that folder. If you
  131. right click on an .Rdata file rather than a folder then R will
  132. start up with that file loaded (although in that case its probably
  133. easier to just double click the .Rdata file provided you have
  134. file type associations set up -- if you don't then the RguiStart.bat
  135. will provide an alternative).
  136. A second possibility is to place RguiStart.bat on your desktop and
  137. then drag a folder to it to start R in that folder.
  138. A third possibility is to just shift right click a folder in Windows
  139. Explorer and choose Open Command Window Here and then when the command
  140. window opens enter Rgui assuming you have placed Rgui.bat somewhere in
  141. your path.
  142. 4. Sweave.bat and Stangle.bat - will run Sweave, then pdflatex and then
  143. display latex file. Stangle.bat will run Stangle producing an R file.
  144. Unlike Rcmd Sweave and Rcmd Stangle these do not depend on rtools.
  145. Sweave.bat and Stangle.bat are actually the same file. The file determines
  146. what to do by looking at the name by which it was called.
  147. Sweave mydoc.Rnw
  148. or
  149. Sweave mydoc
  150. The script runs Sweave, pdflatex and then displays the pdf
  151. file (assuming the user has .pdf extension associated with a
  152. pdf viewer). If there is an error in Sweave or the .tex
  153. file is not newer than the Sweave'd file the script stops.
  154. Similarly if there is an error in pdflatex or the .pdf is
  155. not newer than the .tex file then the script stops. Note
  156. that _two_ .pdf files are generated. They are identical
  157. except one has a unique name created by suffixing the base
  158. with the date and time and .bck.pdf. The one with the unique name
  159. is the one viewed. This overcomes problems of not being able to
  160. view the .pdf if the .pdf from a prior run is current being
  161. viewed (which would happen since by default the Acrobat viewer
  162. won't allow you to view two files of the same name concurrently).
  163. Every so often the user should delete all *.bck.pdf files.
  164. Try:
  165. sweave
  166. without arguments to see options and get more info.
  167. Aside from using sweave from the command line, if you place
  168. sweave.bat in your SendTo folder as discussed under
  169. RguiStart.bat you can right click .Rnw files and choose
  170. SendTo > sweave to sweave them.
  171. You may need to copy Sweave.sty to the directory containing
  172. your .Rnw sweave file to use sweave.bat .
  173. 5. Rversions.bat - similar to Rversions.hta but
  174. -- its batch whereas Rversions.hta is GUI
  175. -- uses slightly different heuristic to find R versions
  176. -- run without args to list versions available; run with any of
  177. the listed versions to set that as the new version
  178. -- both forms work on XP; to run arg form on Vista run it elevated
  179. e.g. el cmd /c Rversions.bat R-2.10.0
  180. Examples:
  181. :: list R versions
  182. rversions.bat
  183. :: check mypkg using R current version, 2.4.0, say
  184. Rcmd check mypkg
  185. :: switch to version R-2.5.0 and recheck
  186. rversions R-2.5.0
  187. Rcmd check mypkg
  188. :: reset back to version 2.4.0
  189. rversions.bat R-2.4.0
  190. 6. copydir.bat - can be used to copy the libraries from an
  191. old version of R to your new one. It will not overwrite any
  192. libraries already there so it should be safe to use. e.g. to
  193. upgrade R to a new version
  194. :: Example is for upgrading from R-2.4.1 to R-2.5.0
  195. :: first, download and install R-2.11.0
  196. :: now perform the next two commands at the Windows console
  197. cd %userprofile%\Documents\R\win-library
  198. :: you can use movedir instead of copydir if you prefer to move them
  199. copydir 2.10\library 2.11\library
  200. :: ... now startup new version of R (R 2.11.0 in this example)
  201. # issue this command in R 2.5.0
  202. update.packages(checkBuilt = TRUE, ask = "graphics")
  203. # or (see note below)
  204. update.packages(ask = "graphics")
  205. :: press OK and it will update those packages as necessary
  206. # ... optionally check for deprecated packages
  207. # 1. first select all repositories that you use with menu:
  208. # Packages | Repositories
  209. # 2. second check if there are any deprecated packages that
  210. # were copied over but are not longer on CRAN or other repository
  211. dp <- setdiff(installed.packages()[,1], available.packages()[,1])
  212. # look at what we have
  213. dp
  214. # if you wish to remove them issue the remove.packages command:
  215. # remove.packages(dp)
  216. :: ... exit R and start it up again ...
  217. Note that the checkBuilt=TRUE argument will potentially
  218. cause all your packages to be downloaded again so you could
  219. try leaving it off and then reissue the command with
  220. checkBuilt=TRUE later only if you run into problems. I
  221. normally do it without the checkBuilt=TRUE.
  222. It is anticipated that this command will ultimately be
  223. superceded by functionality in the R setup procedure at
  224. which time this will be deprecated. Note that this method
  225. of just copying libraries may not work depending on the
  226. versions of R involved. If its necessary to re-install most
  227. packages it can be done by issuing the following R command
  228. after performing the copydir.bat:
  229. install.packages(installed.packages()[,1])
  230. (Note that 2.8 of the R Windows FAQ
  231. http://cran.r-project.org/bin/windows/base/rw-FAQ.html#What_0027s-the-best-way-to-upgrade_003f
  232. refers to copying any installed package to the library
  233. folder but does not address how to accomplish that. That
  234. omission is what copydir.bat addresses.)
  235. An alternative to copydir is to reinstall all packages
  236. # Alternative to copydir.bat #1
  237. # this example is for moving from 2.4.1 to 2.5.0
  238. # run this in R 2.5.0
  239. setwd(R.home())
  240. ip <- installed.packages(lib.loc = "../R-2.4.1/library")
  241. ip <- ip[ip[,1]!="base" ,1]
  242. install.packages(ip)
  243. The above is taken from:
  244. https://www.stat.math.ethz.ch/pipermail/r-help/2007-May/131806.html
  245. Note that you may still have to use movedir.bat or copydir.bat
  246. after the above if it fails to install everything. Since movedir.bat
  247. and copydir.bat won't overwrite anything this should be safe.
  248. # Alternative to copydir.bat #2
  249. #---run in previous version, e.g. R 2.4.1
  250. packages <- installed.packages()[,"Package"]
  251. save(packages, file = "~/Rpackages")
  252. #---run in new version, e.g. R 2.5.0
  253. load("~/Rpackages")
  254. install.packages(setdiff(packages, installed.packages()[,"Package"]))
  255. file.remove("~/Rpackages")
  256. This copydir alternative is based on:
  257. https://www.stat.math.ethz.ch/pipermail/r-help/2007-May/131131.html
  258. 7. movedir - same arguments as copydir. Only difference is
  259. that it moves the directories rather than copying them. This
  260. can be used if you are no longer interested in using the
  261. packages with the old version of R other than by
  262. reinstalling them.) This has the advantage that its much
  263. faster than copydir. The example under copydir works with
  264. movedir too. Just replace copydir with movedir in that
  265. example. Comments under copydir.bat apply here too. I
  266. mostly use movedir.bat myself instead of copydir.bat since
  267. its so much faster.
  268. 8. show-svn-info.hta - Just run this from any Tortoise SVN folder
  269. and it will display some information about it. Requires version 1.5
  270. or higher of Tortoise SVN.
  271. 9. find-miktex.hta - displays the path to the MiKTeX bin directory.
  272. Just enter find-miktex.hta at the Windows command line (no arguments
  273. are needed) or double click it from Windows Explorer.
  274. ADDITIONAL FILES
  275. 1. RESOURCES - additional information on writing Windows XP
  276. batch files.
  277. 2. COPYRIGHT and COPYING - this is free software subject to
  278. the GPL license as described.
  279. 3. THANKS - acknowledgments.
  280. DEPRECATED AND CHANGED
  281. - Rfind.bat
  282. - makepkg.bat
  283. - Rversions.hta
  284. - toggerDoc.pl
  285. These are no longer distributed but can be found in older distributions of this
  286. package. It is unknown whether they work with recent versions of R. (I found
  287. I was not using these so am no longer maintaining them.)