File: rw-FAQ.texi

package info (click to toggle)
r-base 3.1.1-1%2Bdeb8u1
  • links: PTS
  • area: main
  • in suites: jessie
  • size: 85,436 kB
  • ctags: 35,389
  • sloc: ansic: 306,779; fortran: 91,908; sh: 11,216; makefile: 5,311; yacc: 4,994; tcl: 4,562; objc: 746; perl: 655; asm: 553; java: 31; sed: 6
file content (1915 lines) | stat: -rw-r--r-- 84,308 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
\input texinfo
@c %**start of header
@setfilename rw-FAQ.info
@settitle R for Windows FAQ
@setchapternewpage on
@set VERSION @RWVER@
@set RVERSION @RVER@
@c %**end of header
@documentlanguage en
@documentencoding ISO-8859-1

@finalout

@macro newchap{}
@ifinfo
@sp 1
@end ifinfo
@ifhtml
@html
<hr>
@end html
@end ifhtml
@end macro

@titlepage
@title R for Windows FAQ
@subtitle Frequently Asked Questions on R for Windows
@subtitle Version @value{VERSION}
@author B. D. Ripley and D. J. Murdoch
@end titlepage

@ifinfo
R for Windows FAQ                           @*
Frequently Asked Questions on R for Windows @*
Version for @value{VERSION}                 @*
B. D. Ripley and D. J. Murdoch              @*

@sp 2
@end ifinfo

@ifhtml
@html
<h2>Version for <tt>@value{VERSION}</tt></h2>
<address>B. D. Ripley and D. J. Murdoch</address>
<hr>
@end html
@end ifhtml

@paragraphindent 0

@contents

@ifinfo
@sp 1
@end ifinfo


@node Top, Introduction, (dir), (dir)

@menu
* Introduction::                
* Installation and Usage::      
* Languages and Internationalization::  
* Packages::                    
* Windows Features::            
* Workspaces::                  
* The R Console::               
* Building from Source::        
@end menu


@newchap{}
@node Introduction, Installation and Usage, Top, Top
@chapter Introduction

This FAQ is for the Windows port of R: it describes features specific to
that version.  The main R FAQ can be found at

@display
@uref{http://CRAN.R-project.org/doc/FAQ/R-FAQ.html}.
@end display

The information here applies only to recent versions of R for Windows,
(@samp{3.0.0} or later).  It is biased towards users of 64-bit Windows.


@newchap{}
@node Installation and Usage, Languages and Internationalization, Introduction, Top
@chapter Installation and Usage

@menu
* Where can I find the latest version?::  
* How do I install R for Windows?::  
* How do I check an installation?::  
* Can I customize the installation?::  
* How do I run it?::            
* Can I run R from a CD or USB drive?::  
* How do I UNinstall R?::       
* What's the best way to upgrade?::  
* There seems to be a limit on the memory it uses!::  
* How can I keep workspaces for different projects in different directories?::  
* How do I print from R?::      
* Can I use R CMD BATCH?::      
* Can I use @RWVER@ with ESS and Emacs?::  
* What are HOME and working directories?::  
* How do I set environment variables?::  
* R can't find my file::        
* Does R use the Registry?::    
* Does R support automation?::  
* The Internet download functions fail.::  
* Entering certain characters crashes Rgui.::  
* What does 'DLL attempted to change FPU control word' mean?::  
* Other strange crashes.::      
* Why does R never use more than 50% of my CPU?::  
* Does R run under Windows Vista?::  
* Quotes don't come out right on the console/terminal/pager::  
* There is no tilde on my keyboard::  
* Can I use R on 64-bit Windows?::  
* Should I run 32-bit or 64-bit R?::  
* Can both 32- and 64-bit R be installed on the same machine?::  
* Rcmd is not found in my PATH!::  
@end menu


@node Where can I find the latest version?, How do I install R for Windows?, Installation and Usage, Installation and Usage
@section Where can I find the latest version?

Go to any CRAN site (see @uref{http://cran.r-project.org/@/mirrors.html}
for a list), navigate to the @file{bin/windows/base} directory and
collect the file(s) you need.  The current release is distributed as an
installer @samp{@RWVER@-win.exe} of about 54Mb.

There are also links on that page to the @samp{r-patched} and
@samp{r-devel} snapshots.  These are frequently updated builds of
development versions of R.  The @samp{r-patched} build includes bug
fixes to the current release, and @samp{r-devel} contains these as well
as changes that will eventually make it into the next @samp{x.y.0}
release.

@node How do I install R for Windows?, How do I check an installation?, Where can I find the latest version?, Installation and Usage
@section How do I install R for Windows?

Current binary versions of R run on Windows XP or later, including on
64-bit versions: @xref{Can I use R on 64-bit Windows?}. The last version
known to run on Windows 2000 was 2.12.2 and the last version supporting
95/98/ME/NT4 was 2.6.1.

@c 2000 went end-of-life 2010-07-13
@c XP SP3 went end of life 2014-04-08

We only test on versions of Windows currently supported by Microsoft,
mainly 64-bit Windows 7 and Server 2008.

Your file system must allow case-honouring long file names (as is likely
except perhaps for some network-mounted systems).  A installation takes
75--100Mb of disk space.

If you want to be able to build packages from sources, we recommend that
you choose an installation path not containing spaces.  (Using a path
with spaces in will probably work, but is little-tested.)  Users of
Vista/Windows 7/8/Server 2008/2012 installing for a single user using an
account with administrator rights@footnote{Non-administrator accounts
will automatically be offered a default installation directory in the
user area.} should consider installing into a non-system area (such as
@file{C:\R}).  Installing to a network share (a filepath starting with
@code{\\machine\...}) is not supported: such paths will need to mapped
to a network drive.

To install use @samp{@RWVER@-win.exe}.  Just double-click on the icon
and follow the instructions.  If you have an account with Administrator
privileges you will be able to install R in the @file{Program Files}
area and to set all the optional registry entries; otherwise you will
only be able to install R in your own file area.  You may need to
confirm that you want to proceed with installing a program from an
`unknown' or `unidentified' publisher.

After installation you should choose a working directory for R.  You
will have a shortcut to @file{Rgui.exe} on your desktop and/or somewhere
on the Start menu file tree, and perhaps also in the Quick Launch part
of the taskbar (Vista and earlier).  Right-click each shortcut, select
Properties... and change the `Start in' field to your working directory.

On some systems you will have two shortcuts, one for 32-bit with a label
starting @code{R i386} and one for 64-bit starting @code{R x64}
(@pxref{Should I run 32-bit or 64-bit R?})

You may also want to add command-line arguments at the end of the
Target field (@emph{after} any final double quote, and separated by a
space), for example @code{--sdi --max-mem-size=1G}.  You can also set
environment variables at the end of the Target field, for example
@code{R_LIBS=p:/myRlib}, and if you want to ensure that menus and
messages are in (American) English, @code{LANGUAGE=en}.

It is also possible to install from an MSI file, which will be of
interest only for system administrators.  For how to build the MSI file,
see the `R Installation and Administration Manual'.


@node How do I check an installation?, Can I customize the installation?, How do I install R for Windows?, Installation and Usage
@section How do I check an installation is not corrupt?

Relates to earlier installers, removed in R 2.11.0.

@node Can I customize the installation?, How do I run it?, How do I check an installation?, Installation and Usage
@section Can I customize the installation?

The normal way to customize the installation is by selecting components
from the wizards shown by the installer.  However, sysadmins might like
to install R from scripts, and the following command-line flags are
available for use with the installer.

@table @samp
@item /SILENT
only show the installation progress window and error messages.
@item /VERYSILENT
only show error messages.
@item /DIR="x:\dirname"
set the default installation directory
@item /GROUP="folder name"
set the default Start-menu group name
@item /COMPONENTS="comma separated list of component names"
set the initial list of components: Components are named @samp{main},
@samp{i386}, @samp{x64} and @samp{translations}.
@end table

@noindent
It is also possible to save the settings used to a file and later
reload those settings using

@table @samp
@item /SAVEINF="filename"
save the settings to the specified file.  Don't forget to use the quotes if
the filename contains spaces.
@item /LOADINF="filename"
instructs the installer to load the settings from the specified file
after having checked the command line.
@end table

A successful installation has exit code 0: unsuccessful ones may give 1,
2, 3, 4 or 5.  See the help for Inno Setup
(@uref{http://jrsoftware.org/@/ishelp.php}) for details.

We have some facilities for building a customized installer, in
particular to add packages to the installer.  See the `R Installation
and Administration' manual in the subsection `Building the installers'.

@node How do I run it?, Can I run R from a CD or USB drive?, Can I customize the installation?, Installation and Usage
@section How do I run it?

Just double-click on the shortcut you prepared at installation.

If you want to set up another project, make a new shortcut or use the
existing one and change the `Start in' field of the Properties.

You may if you prefer run R from the command line of any shell you use,
for example a `Command Prompt' or a port of a Unix shell such as
@command{tcsh} or @command{bash}. (The command line can be anything you
would put in the Target field of a shortcut, and the starting directory
will be the current working directory of the shell.)

@node Can I run R from a CD or USB drive?, How do I UNinstall R?, How do I run it?, Installation and Usage
@section Can I run R from a CD or USB drive?

Yes, with care.  A basic R installation is relocatable, so you can burn
an image of the R installation on your hard disc or install directly
onto a removable storage device such as a flash-memory USB drive.

Running R does need access to a writable temporary directory and to a
home directory, and in the last resort these are taken to be the current
directory.  This should be no problem on a properly configured version
of Windows, but otherwise does mean that it may not be possible to run R
without creating a shortcut starting in a writable folder.


@node How do I UNinstall R?, What's the best way to upgrade?, Can I run R from a CD or USB drive?, Installation and Usage
@section How do I UNinstall R?

Normally you can do this from the @samp{Add/Remove Programs} (XP) or
@samp{Programs and Features} group in the Control Panel.  If it does not
appear there, run @file{unins000.exe} in the top-level installation
directory.  On recent versions of Windows you may well be asked to
confirm that you wish to run a program from an `unknown' or
`unidentified' publisher.

Uninstalling R only removes files from the initial installation, not
(for example) packages you have installed or updated.

If all else fails, you can just delete the whole directory in which R
was installed.


@node What's the best way to upgrade?, There seems to be a limit on the memory it uses!, How do I UNinstall R?, Installation and Usage
@section What's the best way to upgrade?

That's a matter of taste.  For most people the best thing to do is to
uninstall R (see the previous Q), install the new version, copy any
installed packages to the library folder in the new installation, run
@code{update.packages(checkBuilt=TRUE, ask=FALSE)} in the new R and then
delete anything left of the old installation.  Different versions of R
are quite deliberately installed in parallel folders so you can keep old
versions around if you wish.

For those with a personal library (folder @file{R\win-library\@var{x.y}}
of your home directory, @file{R\win64-library\@var{x.y}} on 64-bit
builds), you will need to update that too when the minor version of R
changes (e.g.@: from 3.0.2 to 3.1.0).  A simple way to do so is to
copy (say) @file{R\win-library\3.0} to @file{R\win-library\3.1} before
running @code{update.packages(checkBuilt=TRUE, ask=FALSE)}.


@node There seems to be a limit on the memory it uses!, How can I keep workspaces for different projects in different directories?, What's the best way to upgrade?, Installation and Usage
@section There seems to be a limit on the memory it uses!

Indeed there is.  It is set by the command-line flag
@option{--max-mem-size} (@pxref{How do I install R for Windows?}) or by
environment variable @env{R_MAX_MEM_SIZE}. 

For a 64-bit build of R it defaults to the amount of RAM.

For a 32-bit build of R it defaults to the smaller of the amount of
physical RAM in the machine and 0.5GB less than the limit on user
virtual memory for a process (most often 2GB when using a 32-bit edition
of Windows).

Use @code{?Memory} and @code{?memory.size} for information about memory
usage.  The limit can be raised (if possible) by calling
@code{memory.limit} within a running R session.

The 32-bit executables support up to 3GB of user address space per
process under suitably enabled versions of 32-bit Windows (see
@uref{http://www.microsoft.com/@/whdc/@/system/@/platform/@/server/@/PAE/@/PAEmem.mspx},
@uref{http://msdn.microsoft.com/@/en-us/@/library/@/bb613473%28VS.85%29.aspx};
this is not enabled by default).  On such systems, the default for
@code{--max-mem-size} is the smaller of the amount of RAM and 2.5GB.  On
all but the earliest 64-bit versions of Windows the user address space
for a 32-bit process is 4GB, and there the default for
@code{--max-mem-size} is the smaller of the amount of RAM and 3.5GB.


@c limits are documented at http://msdn.microsoft.com/en-us/library/aa366778%28VS.85%29.aspx

@node How can I keep workspaces for different projects in different directories?, How do I print from R?, There seems to be a limit on the memory it uses!, Installation and Usage
@section How can I keep workspaces for different projects in different directories?

Create a separate shortcut for each project: see Q2.5.  All the paths to
files used by R are relative to the starting directory, so setting the
`Start in' field automatically helps separate projects.

Alternatively, start R by double-clicking on a saved @file{.RData} file
in the directory for the project you want to use, or drag-and-drop a
file with extension @file{.RData} onto an R shortcut.  In either case,
the working directory will be set to that containing the file.


@node How do I print from R?, Can I use R CMD BATCH?, How can I keep workspaces for different projects in different directories?, Installation and Usage
@section How do I print from R?

It depends what you want to print.

@itemize @bullet
@item
You can print the graphics window from its menu or by using
@code{dev.print} with suitable arguments (see its help page: most likely
@code{dev.print(win.graph)} will work).

@item
You can print from the R console or pager by @samp{File | Print}.
(This will print the selection if there is one, otherwise the whole
console or pager contents.)

@item
You can print help files from the pager or HTML browser.

@item
If you have LaTeX installed and a PDF printing system you
can print help files by @code{help(fn_name, help_type="PDF")}.
@end itemize


@node Can I use R CMD BATCH?, Can I use @RWVER@ with ESS and Emacs?, How do I print from R?, Installation and Usage
@section Can I use @code{R CMD BATCH}?

Yes: use @code{R CMD BATCH --help} or @code{?BATCH} for full details.

You can also set up a batch file using @command{Rterm.exe}.  A sample
batch file might contain (as one line)

@example
path_to_R\bin\x64\Rterm.exe --no-restore --no-save < %1 > %1.out 2>&1
@end example

@noindent
The purpose of @code{2>&1} is to redirect warnings and errors to the
same file as normal output.


@node Can I use @RWVER@ with ESS and Emacs?, What are HOME and working directories?, Can I use R CMD BATCH?, Installation and Usage
@section Can I use @RWVER@ with ESS and Emacs?

Yes.  ESS has for a long time supported R under Windows: it does so by
running @code{Rterm.exe} without a visible console.

For help with ESS, please send email to @email{ESS-help@@stat.ethz.ch},
not the R mailing lists.


@node What are HOME and working directories?, How do I set environment variables?, Can I use @RWVER@ with ESS and Emacs?, Installation and Usage
@section What are HOME and working directories?

Several places in the documentation use these terms.

The working directory is the directory from which @code{Rgui} or
@command{Rterm} was launched, unless a shortcut was used when it is given
by the `Start in' field of the shortcut's properties.  You can find this
from R code by the call @code{getwd()}.

The home directory is set as follows: If environment variable
@env{R_USER} is set, its value is used.  Otherwise if environment
variable @env{HOME} is set, its value is used.  After those two
user-controllable settings, R tries to find system-defined home
directories.  It first tries to use the Windows "personal" directory
(typically @file{C:\Documents and Settings\username\My Documents} on
Windows XP and @file{C:\Users\username\Documents} nowadays).  If that
fails, if both environment variables @env{HOMEDRIVE} and @env{HOMEPATH}
are set (and they normally are), the value is
@file{$@{HOMEDRIVE@}$@{HOMEPATH@}}.  If all of these fail, the current
working directory is used.

You can find this from R code by @code{Sys.getenv("R_USER")} or
@code{normalizePath("~")}, @samp{~} being Unix notation for the home directory.

@node How do I set environment variables?, R can't find my file, What are HOME and working directories?, Installation and Usage
@section How do I set environment variables?

Environment variables can be set for @command{Rgui.exe} and
@command{Rterm.exe} in three different ways.
@enumerate
@item
On the command line as name=value pairs.  For example in the shortcut to
@command{Rgui} you could have

@example
"path_to_R\bin\x64\Rgui.exe" HOME=p:/ R_LIBS=p:/myRlib
@end example

@item
In an environment file @file{.Renviron} in the working directory
or in your home directory, for example containing the line

@example
R_LIBS=p:/myRlib
@end example

If you have permission to do so, you can also create an environment file
@file{etc\Renviron.site} and set environmental variables in that file in
the same way.  This is useful for variables which should be set for all
users and all usages of this R installation.  (Their values can be
overridden in a @file{.Renviron} file or on the command line.)

See @code{?Startup} for more details of environment files.

@item
For all applications via Windows.  How you set an environment variable
is system specific: under recent versions of Windows, go to `User
Accounts' in the Control Panel, and select your account and then `Change
my environment variables'.
@end enumerate

The order of precedence for environmental variables is the order in
which these options are listed, that is the command line then
@file{.Renviron} then the inherited environment.


@node R can't find my file, Does R use the Registry?, How do I set environment variables?, Installation and Usage
@section R can't find my file, but I know it is there!

How did you specify it?  Backslashes have to be doubled in R character
strings, so for example one needs
@samp{"d:\\@RWVER@\\library\\xgobi\\scripts\\xgobi.bat"}.  You can make
life easier for yourself by using forward slashes as path separators:
they do work under Windows.  You should include the file extension
(e.g.@: @samp{"xgobi.bat"} rather than just @samp{"xgobi"}); sometimes
this isn't shown in Windows Explorer, but it is necessary in R.

A simple way to avoid these problems is to use the function
@code{file.choose()} to invoke the standard Windows file selection
dialog.  If you select a file there, the name will be passed to R in
the correct format.

Another possible source of grief is spaces in folder names.  We have
tried to make R work on paths with spaces in, but many people writing
packages for Unix do not bother.  So it is worth trying the alternative
short name (something like @samp{PROGRA~1}; you can get it as the
`MS-DOS name' from the Properties of the file on some versions of
Windows, and from @command{dir /X} in a @samp{Command Prompt} window),
and using the function @code{shortPathName} from R code.


@node Does R use the Registry?, Does R support automation?, R can't find my file, Installation and Usage
@section Does R use the Registry?

Not when R itself is running.

When you run the R installer, there are options (under @samp{Select
Additional Tasks}) to @samp{Save version number in registry} and (for
Administrator installs) @samp{Associate R with .RData files}.

If you tick the first option, the following string entries are added to the
Windows registry:
@itemize @bullet
@item  @code{HKEY_LOCAL_MACHINE\Software\R-core\R\Current Version}  
    contains the version number, currently @RVER@.
@item @code{HKEY_LOCAL_MACHINE\Software\R-core\R\[version]\InstallPath}
    (where @code{[version]} is currently @RVER@) contains the path to the R 
    home directory.
@end itemize
If you do not have administrative privileges on the machine while
running the installer, then the entries are created under
@code{HKEY_CURRENT_USER}.  The same entries are also created under
@code{Software\R-core\R32} or @code{Software\R-core\R64}, for 32- and
64-bit R respectively.

If you tick the second option (shown with administrative privileges
only) (@samp{Associate R with .RData files}) then entries are created
under @code{HKEY_CLASSES_ROOT\.RData} and
@code{HKEY_CLASSES_ROOT\RWorkspace}.

After installation you can add the Registry entries by running
@code{RSetReg.exe} in a sub-folder of the @code{bin} folder, and remove
them by running this with argument @code{/U}.  Note that this requires
administrative privileges unless run with argument @code{/Personal} and
neither sets up nor removes the file associations.


@node Does R support automation?, The Internet download functions fail., Does R use the Registry?, Installation and Usage
@section Does R support automation (OLE, COM)?

Directly, no.  See CRAN packages @code{rscproxy} and @code{rcom} as well
as @code{RDCOMServer}, @code{RDCOMClient}, @code{RDCOMEvents} and
@code{SWinTypeLibs} from @uref{http://www.omegahat.org/}.


@node The Internet download functions fail., Entering certain characters crashes Rgui., Does R support automation?, Installation and Usage
@section The Internet download functions fail.

for example @code{update.packages()} and the menu items on the Packages menu.

We have had several reports of this, although they do work for us on
@emph{all} of our machines.  There are two known possible fixes.

(a) Use the alternative @file{internet2.dll} by starting R with the flag
@option{--internet2} (@pxref{How do I install R for Windows?}) or
calling @code{setInternet2(TRUE)}, or setting the environment variable
@env{R_WIN_INTERNET2} to a non-empty value.  These cause R to use the
Internet Explorer internals, which may already be configured for use
with proxies.  Note that this does @emph{not} work with proxies that
need authentication.

(b) A proxy needs to be set up: see @code{?download.file}.  Here are two
versions of an example (a real one, but from a machine that is only
available locally) of a command-line in a short cut:

@example
"path_to_R\bin\x64\Rgui.exe" http_proxy=http://user:pass@@gannet:80/

"path_to_R\bin\x64\Rgui.exe" http_proxy=http://gannet/ http_proxy_user=ask
@end example

@noindent
The second version will prompt the user for the proxy username and
password when HTTP downloads are first used.

Another possibility is that firewall settings are blocking the R
executables from contacting the Internet, but this should result in
informative error messages from the firewall program.


@node Entering certain characters crashes Rgui., What does 'DLL attempted to change FPU control word' mean?, The Internet download functions fail., Installation and Usage
@section Entering certain characters crashes Rgui.

This has not been reported for a few years, but used to happen
regularly.  All the occurrences we have solved have been traced to
faulty versions of @samp{msvcrt.dll}: we have installed a workaround
that seems to avoid this.  A few other people have discovered this was
caused by desktop switcher and keyboard macro programs, for example
`Macro Magic' and `JS Pager'.

@node What does 'DLL attempted to change FPU control word' mean?, Other strange crashes., Entering certain characters crashes Rgui., Installation and Usage
@section What does 'DLL attempted to change FPU control word' mean?

This is a @emph{warning} which indicates that R has taken action to
correct the action of some (non-R) DLL which has just been loaded and
has changed the floating point control word (in its initialization code)
to a setting incompatible with that needed for R.  This is not good
practice on the part of the DLL, and often indicates that it needs to be
updated.

Unfortunately, because DLLs may themselves load other DLLs it is not
possible for R to track which DLL caused the problem.

See also @code{?dyn.load}.

@node Other strange crashes., Why does R never use more than 50% of my CPU?, What does 'DLL attempted to change FPU control word' mean?, Installation and Usage
@section Other strange crashes.

Some users have found that @code{Rgui.exe} fails to start, exiting with
a ``Floating-point invalid operation'' or other low level error.  This
error may also happen in the middle of a session.  In some cases where
we have tracked this down, it was due to bugs in the video driver on the
system in question: it makes changes to the floating point control word
which are incompatible with R.  (Good practice would restore the control
word to the state it was in when the driver code was called, and R
tries hard to correct this before running its own code.)  For example,
one user reported that the virtual screen manager JSP2 caused this
crash.

These errors are essentially impossible for us to fix or work around
beyond the measures already taken.  The only solution we know of is for
the user to replace the buggy system component that is causing the
error.


@node Why does R never use more than 50% of my CPU?, Does R run under Windows Vista?, Other strange crashes., Installation and Usage
@section Why does R never use more than 50% of my CPU?

This is a misreading of Windows' confusing Task Manager.  R's
computation is single-threaded, and so it cannot use more than one CPU.
What the task manager shows is not the usage in CPUs but the usage as a
percentage of the apparent total number of CPUs.  We say `apparent' as
it treats so-called `hyper-threaded' CPUs such as two CPUs per core, and
most modern CPUs have at least two cores.

You can see how many `CPU's are assumed by looking at the number of
graphs of `CPU Usage History' on the `Performance' tab of the Windows
Task manager.


@node Does R run under Windows Vista?, Quotes don't come out right on the console/terminal/pager, Why does R never use more than 50% of my CPU?, Installation and Usage
@section Does R run under Windows Vista/7/8/Server 2008?

It does.  A few issues have been reported that are related to the way
accounts and file permissions work.  (These are not specifically R
issues, but changes in user experiences.)

Earlier versions of Windows had user and Administrator accounts, and
user accounts could be give administrative privileges (by being added to
the local Administrators group) and so write permission over system
areas such as @file{c:\Program Files}.  R would be installed either by a
user in his own file space or by an account with administrator
privileges into a system area.  Sysadmins could set policies for user
accounts, and you might for example have needed to be a `Power User' to
install software at all.

Vista and later normally disable the Administrator account and expect
software installation to be done by an account which is in the local
Administrator group with `admin approval mode' turned on.  (The
Administrator account by default has it turned off.)  Unlike (say)
Windows XP, such accounts do not run programs with full administrator
privileges, and this is where the issues arise.  (For background
information consult e.g.@:
@url{http://windowsvistablog.com/@/blogs/@/windowsvista/@/archive/@/2007/01/23/@/security-features-vs-convenience.aspx}.)
These OSes have the concept of `over-the-shoulder' credentials: if you
are running without full administrator privileges and do something which
needs them you may be prompted with one or more security-check dialog
boxes, and may be required to provide administrator credentials or
confirm that you really want to take that action.

Vista and later will report that the R installer has an `unidentified
publisher' or `unknown publisher' and ask if it should be run.  System
administrators can disable installing applications from non-trusted
sources, in which case you will have to persuade them that R is
trustworthy, or digitally sign the R installer yourself, or (unless this
is also disabled) run the installer from a standard account and install
into your own file area.  (The same issues apply to the @file{.msi}
version of the installer.)

If you install R as a standard user into your own file space and use it
under the same account, there are no known permission issues.

If you use the default Administrator account (without `admin approval
mode' being turned on) and install/update packages (in the system area
or elsewhere), no issues are known.

If you use an account in the local Administrators group in `admin
approval mode' (which is the intended norm under these OSes),
installation will make use of `over-the-shoulder' credentials.  You will
run into problems if you try installing (including updating) packages in
the main R library.  (It would be nice if at that point R could use
over-the-shoulder credentials, but they apply to processes as a whole.
Vista and later disallow creating @code{.dll} files in the system area
without credentials.)  There are several ways around this.

@itemize
@item
Run R with Administrator privileges in sessions where you want to
install packages.  (Do so by right-clicking on the R shortcut and
selecting 'Run as Administrator'.)

@item
Transfer ownership of the R installation to the user which installed R.
To do so, use the security tab on the @samp{Properties} of the top-level
R folder and give `Full Control' over this directory to the user (not
just the Administrator group).

@item
Install packages into a different library tree owned by the account used to
install R.

For an installation to be used by a single user, the simplest way is to
make use of a `personal library': @xref{I don't have permission to write
to the @RWVER@\library directory}.

For a site installation, you can create a site-wide library directory
anywhere convenient, and add it to the default package search path for
all users via @env{R_LIBS_SITE} in @file{etc\Renviron.site}.  @xref{What
are HOME and working directories?}.  There is a standard location for a
site library, the @file{site-library} directory in the top-level R
folder (which you would need to create with full control for the R
installation account).  This will be used for installation in preference
to the main library folder if it exists.

This approach will not allow you to update the recommended packages
unless you `Run as administrator': we suggest you use an R session
running under Administrator privileges when updating those.
@end itemize


Another issue with Vista was that the standard POSIX ways that R uses
(e.g.@: in @code{file.info} and @code{file.access}) to look at file
permissions no longer work reliably.  @code{file.access} was re-written
to work with Windows NT-based security and the new version seems much
more reliable with these OSes (but still not 100% correct).

On suitably recent hardware Vista and later can prevent the execution of
code from data areas via `Data Execution Prevention' (from a tab in
System Properties -> Advanced -> Performance), and sysadmins can turn
this on for all programs.  R runs correctly with DEP enabled.


@node Quotes don't come out right on the console/terminal/pager, There is no tilde on my keyboard, Does R run under Windows Vista?, Installation and Usage
@section Quotes don't come out right on the console/terminal/pager.

R may make use of directional quotes that are not always rendered
correctly by Windows: these are used by default only by @code{Rgui} in
suitable locales (not Chinese/Japanese/Korean).

Whether these are used in R output (from functions @code{sQuote} and
@code{dQuote}) is controlled by @code{getOption("useFancyQuotes")} whose
default is @code{FALSE} except for the @code{Rgui} console.  There are
two potential problems with rendering directional quotes.  The first is
with running @code{Rterm}: in European locales the `Windows Command
Prompt' is by default set up to use MS-DOS and not Windows default
encodings: this can be changed via @command{chcp}, with @command{chcp
1252} being appropriate for Western European (including English)
locales.  The other is that the default raster fonts only include
directional single quotes and not directional double quotes (which will
probably be rendered as a filled rectangle).

Directional quotes will also be used in text help which is normally
displayed in R's internal pager: these may not be rendered correctly in
an external pager.  They are also used in HTML help, where most browsers
use fonts which render them correctly.

The font used can affect whether quotes are rendered correctly.  The
default font in the @code{Rgui} console and internal pager is
@code{Courier New}, which has directional quotes on all the systems we
tried.  @code{Lucida Console} has elegant glyphs for directional quotes
(but seems rather light unless ClearType is in use): @code{Consolas} is
another font which we often select when ClearType is in use.
Non-TrueType fonts such as @code{Courier} and @code{FixedSys} lack
directional double quotes on all the systems we tried.

There is a related problem with using @code{Sweave} output in
@code{Rgui}, for LaTeX needs to be told about the encoding of
directional quotes by including in the LaTeX preamble e.g.@: (for a
Western European locale)

@example
\usepackage[cp1252]@{inputenc@}
@end example

@noindent
or their use suppressed by @code{options(useFancyQuotes=FALSE)}.

@node There is no tilde on my keyboard, Can I use R on 64-bit Windows?, Quotes don't come out right on the console/terminal/pager, Installation and Usage
@section There is no tilde on my keyboard!

Where tilde does not appear on the main keyboard, it can normally be
accessed by pressing AltGr (the right Alt key) plus some other key.
This is @code{]} in Canadian (multilingual), German and Scandinavian
layouts, @code{1} in Eastern Europe, @code{[} in Portuguese, @code{4} or
@code{5} in Spanish, @code{/} in Francophone Belgian, and so on.  For
some keyboards the uses of AltGr are at
@url{http://office.microsoft.com/@/en-us/@/word/@/HP052590631033.aspx}:
you can explore those for your keyboard via the `On-Screen Keyboard'
(under Ease of access on Windows 7).

On all Windows versions you should be able to get tilde by holding the
down the left Alt key and typing 0126 on the numeric keypad (if you have
one), then releasing the Alt key.

@node Can I use R on 64-bit Windows?, Should I run 32-bit or 64-bit R?, There is no tilde on my keyboard, Installation and Usage
@section Can I use R on 64-bit Windows?

The 32-bit build of R for Windows will run on both 32-bit and
64-bit@footnote{what Windows calls x64 for x86-64 CPUs, not the very
rare ia64 Windows for Itanium CPUs.} versions of Windows.  64-bit
versions of Windows run 32-bit executables under the WOW (Windows on
Windows) subsystem: they run in almost exactly the same way as on a
32-bit version of Windows, except that the address limit for the R
process is 4GB (rather than 2GB or perhaps 3GB).

When R is installed on 64-bit Windows there is the option of installing
32- and/or 64-bit builds: the default is to install both. If you are
using the 32-bit build, replace @samp{x64} by @samp{i386} in the
examples in this FAQ.

@node Should I run 32-bit or 64-bit R?, Can both 32- and 64-bit R be installed on the same machine?, Can I use R on 64-bit Windows?, Installation and Usage
@section Should I run 32-bit or 64-bit R?

Obviously, only relevant if you are using 64-bit Windows.

For most users we would recommend using the `native' build, that is the
32-bit version on 32-bit Windows and the 64-bit version of 64-bit Windows.

The advantage of a native 64-bit application is that it gets a 64-bit
address space and hence can address far more than 4GB (how much depends
on the version of Windows, but in principle 8TB).  This allows a single
process to take advantage of more than 4GB of RAM (if available) and for
R's memory manager to more easily handle large objects (in particular
those of 1GB or more).  The disadvantages are that all the pointers are
8 rather than 4 bytes and so small objects are larger and more data has
to be moved around, and that less external software is available for
64-bit versions of the OS. The 64-bit compilers are able to take
advantage of extra features of all x86-64 chips (more registers, SSE2/3
instructions, @dots{}) and so the code may run faster despite using
larger pointers.  The 64-bit build is nowadays usually slightly faster
than the 32-bit build on a recent CPU (Intel Core 2 or later or AMD
equivalent).

For advanced users the choice may be dictated by whether the contributed
packages needed are available in 64-bit builds (although CRAN only
offers 32/64-bit builds).  The considerations can be more complex: for
example 32/64-bit @code{RODBC} need 32/64-bit ODBC drivers respectively,
and where both exist they may not be able to be installed together.  An
extreme example is the Microsoft Access/Excel ODBC drivers: if you have
installed 64-bit Microsoft Office you can only install the 64-bit
drivers and so need to use 64-bit @code{RODBC} and hence R.  (And
similarly for 32-bit Microsoft Office.)

@node Can both 32- and 64-bit R be installed on the same machine?, Rcmd is not found in my PATH!, Should I run 32-bit or 64-bit R?, Installation and Usage
@section Can both 32- and 64-bit R be installed on the same machine?

Obviously, only relevant if the machine is running a 64-bit version of
Windows -- simply select both when using the installer.  You can also go
back and add 64-bit components to a 32-bit install, or @emph{vice versa}.

For many Registry items, 32- and 64-bit programs have different views of
the Registry, but clashes can occur.  The most obvious problem is the
file association for @file{.RData} files, which will use the last
installation for which this option is selected, and if that was for an
installation of both, will use 64-bit R.  To change the association the
safest way is to edit the Registry entry
@samp{HKEY_CLASSES_ROOT\RWorkspace\shell\open\command}
and replace @samp{x64} by @samp{i386} or @emph{vice versa}.


@node Rcmd is not found in my PATH!,  , Can both 32- and 64-bit R be installed on the same machine?, Installation and Usage
@section Rcmd is not found in my PATH!

This has often been reported after an upgrade.

The R installer does not put @command{Rcmd.exe} (nor any other R
executable) on your @env{PATH}.  What seems to have happened is that
people did this for themselves in the past, upgraded R (which by default
will install to a different location) and un-installed the old version
of R.  If you do that (or install R for the first time), you need to
edit the @env{PATH}.

The element you want to add to the path is something like

@example
c:\Program Files\R\R-3.0.0\bin\x64
@end example

@noindent
for 64-bit @command{Rcmd.exe}, replacing @code{x64} by @code{i386} for
32-bit.

How you set the path depends on your OS version.  On Windows XP/Server
2003 you can use `System' in the control panel or the properties of `My
Computer' (under the `Advanced' tab).  Under more recent versions, go to
`User Accounts' in the Control Panel, and select your account and then
`Change my environment variables'.  (System policies can prevent end
users making changes.)

An alternative is to set the @env{PATH} in the shell you are running
(@command{Rcmd.exe} is  a command-line program).  For those using the
standard Windows `Command Prompt' Duncan Murdoch suggested:
@c https://stat.ethz.ch/pipermail/r-help/2011-October/293413.html

The simple way to do it just for the command prompt is to write a little 
batch file @command{setpath.bat} containing

@example
set PATH=newstuff;%PATH%
@end example

@noindent
and then run @command{cmd} with

@example
CMD /K setpath.bat
@end example


@newchap{}
@node Languages and Internationalization, Packages, Installation and Usage, Top
@chapter Languages and Internationalization

@menu
* The installer does not offer my language::  
* I want R in English!::        
* I want to run R in Chinese/Japanese/Korean::  
* I selected English for installation but R runs in Chinese::  
* I would like to be able to use Japanese fonts::  
* I don't see characters with accents at the R console::  
* The dialog buttons are not translated::  
@end menu

@node The installer does not offer my language, I want R in English!, Languages and Internationalization, Languages and Internationalization
@section The installer does not offer my language.

Only a limited range of languages is supported, currently
Catalan,
both Simplified and Traditional Chinese,
Czech,
Danish,
Dutch,
Finnish,
French,
German,
Greek,
Hebrew,
Hungarian,
Italian,
Japanese,
Korean,
Norwegian,
Polish,
Portuguese (Brazil),
Portuguese (Portugal),
Russian,
Slovenian,
Spanish (Spain)
and Ukranian.

@node I want R in English!, I want to run R in Chinese/Japanese/Korean, The installer does not offer my language, Languages and Internationalization
@section I want R in English (and not in French/Chinese/...)!

The default behaviour of R is to try to run in the language you run
Windows in.

Apparently some users want@footnote{or they may have no choice:
apparently some Windows editions are tied to a specific language.}
Windows in their native language, but not R.  To do so, set
@code{LANGUAGE=en} as discussed in Q2.2 and Q2.15, or in the
@file{Rconsole} file.

@node I want to run R in Chinese/Japanese/Korean, I selected English for installation but R runs in Chinese, I want R in English!, Languages and Internationalization
@section I want to run R in Chinese/Japanese/Korean.

Suitable versions of Windows support what it calls `East Asian'
languages, but e.g.@: Western installations of Windows often do not have
such support.  So we need to assume that your copy of Windows does.

Both @command{Rterm.exe} and @command{Rgui.exe} support single- and
double-width characters.  It will be necessary to select suitable fonts
in files @file{Rconsole} and @file{Rdevga} (see @code{?Rconsole} or the
comments in the files: the system versions are in the @file{etc}
folder); in the latter you can replace @code{Arial} by @code{Arial
Unicode MS}, and we tried @code{FixedSys} and @code{MS Mincho} in
@file{Rconsole}.  (Note that @file{Rdevga} only applies to Windows
graphics devices and not, say, to @code{pdf}.)  

Note that it is important that the console font uses double-width
characters for all CJK characters (as that is what the width table used
assumes): this is true for the fonts intended for CJK locales but not
for example for @code{Lucida Console} or @code{Consolas}.

You do need to ensure that R is running in a suitable locale: use
@code{Sys.getlocale()} to find out.  (CJK users may be used to their
language characters always being available, which is the case for
so-called `Unicode' Windows applications.  However, R is primarily
written for Unix-alikes and is not therefore `Unicode' in the Windows
sense.)  You can find suitable locale names from
@uref{http://msdn.microsoft.com/@/library/@/default.asp?url=/@/library/@/en-us/@/vccore98/@/html/@/_crt_language_and_country_strings.asp}:
beware that @code{"Chinese"} is Traditional Chinese (code page 950,
Big5) and @code{"chs"} is needed for Simplified Chinese (code page 936,
GB2312).

When using @command{Rterm} the window in which it is run has to be set
up to use a suitable font (e.g. @code{Lucida Console} or
@code{Consolas}, not the OEM raster fonts) and a suitable codepage
(which for the Windows Cmd shell can be done using @command{chcp}).

@node I selected English for installation but R runs in Chinese, I would like to be able to use Japanese fonts, I want to run R in Chinese/Japanese/Korean, Languages and Internationalization
@section I selected English for installation but R runs in Chinese.

Precisely, you selected English @strong{for installation}!  The language
of the installer has nothing to do with the language used to run R: this
is completely standard Windows practice (and necessary as different
users of the computer may use different languages).

The language R uses for menus and messages is determined by the
@emph{locale}: please read the appropriate manual (`R Installation and
Administration') for the details.  You can ensure that R uses English
messages by appending @code{LANGUAGE=en} to the shortcut you use to
start R, or setting it in the @file{Rconsole} file.

@node I would like to be able to use Japanese fonts, I don't see characters with accents at the R console, I selected English for installation but R runs in Chinese, Languages and Internationalization
@section I would like to be able to use Japanese fonts.

for example, in the console and to annotate graphs.  Similar comments
apply to any non-Western-European language.

With suitable fonts, this should just work.  You will need to set MS
Mincho or MS Gothic as the console font to ensure that single- and
double-width characters are handled correctly.  The default graphics
fonts for the @code{windows()} graphics device can handle most common
Japanese characters, but more specialized fonts may need to be set.
(See Q5.2 for how to set fonts: the console font can also be set from
the `GUI preferences' menu item.)  The help for @code{windowsFonts} has
examples of selecting Japanese fonts for the @code{windows()} family of
devices.

In addition, the Hershey vector fonts (see @code{?Hershey},
@code{?Japanese} and @code{demo(Japanese)}) can be used on any graphics
device to display Japanese characters.

To use non-Latin-1 characters in the @code{postscript} graphics device,
see its help page (which also applies to @code{pdf}).

@node I don't see characters with accents at the R console, The dialog buttons are not translated, I would like to be able to use Japanese fonts, Languages and Internationalization
@section I don't see characters with accents at the R console, for example in ?text.

You need to specify a font in @file{Rconsole} (see Q5.2) that supports
the encoding in use.  This used to be a problem in earlier versions of
Windows, but now it is hard to find a font which does not.

Support for these characters within @command{Rterm} depends on the
environment (the terminal window and shell, including locale and
codepage settings) within which it is run as well as the font used by
the terminal window.  Those are usually on legacy DOS settings and need
to altered.

@node The dialog buttons are not translated,  , I don't see characters with accents at the R console, Languages and Internationalization
@section The dialog buttons are not translated.

In most cases they actually are, but by Windows.  Setting the locale or
the @code{LANGUAGE} environment variable does not change the Windows
setting of its `UI language'.  Vista and later talk about the 'UI
language' and the 'system locale' for setting the language used for
`non-Unicode' programs (on the 'Administrative' tab in Windows 7).

If you have Windows running completely in say French or Chinese these
settings are likely to be consistent.  However, if you try to run
Windows in one language and R in another, you may find the way Windows
handles internationalization slightly odd.
@c For further details see
@c @uref{http://msdn.microsoft.com/@/library/@/default.asp?url=/@/library/@/en-us/@/intl/@/nls_0ddl.asp}.

@newchap{}
@node Packages, Windows Features, Languages and Internationalization, Top
@chapter Packages


@menu
* Can I install packages into libraries in this version?::  
* I don't have permission to write to the @RWVER@\library directory::  
* The packages I installed do not appear in the HTML help system::  
* My functions are not found by the HTML help search system.::  
* Loading a package fails.::    
* Package TclTk does not work.::  
* Hyperlinks in HTML do not work.::  
* update.packages() fails::     
* How do I add to the list of repositories?::  
* Help is not shown for some of the packages::  
* How do I get static HTML pages?::  
* How can I get a binary version of a package?::  
* Package xxx is out of date for Windows::  
* No binary packages appear to be available for my version of R::  
* How do I build my package for both 32- and 64-bit R?::  
@end menu


@node Can I install packages into libraries in this version?, I don't have permission to write to the @RWVER@\library directory, Packages, Packages
@section Can I install packages into libraries in this version?

Yes, but you will need a lot of tools to do so, unless the author or the
maintainers of the @file{bin/windows/contrib} section on CRAN have been
kind enough to provide a binary version for Windows as a
@code{.zip} file, or the package is a simple one involving no compiled
code (and binary versions are usually available for simple
packages).

You can install binary packages either from a repository such as
CRAN or from a local @code{.zip} file by using @code{install.packages}:
see its help page.  There are menu items on the @code{Packages} menu to
provide a point-and-click interface to package installation.  The
packages for each minor (2.x.? or 3.x.?) version will be stored in a separate area,
so for R 3.0.? the files are in @file{bin/windows/contrib/3.0}.

Note that the binary versions on CRAN are unsupported: see
@uref{http://cran.r-project.org/@/bin/@/windows/@/contrib/@/3.0/@/ReadMe},
which also gives the locations of a few other binary packages.

If there is no binary package or that is not up-to-date or you prefer
compiling from source, read the `R Installation and Administration'
manual section on `Add-on Packages'.  Source packages which contain no
C/C++/Fortran code which needs compilation can simply be installed by
@code{install.packages(type = "source")} or @command{R CMD INSTALL
pkgname} at a Windows command prompt.  For packages with code that needs
compilation you will need to collect and install several tools: you can
download them via the portal at
@uref{http://www.murdoch-sutherland.com/Rtools/}.  Once you have done
so, just run @command{R CMD INSTALL pkgname} at a Windows command
prompt.  To check the package (including running all the examples on its
help pages and in its test suite, if any) use @command{R CMD check
pkgname}: see the @emph{`Writing R Extensions'} manual.

Note that setting up Windows to install a source package that needs
compilation is rather tricky; please do ensure that you have followed
the instructions @strong{exactly}.  At least 90% of the questions asked
are because people have not done so.

If you have a source package that is known to work on a Unix-alike
system, you can try the automated Windows binary package builder
documented at @url{http://win-builder.r-project.org}.

@node I don't have permission to write to the @RWVER@\library directory, The packages I installed do not appear in the HTML help system, Can I install packages into libraries in this version?, Packages
@section I don't have permission to write to the @file{@RWVER@\library} directory.

You can install packages anywhere and use the environment variable
@env{R_LIBS} (@pxref{How do I set environment variables?}) to point to
the library location(s).

Suppose your packages are installed in @file{p:\myRlib}.  Then you can
EITHER

@example
set the environment variable R_LIBS to p:/myRlib before starting R
@end example

OR use a package by, e.g.@:

@example
library(mypkg, lib.loc="p:/myRlib")
@end example

You can also have a personal library, which defaults to the directory
@file{R\win-library\@var{x.y}} of your home directory for versions
@var{x.y.z} of R.  This location can be changed by setting the
environment variable @env{R_LIBS_USER}, and can be found from inside R
by running @code{Sys.getenv("R_LIBS_USER")}.  This will only be used if
it exists so you may need to create it: you can use

@example
dir.create(Sys.getenv("R_LIBS_USER"), recursive = TRUE)
@end example

@noindent
to do so.  If you use @code{install.packages} and do not have permission
to write to the main or site library, it should offer to create a personal
library for you and install the packages there.  This will also happen
if @code{update.packages} offers to update packages for you in a library
where you do not have write permission.

There can be additional security issues under Windows Vista and later:
@xref{Does R run under Windows Vista?}.  In particular, the detection
that a standard user has suitable permissions appears to be unreliable
under Vista, so we recommend that you do create a personal directory
yourself.


@node The packages I installed do not appear in the HTML help system, My functions are not found by the HTML help search system., I don't have permission to write to the @RWVER@\library directory, Packages
@section The packages I installed do not appear in the HTML help system.

This question applied to the pre-2.10.0 HTML help system, which has been
replaced.


@node My functions are not found by the HTML help search system., Loading a package fails., The packages I installed do not appear in the HTML help system, Packages
@section My functions are not found by the HTML help search system.

This question applied to the pre-2.10.0 search system, which has been
replaced.


@node Loading a package fails., Package TclTk does not work., My functions are not found by the HTML help search system., Packages
@section Loading a package fails.

Is the package installed for this version of R?   Packages need to have
prepared for R 2.10.0 or later, and packages containing compiled code
for R 2.12.0 or later.

You can tell the version the package was compiled for by looking at the
@samp{Built:} line in its @file{DESCRIPTION} file 

For a small number of binary packages you need to install additional
software and have its DLLs in your @code{PATH}.  Windows will normally
give an informative message about a certain DLL not being found.  See
@uref{http://cran.r-project.org/@/bin/@/windows/@/contrib/@/3.0/@/ReadMe} for a
listing of some of these packages (notably @code{RGtk2},
@code{cairoDevice}, @code{rggobi}, @code{rJava}, @code{rjags} and some
of the packages connecting to databases).


@node Package TclTk does not work., Hyperlinks in HTML do not work., Loading a package fails., Packages
@section Package TclTk does not work.

For package @code{tcltk} to work (try @code{demo(tkdensity)} or
@code{demo(tkttest)} after @code{library(tcltk)}) you need to have Tcl/Tk
installed.  This part of the R installation, so it should be there.

However, if you have the environment variable @env{MY_TCLTK} set to a
non-empty value, it is assumed that you want to use a different Tcl/Tk
8.5.x installation with the path to its @file{bin} directory given by
value of @env{MY_TCLTK}, and that this is set up correctly (with
@env{TCL_LIBRARY} set if needed).  Note that you do need 8.5.x and not
8.4.x nor 8.6.0, and you do need the architecture to match, that is a
32-bit or 64-bit build of Tcl/Tk to match the R build in use.  (There is
no guarantee that a 64-bit build will work: it depends on the layout it
uses.)

In the past several package authors have suggested using ActiveTcl
(@uref{http://www.activestate.com/@/Products/@/activetcl/}) as a way to
get Tcl/Tk extensions (but the support files do contain the most
commonly used @code{TkTable} and @code{BWidget} extensions).  This could
be used by setting (for a default install)

@example
MY_TCLTK=c:/Tcl/bin
@end example

@noindent
@strong{but} current versions do not by default contain any extra
extensions (although they may be downloaded via the @code{Teacup}
facility) and this only works for 32-bit R.


@node  Hyperlinks in HTML do not work., update.packages() fails, Package TclTk does not work., Packages
@section Hyperlinks in HTML sometimes do not work.

This question was much more relevant prior to version 2.10.0.

They may still not work between packages installed in different libraries
if the HTTP server has been disabled: the remedy is not to do that!

@node update.packages() fails, How do I add to the list of repositories?, Hyperlinks in HTML do not work., Packages
@section @code{update.packages()} fails.

You may not be able to update a package which is in use: Windows `locks'
the package's DLL when it is loaded.  So use @code{update.packages()}
(or the menu equivalent) in a new session.

If you put @code{library(foo)} in your @file{.Rprofile} you will need to
start R with @option{--vanilla} to be able to update package @code{foo}.
If you set @env{R_DEFAULT_PACKAGES} to include @code{foo}, you will
need to unset it temporarily.

It has been reported that some other software has interfered with the
installation process by preventing the renaming of temporary files,
@emph{Google Desktop} being a known example.


@node How do I add to the list of repositories?, Help is not shown for some of the packages, update.packages() fails, Packages
@section How do I add to the list of repositories?

as shown in the @code{Select repositories...} item on the
@code{Packages} menu?

This reads from the tab-delimited file @file{R_HOME\etc\repositories},
which you can edit, or put a modified copy at @file{.R\repositories}
in your HOME directory (@pxref{What are HOME and working directories?}).

@node Help is not shown for some of the packages, How do I get static HTML pages?, How do I add to the list of repositories?, Packages
@section Help is not shown for some of the packages

This was about Compiled HTML help, which has not been supported since R
2.10.0.

@node How do I get static HTML pages?, How can I get a binary version of a package?, Help is not shown for some of the packages, Packages
@section How do I get static HTML pages?

We presume you want to do this for some special purpose: R's help system
will not make use of them, links across library directories will not
work (unlike R < 2.10.0), ambiguous links will be resolved at install
time and missing links will be broken (previous versions used
JavaScript to look for them at run time).  But if you still want them,
here is how to do it.

Static HTML pages are not part of the binary distribution, so you will
need to install R and/or packages from their sources.  To install just a
few packages with static HTML pages use

@example
R CMD INSTALL --html @var{pkg1} @var{pkg2} @dots{}
@end example

To install R itself with static HTML pages you need to build it from the
sources for yourself.  Change the following line in file
@file{MkRules.local} (after copying @file{MkRules.dist} to
@file{MkRules.local} if that has not already been done).

@example
# set this to YES to build static HTML help
BUILD_HTML = NO
@end example

@noindent
and them all packages installed by that build of R will (by default) be
installed with static HTML pages.

@node How can I get a binary version of a package?, Package xxx is out of date for Windows, How do I get static HTML pages?, Packages
@section How can I get a binary version of a package?

Presumably one not available on CRAN, BioC or a similar repository.

If you have a source package that is known to work on a Unix-alike
system, you can try the automated Windows binary package builder
documented at @url{http://win-builder.r-project.org}.  If the package is
not yours, please remember to change the maintainer address so the
results go to you and not the author(s)!

However, if a CRAN package is not available in binary form or only
available for 32-bit R, this usually means that there is a problem
with some dependent package or external software (often mentioned in the
@file{@@ReadMe} file in the binary repository directory).  You can email
@email{R-windows@@r-project.org} expressing a wish for such a package to
be ported---the maintainers will take such wishes into account when
prioritizing work on binary packages.

In many cases installing packages from the sources is not at all
difficult (especially if the package contains no compiled code), so
please attempt that for yourself before requesting help from the busy
volunteers.

@node Package xxx is out of date for Windows, No binary packages appear to be available for my version of R, How can I get a binary version of a package?, Packages
@section Package xxx is out of date for Windows

Here are three possible reasons:

You are simply impatient, and need to wait until the binary package has
been built and propagated to the CRAN mirror you are using.  This
normally (but not always) happens within 24 hours.  Sometimes mirrors
do get behind (especially unofficial ones), so you could try another
mirror.  (Mirror statistics are linked near the top of the CRAN mirror
page at @uref{http://cran.r-project.org/mirrors.html}.)

The latest version of the package might require a later version of R
than the one you are using.  You can check on the package's HTML page on
CRAN, and update your R if needed.

Your R might be too old.  Binary packages for the 2.x series were built
(if possible) whilst 2.(x+1) is current, and once 3.0.0 is released,
binary packages for 2.14.x will be frozen.  You can always try
installing from the sources.

@node No binary packages appear to be available for my version of R, How do I build my package for both 32- and 64-bit R?, Package xxx is out of date for Windows, Packages
@section No binary packages appear to be available for my version of R

How old is it?  The CRAN policy is to archive binary packages two years
after the 2.x series is closed.  Other repositories may do so sooner.

If you are using an R version that old we advise you to update your R,
but you do also have the option of installing packages from their
source.


@node How do I build my package for both 32- and 64-bit R?,  , No binary packages appear to be available for my version of R, Packages
@section How do I build my package for both 32- and 64-bit R?

Packages without compiled code nor a @file{configure.win} script will
run on both 32- and 64-bit R.

Packages with compiled code but no @file{configure.win} nor
@code{src/Makefile.win} file will be built for both when running on a
64-bit version of Windows if both versions of R are installed.

An empty @file{configure.win} is treated in the same way as if none
existed.  Also, there is a list of packages known to have an
architecture-independent @file{configure.win} hardcoded into @command{R
CMD INSTALL}, and for these packages, both architectures will be built
under the above conditions.  Other packages can be installed with
@file{configure.win} run for just the first architecture by using option
@option{--force-biarch}. 

Any package can be installed for first one architecture and then the
other with option @option{--merge-multiarch}, but the package source
must be a tarball (and as before, running on a 64-bit version of Windows
with both versions of R installed).

Finally, as from R 2.15.0, a package without a @code{src/Makefile.win}
file and no or empty or architecture-independent @code{configure.win}
file can be installed for both architectures from 32-bit Windows if the
64-bit components were selected when R was installed and option
@option{--compile-both} is given.  Obviously, only the 32-bit
installation can be tested.

@newchap{}
@node Windows Features, Workspaces, Packages, Top
@chapter Windows Features

@menu
* What should I expect to behave differently from the Unix version::  
* I hear about some nifty features.::  
* Circles appear as ovals on screen::  
* How do I move focus to a graphics window or the console?::  
* What does TAB completion do?::  
@end menu


@node  What should I expect to behave differently from the Unix version, I hear about some nifty features., Windows Features, Windows Features
@section  What should I expect to behave differently from the Unix version of R?

@itemize @bullet
@item
R commands can be interrupted by @key{Esc} in @command{Rgui.exe}
and @key{Ctrl-break} or @key{Ctrl-C} in @command{Rterm.exe}:
@key{Ctrl-C} is used for copying in @command{Rgui.exe}.

@item 
Command-line editing is always available, but is somewhat simpler than the
readline-based editing on Unix.  For @command{Rgui.exe}, the menu item
`Help | Console' will give details.  For @command{Rterm.exe} see file
@file{README.rterm}.

@item Paths to files (e.g.@: in @code{source()}) can be specified with
either "/" or "\\".

@item @code{system()} is slightly different: see its help page and that
of @code{shell()}.
@end itemize


@node I hear about some nifty features., Circles appear as ovals on screen, What should I expect to behave differently from the Unix version, Windows Features
@section I hear about some nifty features: please tell me about them!

You have read the file @file{README.@RWVER@}? There are file menus on
the R console, pager and graphics windows.  You can source and save from
those menus, and copy the graphics to @code{png}, @code{jpeg},
@code{bmp}, @code{postscript}, @code{PDF} or @code{metafile}.  There are
right-click menus giving shortcuts to menu items, and optionally
toolbars with buttons giving shortcuts to frequent operations.

If you resize the R console the @code{options(width=)} is automatically
set to the console width (unless disabled in the configuration file).

The graphics has a history mechanism.  As @file{README.@RWVER@} says:

@quotation
`The History menu allows the recording of plots.  When plots have been
recorded they can be reviewed by @key{PgUp} and @key{PgDn}, saved and
replaced.  Recording can be turned on automatically (the Recording item
on the list) or individual plots can be added (Add or the @key{INS}
key).  The whole plot history can be saved to or retrieved from an R
variable in the global environment.
  The format of recorded plots may change between R versions.
  Recorded plots should @strong{not} be used as a permanent
  storage format for R plots.

There is only one graphics history shared by all the windows devices.'
@end quotation

@noindent
The R console and graphics windows have configuration files stored in
the @file{RHOME\etc} directory called @file{Rconsole} and @file{Rdevga};
you can keep personal copies in your @file{HOME} directory.  They contain
comments which should suffice for you to edit them to your
preferences.  For more details see @code{?Rconsole}.
There is a GUI preferences editor invoked from the @code{Edit} menu which
can be used to edit the file @file{Rconsole}.


@node Circles appear as ovals on screen, How do I move focus to a graphics window or the console?, I hear about some nifty features., Windows Features
@section Circles appear as ovals on screen.

The graphics system asks Windows for the number of pixels per inch in
the X and Y directions, and uses that to size graphics (which in R are
in units of inches).  Sometimes the answer is a complete invention, and
in any case Windows will not know exactly how the horizontal and
vertical size have been set on a monitor which allows them to be
adjusted.  You can specify correct values either in the call to
@code{windows} or as options: see @code{?windows}.  (Typically these are
of the order of 100.)

On one of our systems, the screen height was reported as 240mm, and the
width as 300mm in 1280 x 1024 mode and 320mm in 1280 x 960 and 1600 x 1200
modes.  In fact it was a 21" monitor and 400mm x 300mm!

@node How do I move focus to a graphics window or the console?, What does TAB completion do?, Circles appear as ovals on screen, Windows Features
@section How do I move focus to a graphics window or the console?

You may want to do this from within a function, for example when calling
@samp{identify} or @samp{readline}.  Use the function
@samp{bringToTop()}.  With its default argument it brings the active
graphics window to the top and gives it focus.  With argument @samp{-1}
it brings the console to the top and gives it focus.

This works for @command{Rgui.exe} in MDI and SDI modes, and can be used for
graphics windows from @command{Rterm.exe} (although Windows may not always
act on it).


@node What does TAB completion do?,  , How do I move focus to a graphics window or the console?, Windows Features
@section What does TAB completion do?

Both @command{Rgui} and @command{Rterm} support @kbd{TAB} completion.
Hitting @kbd{TAB} whilst entering a command line completes the current
`word' as far as is unambiguously possible.  Hitting @kbd{TAB} a second
time then shows a list of possible completions (or the first few if
there are many): the user can then enter one or more characters and hit
@kbd{TAB} again.

What is it `completing'?  There are two modes: within an unterminated
(single- or double-) quoted expression it completes file
paths.@footnote{It does not have a complete understanding of Windows
file paths, but can complete most relative or absolute file paths,
including drives and spaces. Relative paths on drives are not handled,
for example.}  Otherwise, it is completing R expressions: most obviously
it will match visible R object names and keywords, so @kbd{apr} followed
by @kbd{TAB} will (in a vanilla session) complete to @code{apropos}.
After a function name and parenthesis (e.g.@: @kbd{apropos(}) it will
complete argument names (and @kbd{=}), and after @kbd{$} or @kbd{@@} it
will complete list components or slot names respectively.

This feature can be turned off: @command{Rgui} has two menu items to do
so, and setting the environment variable @env{R_COMPLETION} to
@code{FALSE} turns it off completely for both @command{Rgui} and
@command{Rterm}.  Further, the behaviour can be fine-tuned: to see the
settings available use

@example
?rc.settings
@end example

@noindent
which also explains how the various types of completion work.

This feature is very similar to the completion available in the
@code{readline}-based command line interface on Unix-alikes: the OS X
GUI @code{R.app} has a different completion scheme.

@newchap{}
@node Workspaces, The R Console, Windows Features, Top
@chapter Workspaces


@menu
* My workspace gets saved in a strange place.  How do I stop this?::  
* How do I store my workspace in a different place?::  
* Can I load workspaces saved under Unix/GNU-Linux or OS X?::  
@end menu


@node My workspace gets saved in a strange place.  How do I stop this?, How do I store my workspace in a different place?, Workspaces, Workspaces
@section My workspace gets saved in a strange place: how do I stop this?

Have you changed the working directory?: see Q6.2.


@node How do I store my workspace in a different place?, Can I load workspaces saved under Unix/GNU-Linux or OS X?, My workspace gets saved in a strange place.  How do I stop this?, Workspaces
@section How do I store my workspace in a different place?

Use the `File | Change Dir...' menu item to select a new working
directory: this defaults to the last directory you loaded a file
from.  The workspace is saved in the working directory.  You can also
save a snapshot of the workspace from the `Save Workspace...' menu item.

From the command line you can change the working directory by the
function @code{setwd}: see its help page.


@node Can I load workspaces saved under Unix/GNU-Linux or OS X?,  , How do I store my workspace in a different place?, Workspaces
@section Can I load workspaces saved under Unix/GNU-Linux or Mac OS X?

Yes.  All ports of R use the same format for saved workspaces, so they
are interchangeable (for the same 2.x.? version of R, at least).

Note though that character data in a workspace will be in a particular
encoding that is not recorded in the workspace, so workspaces containing
non-@acronym{ASCII} character data may not be interchangeable even on
the same OS.  Since R marks character data when it knows it to be in
UTF-8 or Latin-1 (including its Windows superset, CP1252), strings in
those encodings are likely to be transferred correctly: fortunately this
covers most of the common cases (OS X normally uses UTF-8, and Linux
users are likely to use UTF-8 or perhaps Latin-1 (which used to be used
for English)).

It is possible to save references to package namespaces when saving the
workspace: if that happens the package will need to be installed on the
machine loading the workspace.

@newchap{}
@node The R Console, Building from Source, Workspaces, Top
@chapter The R Console


@menu
* The output to the console seems to be delayed::  
* Long lines seem to be truncated.::  
@end menu




@node The output to the console seems to be delayed, Long lines seem to be truncated., The R Console, The R Console
@section When using Rgui the output to the console seems to be delayed.

This is deliberate: the console output is buffered and re-written in
chunks to be faster and less distracting.  You can turn buffering off or
on from the `Misc' menu or the right-click menu: @key{Ctrl-W} toggles
the setting.

If you are sourcing R code or writing from a function, there is another
option.  A call to the R function @code{flush.console()} will write out
the buffer and so update the console.


@node Long lines seem to be truncated.,  , The output to the console seems to be delayed, The R Console
@section Long lines in the console or pager are truncated.

They only @strong{seem} to be truncated: that $ at the end indicates you
can scroll the window to see the rest of the line.  Use the horizontal
scrollbar or the @key{CTRL + left/right arrow} keys to scroll
horizontally. (The @key{left/right arrow} keys work in the pager too.)



@newchap{}
@node Building from Source,  , The R Console, Top
@chapter Building from Source

@menu
* How can I compile R from source?::  
* Can I use a fast BLAS?::      
* How do I include compiled C code?::  
* How do I debug code that I have compiled and dyn.load-ed?::  
* How do I include C++ code?::  
* The output from my C code disappears.::  
* The output from my Fortran code disappears.::  
* The console freezes when my compiled code is running::  
@end menu


@node How can I compile R from source?, Can I use a fast BLAS?, Building from Source, Building from Source
@section How can I compile R from source?

See the `R Installation and Administration' manual (for the version of R
you want to install).

@node Can I use a fast BLAS?, How do I include compiled C code?, How can I compile R from source?, Building from Source
@section  Can I use a fast BLAS?

Fast BLAS (Basic Linear Algebra Subprograms,
@uref{http://www.netlib.org/@/blas/@/faq.html}) routines are used to
speed up numerical linear algebra.  There is support in the R sources
for the `tuned' BLAS called ATLAS
(@uref{http://math-atlas.sourceforge.net}).  The savings can be
appreciable but because ATLAS is tuned to a particular chip we can't use
it generally.  However, linear algebra on large matrices is not often an
important part of R computations, and more typical calculations on small
matrices may run slower.

BLAS support is supplied by the single DLL
@file{R_HOME\bin\x64\Rblas.dll}, and you can add a fast BLAS just by
replacing that.  Replacements for 32-bit R and some of the older common
chips are available on CRAN in directory
@file{bin/windows/contrib/ATLAS}.  See the R Installation and
Administration' manual for how to build an ATLAS @file{Rblas.dll} tuned
to your system using the R sources.  Unfortunately the process has been
less successful when tried for the common current chips such as Intel's
Core 2.

Versions of Dr Kazushige Goto's BLAS (see
@uref{http://en.wikipedia.org/wiki/Kazushige_Goto}) for 64-bit Windows
by Ei-Ji Nakama can be found at
@uref{http://prs.ism.ac.jp/~nakama/SurviveGotoBLAS2/binary/windows/x64/}.
Just download the file @file{Rblas.dll} appropriate to your CPU and
replace @file{@var{R_HOME}/bin/x64/Rblas.dll}.  (There is also a generic
version called @samp{DYNAMIC_ARCH} that tries to adapt itself to the CPU
found -- however if you know the exact CPU used it is better to download
the CPU-specific version.  Note that development of that BLAS was frozen
in 2010 so you will not find versions for recent CPUs.)

Note that fast BLAS implementations may give different (and often
slightly less accurate) results than the reference BLAS included in R.

@node  How do I include compiled C code?, How do I debug code that I have compiled and dyn.load-ed?, Can I use a fast BLAS?, Building from Source
@section How do I include compiled C code?

We strongly encourage you to do this @emph{via} building an R package:
see the @emph{`Writing R Extensions'} manual.  In any event you should
get and install the tools and toolchain mentioned in the `R Installation
and Administration' manual.  Then you can use
@example
...\bin\x64\R CMD SHLIB foo.c bar.f
@end example
@noindent
to make @file{foo.dll}.  Use @command{...\bin\x64\R CMD SHLIB --help} for
further options, or see @code{?SHLIB}.  (Replace @code{x64} by
@code{i386} for 64-bit R.)

If you want to use Visual C++, Borland C++ or other compilers, see the
appropriate section in @file{README.packages}.



@node How do I debug code that I have compiled and dyn.load-ed?, How do I include C++ code?, How do I include compiled C code?, Building from Source
@section How do I debug code that I have compiled and dyn.load-ed?

Debugging under Windows is often a fraught process, and sometimes does
not work at all.  If all you need is a @emph{just-in-time} debugger to
catch crashes, consider (32-bit) @code{Dr. Mingw} from the
@code{mingw-utils} bundle on @uref{http://www.mingw.org}.  That will be
able to pinpoint the error, most effectively if you build a version of R
with debugging information as described below.

First, build a version of the R system with debugging information by

@example
make clean
make DEBUG=T
@end example

@noindent
and make a debug version of your package by

@example
Rcmd INSTALL --debug mypkg
@end example

@noindent
You will need a suitable version of @command{gdb} which matches your
compiler.  Then you can debug by

@example
gdb /path/to/@RWVER@/bin/x64/Rgui.exe
@end example

@noindent
(or use @command{Rterm.exe}.)  However, note

@itemize @bullet
@item
@command{gdb} may only be able to find the source code if we run in the
location where the source was compiled (@file{@RWVER@/src/gnuwin32} for
the main system, @file{@RWVER@/src/library/mypkg/src} for a package),
unless told otherwise by the @command{directory} command.  It is most
convenient to set a list of code locations via @command{directory} commands
in the file @file{.gdbinit} in the directory from which @command{gdb} is
run.

@item
It is only possible to set breakpoints in a DLL after the DLL has
been loaded.  So a way to examine the function @code{tukeyline} in
package @code{stats} might be

@example
     gdb ../../../../bin/i386/Rgui.exe
     (gdb) break WinMain
     (gdb) run
     [ stops with R.dll loaded ]
     (gdb) break R_ReadConsole
     (gdb) continue
     [ stops with console running ]
     (gdb) continue
     Rconsole> library(stats)
     (gdb) break tukeyline
     (gdb) clear R_ReadConsole
     (gdb) continue
     Rconsole> example(line)
     ...
@end example

@noindent
Alternatively, in @command{Rgui} you can use the `Misc|Break to
debugger' menu item after your DLL is loaded.  The C function call
@code{breaktodebugger()} will do the same thing.

@item
Fortran symbols need an underline appended.

@item
Windows has little support for signals, so the Unix idea of running a
program under a debugger and sending it a signal to interrupt it and
drop control back to the debugger does not work with a MinGW version of
@command{gdb}.  It does often work with the @code{cygwin} version.

@item
Other debuggers than @command{gdb} can be used.  We have successfully
used the @command{insight} front-end to @command{gdb} (see
@uref{http://sources.redhat.com/@/insight/}: there is a MinGW port on
their site), and Borland's debugger with a DLL compiled in a Borland
compiler.

@end itemize

See
@uref{http://www.stats.uwo.ca/@/faculty/@/murdoch/@/software/@/debuggingR/@/gdb.shtml}
for some further details.


@node  How do I include C++ code?, The output from my C code disappears., How do I debug code that I have compiled and dyn.load-ed?, Building from Source
@section  How do I include C++ code?

You need to do two things:

(a) Write a wrapper to export the symbols you want to call from R as
 @code{extern "C"}.

(b) Include the C++ libraries in the link to make the DLL.  Suppose
@file{X.cc} contains your C++ code, and @file{X_main.cc} is the wrapper,
as in the example in @emph{`Writing R Extensions'}.  Then build the DLL by
(@command{gcc})

@example
...\bin\x64\R CMD SHLIB X.cc X_main.cc
@end example

@noindent
or (VC++, which requires extension @code{.cpp})

@example
cl /MT /c X.cpp X_main.cpp
link /dll /out:X.dll /export:X_main X.obj X_main.obj
@end example

@noindent
or (Borland C++, which also requires extension @code{.cpp})

@example
bcc32 -u- -WDE X.cpp X_main.cpp
@end example

@noindent
and call the entry point(s) in @code{X_R}, such as @code{X_main}.
Construction of static variables will occur when the DLL is loaded, and
destruction when the DLL is unloaded, usually when R terminates.

Note that you will not see the messages from this example in the GUI
console: see the next section.

This example used to be in package @file{cxx_0.0-x.tar.gz} in the
@file{src/contrib/Devel} section on CRAN, and could be compiled as a
package in the usual way on Windows.


@node  The output from my C code disappears., The output from my Fortran code disappears., How do I include C++ code?, Building from Source
@section  The output from my C code disappears.  Why?

The @command{Rgui.exe} console is a Windows application: writing to
@code{stdout} or @code{stderr} will not produce output in the
console.  (This will work with @command{Rterm.exe}.)  Use @code{Rprintf} or
@code{REprintf} instead.  These are declared in header file
@file{R_ext/PrtUtil.h}.

Note that output from the console is delayed (@pxref{The output to the
console seems to be delayed}), so that you will not normally see any
output before returning to the R prompt.


@node  The output from my Fortran code disappears., The console freezes when my compiled code is running, The output from my C code disappears., Building from Source
@section  The output from my Fortran code disappears.  Why?

Writing to Fortran output writes to a file, not the @command{Rgui} console.
Use one of the subroutines @code{dblepr}, @code{intpr} or @code{realpr}
documented in the @emph{`Writing R Extensions'} manual.

Note that output from the console is delayed (@pxref{The output to the
console seems to be delayed}), so that you will not normally see any
output before returning to the R prompt even when using the @code{xxxpr}
subroutines.


@node  The console freezes when my compiled code is running,  , The output from my Fortran code disappears., Building from Source
@section The console freezes when my compiled code is running.

The console, pagers and graphics window all run in the same thread
as the R engine.  To allow the console etc to respond to Windows events,
call @code{R_ProcessEvents()} periodically from your compiled code.
If you want output to be updated on the console, call
@code{R_FlushConsole()} and then @code{R_ProcessEvents()}.

@set LASTEDIT 2012-12-12
@ifhtml
@html
<hr WIDTH="100%">
<address>
Last edited @value{LASTEDIT}: comments to
<code><a href="mailto:R-windows@@R-project.org">R-windows@@r-project.org</a></code>
</address>
@end html
@end ifhtml
@ifinfo
@sp 2
Last edited @value{LASTEDIT}: comments to <R-windows@@r-project.org>
@end ifinfo

@bye

@c Local Variables: ***
@c mode: TeXinfo ***
@c End: ***