/usr/share/R/doc/manual/R-lang.html is in r-doc-html 3.4.4-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- This manual is for R, version 3.4.4 (2018-03-15).
Copyright (C) 2000-2018 R Core Team
Permission is granted to make and distribute verbatim copies of this
manual provided the copyright notice and this permission notice are
preserved on all copies.
Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided that the
entire resulting derived work is distributed under the terms of a
permission notice identical to this one.
Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified versions,
except that this permission notice may be stated in a translation
approved by the R Core Team. -->
<!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>R Language Definition</title>
<meta name="description" content="R Language Definition">
<meta name="keywords" content="R Language Definition">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="texi2any">
<link href="#Top" rel="start" title="Top">
<link href="#Function-and-Variable-Index" rel="index" title="Function and Variable Index">
<link href="#SEC_Contents" rel="contents" title="Table of Contents">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smalllisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
body {
margin-left: 5%;
margin-right: 5%;
}
h1 {
background: white;
color: rgb(25%, 25%, 25%);
font-family: monospace;
font-size: xx-large;
text-align: center;
}
h2 {
background: white;
color: rgb(40%, 40%, 40%);
font-family: monospace;
font-size: x-large;
text-align: center;
}
h3 {
background: white;
color: rgb(40%, 40%, 40%);
font-family: monospace;
font-size: large;
}
h4 {
background: white;
color: rgb(40%, 40%, 40%);
font-family: monospace;
}
span.samp {
font-family: monospace;
}
span.command {
font-family: monospace;
}
span.option {
font-family: monospace;
}
span.file {
font-family: monospace;
}
span.env {
font-family: monospace;
}
ul {
margin-top: 0.25ex;
margin-bottom: 0.25ex;
}
li {
margin-top: 0.25ex;
margin-bottom: 0.25ex;
}
p {
margin-top: 0.6ex;
margin-bottom: 1.2ex;
}
-->
</style>
</head>
<body lang="en">
<h1 class="settitle" align="center">R Language Definition</h1>
<a name="SEC_Contents"></a>
<h2 class="contents-heading">Table of Contents</h2>
<div class="contents">
<ul class="no-bullet">
<li><a name="toc-Introduction-1" href="#Introduction">1 Introduction</a></li>
<li><a name="toc-Objects-1" href="#Objects">2 Objects</a>
<ul class="no-bullet">
<li><a name="toc-Basic-types-1" href="#Basic-types">2.1 Basic types</a>
<ul class="no-bullet">
<li><a name="toc-Vectors" href="#Vector-objects">2.1.1 Vectors</a></li>
<li><a name="toc-Lists" href="#List-objects">2.1.2 Lists</a></li>
<li><a name="toc-Language-objects-1" href="#Language-objects">2.1.3 Language objects</a>
<ul class="no-bullet">
<li><a name="toc-Symbol-objects-1" href="#Symbol-objects">2.1.3.1 Symbol objects</a></li>
</ul></li>
<li><a name="toc-Expression-objects-1" href="#Expression-objects">2.1.4 Expression objects</a></li>
<li><a name="toc-Function-objects-1" href="#Function-objects">2.1.5 Function objects</a></li>
<li><a name="toc-NULL" href="#NULL-object">2.1.6 NULL</a></li>
<li><a name="toc-Builtin-objects-and-special-forms-1" href="#Builtin-objects-and-special-forms">2.1.7 Builtin objects and special forms</a></li>
<li><a name="toc-Promise-objects-1" href="#Promise-objects">2.1.8 Promise objects</a></li>
<li><a name="toc-Dot_002ddot_002ddot-1" href="#Dot_002ddot_002ddot">2.1.9 Dot-dot-dot</a></li>
<li><a name="toc-Environments" href="#Environment-objects">2.1.10 Environments</a></li>
<li><a name="toc-Pairlist-objects-1" href="#Pairlist-objects">2.1.11 Pairlist objects</a></li>
<li><a name="toc-The-_0060_0060Any_0027_0027-type" href="#Any_002dtype">2.1.12 The “Any” type</a></li>
</ul></li>
<li><a name="toc-Attributes-1" href="#Attributes">2.2 Attributes</a>
<ul class="no-bullet">
<li><a name="toc-Names-1" href="#Names">2.2.1 Names</a></li>
<li><a name="toc-Dimensions-1" href="#Dimensions">2.2.2 Dimensions</a></li>
<li><a name="toc-Dimnames-1" href="#Dimnames">2.2.3 Dimnames</a></li>
<li><a name="toc-Classes-1" href="#Classes">2.2.4 Classes</a></li>
<li><a name="toc-Time-series-attributes-1" href="#Time-series-attributes">2.2.5 Time series attributes</a></li>
<li><a name="toc-Copying-of-attributes-1" href="#Copying-of-attributes">2.2.6 Copying of attributes</a></li>
</ul></li>
<li><a name="toc-Special-compound-objects-1" href="#Special-compound-objects">2.3 Special compound objects</a>
<ul class="no-bullet">
<li><a name="toc-Factors-1" href="#Factors">2.3.1 Factors</a></li>
<li><a name="toc-Data-frame-objects-1" href="#Data-frame-objects">2.3.2 Data frame objects</a></li>
</ul></li>
</ul></li>
<li><a name="toc-Evaluation-of-expressions-1" href="#Evaluation-of-expressions">3 Evaluation of expressions</a>
<ul class="no-bullet">
<li><a name="toc-Simple-evaluation-1" href="#Simple-evaluation">3.1 Simple evaluation</a>
<ul class="no-bullet">
<li><a name="toc-Constants-1" href="#Constants">3.1.1 Constants</a></li>
<li><a name="toc-Symbol-lookup-1" href="#Symbol-lookup">3.1.2 Symbol lookup</a></li>
<li><a name="toc-Function-calls-1" href="#Function-calls">3.1.3 Function calls</a></li>
<li><a name="toc-Operators-1" href="#Operators">3.1.4 Operators</a></li>
</ul></li>
<li><a name="toc-Control-structures-1" href="#Control-structures">3.2 Control structures</a>
<ul class="no-bullet">
<li><a name="toc-if-1" href="#if">3.2.1 if</a></li>
<li><a name="toc-Looping-1" href="#Looping">3.2.2 Looping</a></li>
<li><a name="toc-repeat-1" href="#repeat">3.2.3 repeat</a></li>
<li><a name="toc-while-1" href="#while">3.2.4 while</a></li>
<li><a name="toc-for-1" href="#for">3.2.5 for</a></li>
<li><a name="toc-switch-1" href="#switch">3.2.6 switch</a></li>
</ul></li>
<li><a name="toc-Elementary-arithmetic-operations-1" href="#Elementary-arithmetic-operations">3.3 Elementary arithmetic operations</a>
<ul class="no-bullet">
<li><a name="toc-Recycling-rules-1" href="#Recycling-rules">3.3.1 Recycling rules</a></li>
<li><a name="toc-Propagation-of-names-1" href="#Propagation-of-names">3.3.2 Propagation of names</a></li>
<li><a name="toc-Dimensional-attributes-1" href="#Dimensional-attributes">3.3.3 Dimensional attributes</a></li>
<li><a name="toc-NA-handling-1" href="#NA-handling">3.3.4 NA handling</a></li>
</ul></li>
<li><a name="toc-Indexing-1" href="#Indexing">3.4 Indexing</a>
<ul class="no-bullet">
<li><a name="toc-Indexing-by-vectors-1" href="#Indexing-by-vectors">3.4.1 Indexing by vectors</a></li>
<li><a name="toc-Indexing-matrices-and-arrays-1" href="#Indexing-matrices-and-arrays">3.4.2 Indexing matrices and arrays</a></li>
<li><a name="toc-Indexing-other-structures-1" href="#Indexing-other-structures">3.4.3 Indexing other structures</a></li>
<li><a name="toc-Subset-assignment-1" href="#Subset-assignment">3.4.4 Subset assignment</a></li>
</ul></li>
<li><a name="toc-Scope-of-variables-1" href="#Scope-of-variables">3.5 Scope of variables</a>
<ul class="no-bullet">
<li><a name="toc-Global-environment-1" href="#Global-environment">3.5.1 Global environment</a></li>
<li><a name="toc-Lexical-environment-1" href="#Lexical-environment">3.5.2 Lexical environment</a></li>
<li><a name="toc-The-call-stack" href="#Stacks">3.5.3 The call stack</a></li>
<li><a name="toc-Search-path-1" href="#Search-path">3.5.4 Search path</a></li>
</ul></li>
</ul></li>
<li><a name="toc-Functions-1" href="#Functions">4 Functions</a>
<ul class="no-bullet">
<li><a name="toc-Writing-functions-1" href="#Writing-functions">4.1 Writing functions</a>
<ul class="no-bullet">
<li><a name="toc-Syntax-and-examples-1" href="#Syntax-and-examples">4.1.1 Syntax and examples</a></li>
<li><a name="toc-Arguments-1" href="#Arguments">4.1.2 Arguments</a></li>
</ul></li>
<li><a name="toc-Functions-as-objects-1" href="#Functions-as-objects">4.2 Functions as objects</a></li>
<li><a name="toc-Evaluation-1" href="#Evaluation">4.3 Evaluation</a>
<ul class="no-bullet">
<li><a name="toc-Evaluation-environment-1" href="#Evaluation-environment">4.3.1 Evaluation environment</a></li>
<li><a name="toc-Argument-matching-1" href="#Argument-matching">4.3.2 Argument matching</a></li>
<li><a name="toc-Argument-evaluation-1" href="#Argument-evaluation">4.3.3 Argument evaluation</a></li>
<li><a name="toc-Scope-1" href="#Scope">4.3.4 Scope</a></li>
</ul></li>
</ul></li>
<li><a name="toc-Object_002doriented-programming-1" href="#Object_002doriented-programming">5 Object-oriented programming</a>
<ul class="no-bullet">
<li><a name="toc-Definition-1" href="#Definition">5.1 Definition</a></li>
<li><a name="toc-Inheritance-1" href="#Inheritance">5.2 Inheritance</a></li>
<li><a name="toc-Method-dispatching-1" href="#Method-dispatching">5.3 Method dispatching</a></li>
<li><a name="toc-UseMethod-1" href="#UseMethod">5.4 UseMethod</a></li>
<li><a name="toc-NextMethod-1" href="#NextMethod">5.5 NextMethod</a></li>
<li><a name="toc-Group-methods-1" href="#Group-methods">5.6 Group methods</a></li>
<li><a name="toc-Writing-methods-1" href="#Writing-methods">5.7 Writing methods</a></li>
</ul></li>
<li><a name="toc-Computing-on-the-language-1" href="#Computing-on-the-language">6 Computing on the language</a>
<ul class="no-bullet">
<li><a name="toc-Direct-manipulation-of-language-objects-1" href="#Direct-manipulation-of-language-objects">6.1 Direct manipulation of language objects</a></li>
<li><a name="toc-Substitutions-1" href="#Substitutions">6.2 Substitutions</a></li>
<li><a name="toc-More-on-evaluation-1" href="#More-on-evaluation">6.3 More on evaluation</a></li>
<li><a name="toc-Evaluation-of-expression-objects-1" href="#Evaluation-of-expression-objects">6.4 Evaluation of expression objects</a></li>
<li><a name="toc-Manipulation-of-function-calls-1" href="#Manipulation-of-function-calls">6.5 Manipulation of function calls</a></li>
<li><a name="toc-Manipulation-of-functions-1" href="#Manipulation-of-functions">6.6 Manipulation of functions</a></li>
</ul></li>
<li><a name="toc-System-and-foreign-language-interfaces-1" href="#System-and-foreign-language-interfaces">7 System and foreign language interfaces</a>
<ul class="no-bullet">
<li><a name="toc-Operating-system-access-1" href="#Operating-system-access">7.1 Operating system access</a></li>
<li><a name="toc-Foreign-language-interfaces-1" href="#Foreign-language-interfaces">7.2 Foreign language interfaces</a></li>
<li><a name="toc-_002eInternal-and-_002ePrimitive-1" href="#g_t_002eInternal-and-_002ePrimitive">7.3 .Internal and .Primitive</a></li>
</ul></li>
<li><a name="toc-Exception-handling-1" href="#Exception-handling">8 Exception handling</a>
<ul class="no-bullet">
<li><a name="toc-stop-1" href="#stop">8.1 stop</a></li>
<li><a name="toc-warning-1" href="#warning">8.2 warning</a></li>
<li><a name="toc-on_002eexit-1" href="#on_002eexit">8.3 on.exit</a></li>
<li><a name="toc-Error-options-1" href="#Error-options">8.4 Error options</a></li>
</ul></li>
<li><a name="toc-Debugging-1" href="#Debugging">9 Debugging</a>
<ul class="no-bullet">
<li><a name="toc-browser-1" href="#browser">9.1 browser</a></li>
<li><a name="toc-debug_002fundebug-1" href="#debug_002fundebug">9.2 debug/undebug</a></li>
<li><a name="toc-trace_002funtrace-1" href="#trace_002funtrace">9.3 trace/untrace</a></li>
<li><a name="toc-traceback-1" href="#traceback">9.4 traceback</a></li>
</ul></li>
<li><a name="toc-Parser-1" href="#Parser">10 Parser</a>
<ul class="no-bullet">
<li><a name="toc-The-parsing-process-1" href="#The-parsing-process">10.1 The parsing process</a>
<ul class="no-bullet">
<li><a name="toc-Modes-of-parsing-1" href="#Modes-of-parsing">10.1.1 Modes of parsing</a></li>
<li><a name="toc-Internal-representation-1" href="#Internal-representation">10.1.2 Internal representation</a></li>
<li><a name="toc-Deparsing-1" href="#Deparsing">10.1.3 Deparsing</a></li>
</ul></li>
<li><a name="toc-Comments-1" href="#Comments">10.2 Comments</a></li>
<li><a name="toc-Tokens-1" href="#Tokens">10.3 Tokens</a>
<ul class="no-bullet">
<li><a name="toc-Constants-2" href="#Literal-constants">10.3.1 Constants</a></li>
<li><a name="toc-Identifiers-1" href="#Identifiers">10.3.2 Identifiers</a></li>
<li><a name="toc-Reserved-words-1" href="#Reserved-words">10.3.3 Reserved words</a></li>
<li><a name="toc-Special-operators-1" href="#Special-operators">10.3.4 Special operators</a></li>
<li><a name="toc-Separators-1" href="#Separators">10.3.5 Separators</a></li>
<li><a name="toc-Operator-tokens-1" href="#Operator-tokens">10.3.6 Operator tokens</a></li>
<li><a name="toc-Grouping-1" href="#Grouping">10.3.7 Grouping</a></li>
<li><a name="toc-Indexing-tokens-1" href="#Indexing-tokens">10.3.8 Indexing tokens</a></li>
</ul></li>
<li><a name="toc-Expressions-1" href="#Expressions">10.4 Expressions</a>
<ul class="no-bullet">
<li><a name="toc-Function-calls-2" href="#Function-calls-_0028expressions_0029">10.4.1 Function calls</a></li>
<li><a name="toc-Infix-and-prefix-operators-1" href="#Infix-and-prefix-operators">10.4.2 Infix and prefix operators</a></li>
<li><a name="toc-Index-constructions-1" href="#Index-constructions">10.4.3 Index constructions</a></li>
<li><a name="toc-Compound-expressions-1" href="#Compound-expressions">10.4.4 Compound expressions</a></li>
<li><a name="toc-Flow-control-elements-1" href="#Flow-control-elements">10.4.5 Flow control elements</a></li>
<li><a name="toc-Function-definitions-1" href="#Function-definitions">10.4.6 Function definitions</a></li>
</ul></li>
<li><a name="toc-Directives-1" href="#Directives">10.5 Directives</a></li>
</ul></li>
<li><a name="toc-Function-and-Variable-Index-1" href="#Function-and-Variable-Index">Function and Variable Index</a></li>
<li><a name="toc-Concept-Index-1" href="#Concept-Index">Concept Index</a></li>
<li><a name="toc-References-1" href="#References">Appendix A References</a></li>
</ul>
</div>
<a name="Top"></a>
<div class="header">
<p>
Next: <a href="#Introduction" accesskey="n" rel="next">Introduction</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="R-Language-Definition"></a>
<h1 class="top">R Language Definition</h1>
<p>This is an introduction to the R language, explaining evaluation,
parsing, object oriented programming, computing on the language, and so
forth.
</p>
<p>This manual is for R, version 3.4.4 (2018-03-15).
</p>
<p>Copyright © 2000–2018 R Core Team
</p>
<blockquote>
<p>Permission is granted to make and distribute verbatim copies of this
manual provided the copyright notice and this permission notice are
preserved on all copies.
</p>
<p>Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided that the
entire resulting derived work is distributed under the terms of a
permission notice identical to this one.
</p>
<p>Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified versions,
except that this permission notice may be stated in a translation
approved by the R Core Team.
</p></blockquote>
<table summary="" class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">• <a href="#Introduction" accesskey="1">Introduction</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Objects" accesskey="2">Objects</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Evaluation-of-expressions" accesskey="3">Evaluation of expressions</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Functions" accesskey="4">Functions</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Object_002doriented-programming" accesskey="5">Object-oriented programming</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Computing-on-the-language" accesskey="6">Computing on the language</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#System-and-foreign-language-interfaces" accesskey="7">System and foreign language interfaces</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Exception-handling" accesskey="8">Exception handling</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Debugging" accesskey="9">Debugging</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Parser">Parser</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Function-and-Variable-Index">Function and Variable Index</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Concept-Index">Concept Index</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#References">References</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="Introduction"></a>
<div class="header">
<p>
Next: <a href="#Objects" accesskey="n" rel="next">Objects</a>, Previous: <a href="#Top" accesskey="p" rel="prev">Top</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Introduction-1"></a>
<h2 class="chapter">1 Introduction</h2>
<p>R is a system for statistical computation and graphics. It
provides, among other things, a programming language, high level
graphics, interfaces to other languages and debugging facilities. This
manual details and defines the R language.
</p>
<p>The R language is a dialect of S which was designed in the 1980s
and has been in widespread use in the statistical community since.
Its principal designer, John M. Chambers, was awarded the 1998 ACM
Software Systems Award for S.
</p>
<p>The language syntax has a superficial similarity with C, but the
semantics are of the FPL (functional programming language) variety with
stronger affinities with Lisp and <acronym>APL</acronym>. In particular, it
allows “computing on the language”, which in turn makes it possible to
write functions that take expressions as input, something that is often
useful for statistical modeling and graphics.
</p>
<p>It is possible to get quite far using R interactively, executing
<a name="index-expression"></a>
simple expressions from the command line. Some users may never need to
go beyond that level, others will want to write their own functions
either in an ad hoc fashion to systematize repetitive work or with the
perspective of writing add-on packages for new functionality.
</p>
<p>The purpose of this manual is to document the language <em>per se</em>.
That is, the objects that it works on, and the details of the expression
evaluation process, which are useful to know when programming R
functions. Major subsystems for specific tasks, such as graphics, are
only briefly described in this manual and will be documented separately.
</p>
<p>Although much of the text will equally apply to S, there are also
some substantial differences, and in order not to confuse the issue we
shall concentrate on describing R.
</p>
<p>The design of the language contains a number of fine points and
common pitfalls which may surprise the user. Most of these are due to
consistency considerations at a deeper level, as we shall explain.
There are also a number of useful shortcuts and idioms, which allow the
user to express quite complicated operations succinctly. Many of these
become natural once one is familiar with the underlying concepts. In
some cases, there are multiple ways of performing a task, but some of
the techniques will rely on the language implementation, and others work
at a higher level of abstraction. In such cases we shall indicate the
preferred usage.
</p>
<p>Some familiarity with R is assumed. This is not an introduction to
R but rather a programmers’ reference manual. Other manuals provide
complementary information: in particular <a href="http://cran.r-project.org/doc/manuals/R-intro.html#Preface">Preface</a> in <cite>An
Introduction to R</cite> provides an introduction to R and <a href="http://cran.r-project.org/doc/manuals/R-exts.html#System-and-foreign-language-interfaces">System and
foreign language interfaces</a> in <cite>Writing R Extensions</cite> details
how to extend R using compiled code.
</p>
<hr>
<a name="Objects"></a>
<div class="header">
<p>
Next: <a href="#Evaluation-of-expressions" accesskey="n" rel="next">Evaluation of expressions</a>, Previous: <a href="#Introduction" accesskey="p" rel="prev">Introduction</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Objects-1"></a>
<h2 class="chapter">2 Objects</h2>
<p>In every computer language
<a name="index-variable"></a>
variables provide a means of accessing the data stored in memory. R
does not provide direct access to the computer’s memory but rather
provides a number of specialized data structures we will refer to as
<a name="index-object"></a>
objects. These objects
are referred to through symbols or variables. In R, however, the
symbols are themselves objects and can be manipulated in the same way as
any other object. This is different from many other languages and has
wide ranging effects.
</p>
<p>In this chapter we provide preliminary descriptions of the various data
structures provided in R. More detailed discussions of many of them
will be found in the subsequent chapters. The R specific function
<code>typeof</code>
<a name="index-typeof"></a>
<a name="index-type"></a>
returns the <em>type</em> of an R object. Note that in the C code
underlying R, all objects are pointers to a structure with typedef
<code>SEXPREC</code>; the different R data types are represented in C by
<code>SEXPTYPE</code>, which determines how the information in the various
parts of the structure is used.
</p>
<p>The following table describes the possible values returned by
<code>typeof</code> and what they are.
</p>
<blockquote>
<table summary="">
<tr><td width="20%"><code>"NULL"</code></td><td width="70%">NULL</td></tr>
<tr><td width="20%"><code>"symbol"</code></td><td width="70%">a variable name</td></tr>
<tr><td width="20%"><code>"pairlist"</code></td><td width="70%">a pairlist object (mainly internal)</td></tr>
<tr><td width="20%"><code>"closure"</code></td><td width="70%">a function</td></tr>
<tr><td width="20%"><code>"environment"</code></td><td width="70%">an environment
<a name="index-evaluation_002c-lazy"></a></td></tr>
<tr><td width="20%"><code>"promise"</code></td><td width="70%">an object used to implement lazy evaluation</td></tr>
<tr><td width="20%"><code>"language"</code></td><td width="70%">an R language construct</td></tr>
<tr><td width="20%"><code>"special"</code></td><td width="70%">an internal function that does not evaluate its arguments</td></tr>
<tr><td width="20%"><code>"builtin"</code></td><td width="70%">an internal function that evaluates its arguments</td></tr>
<tr><td width="20%"><code>"char"</code></td><td width="70%">a ‘scalar’ string object (internal only) ***</td></tr>
<tr><td width="20%"><code>"logical"</code></td><td width="70%">a vector containing logical values</td></tr>
<tr><td width="20%"><code>"integer"</code></td><td width="70%">a vector containing integer values</td></tr>
<tr><td width="20%"><code>"double"</code></td><td width="70%">a vector containing real values</td></tr>
<tr><td width="20%"><code>"complex"</code></td><td width="70%">a vector containing complex values</td></tr>
<tr><td width="20%"><code>"character"</code></td><td width="70%">a vector containing character values</td></tr>
<tr><td width="20%"><code>"..."</code></td><td width="70%">the special variable length argument ***</td></tr>
<tr><td width="20%"><code>"any"</code></td><td width="70%">a special type that matches all types: there are no objects of this type</td></tr>
<tr><td width="20%"><code>"expression"</code></td><td width="70%">an expression object</td></tr>
<tr><td width="20%"><code>"list"</code></td><td width="70%">a list</td></tr>
<tr><td width="20%"><code>"bytecode"</code></td><td width="70%">byte code (internal only) ***</td></tr>
<tr><td width="20%"><code>"externalptr"</code></td><td width="70%">an external pointer object</td></tr>
<tr><td width="20%"><code>"weakref"</code></td><td width="70%">a weak reference object</td></tr>
<tr><td width="20%"><code>"raw"</code></td><td width="70%">a vector containing bytes</td></tr>
<tr><td width="20%"><code>"S4"</code></td><td width="70%">an S4 object which is not a simple object</td></tr>
</table>
</blockquote>
<p>Users cannot easily get hold of objects of types marked with a ‘***’.
</p>
<a name="index-mode-3"></a>
<a name="index-mode"></a>
<p>Function <code>mode</code> gives information about the <em>mode</em> of an object
in the sense of Becker, Chambers & Wilks (1988), and is more compatible
with other implementations of the S language.
<a name="index-storage_002emode"></a>
Finally, the function <code>storage.mode</code> returns the <em>storage mode</em>
of its argument in the sense of Becker et al. (1988). It is generally
used when calling functions written in another language, such as C or
FORTRAN, to ensure that R objects have the data type expected by the
routine being called. (In the S language, vectors with integer or
real values are both of mode <code>"numeric"</code>, so their storage modes
need to be distinguished.)
</p>
<div class="example">
<pre class="example">> x <- 1:3
> typeof(x)
[1] "integer"
> mode(x)
[1] "numeric"
> storage.mode(x)
[1] "integer"
</pre></div>
<p>R
<a name="index-object-1"></a>
objects are often coerced to different
<a name="index-type-1"></a>
types during computations.
There are also many functions available to perform explicit
<a name="index-coercion"></a>
coercion.
When programming in the R language the type of an object generally
doesn’t affect the computations, however, when dealing with foreign
languages or the operating system it is often necessary to ensure that
an object is of the correct type.
</p>
<table summary="" class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">• <a href="#Basic-types" accesskey="1">Basic types</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Attributes" accesskey="2">Attributes</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Special-compound-objects" accesskey="3">Special compound objects</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="Basic-types"></a>
<div class="header">
<p>
Next: <a href="#Attributes" accesskey="n" rel="next">Attributes</a>, Previous: <a href="#Objects" accesskey="p" rel="prev">Objects</a>, Up: <a href="#Objects" accesskey="u" rel="up">Objects</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="index-type-2"></a>
<a name="Basic-types-1"></a>
<h3 class="section">2.1 Basic types</h3>
<table summary="" class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">• <a href="#Vector-objects" accesskey="1">Vector objects</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#List-objects" accesskey="2">List objects</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Language-objects" accesskey="3">Language objects</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Expression-objects" accesskey="4">Expression objects</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Function-objects" accesskey="5">Function objects</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#NULL-object" accesskey="6">NULL object</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Builtin-objects-and-special-forms" accesskey="7">Builtin objects and special forms</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Promise-objects" accesskey="8">Promise objects</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Dot_002ddot_002ddot" accesskey="9">Dot-dot-dot</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Environment-objects">Environment objects</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Pairlist-objects">Pairlist objects</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Any_002dtype">Any-type</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="Vector-objects"></a>
<div class="header">
<p>
Next: <a href="#List-objects" accesskey="n" rel="next">List objects</a>, Previous: <a href="#Basic-types" accesskey="p" rel="prev">Basic types</a>, Up: <a href="#Basic-types" accesskey="u" rel="up">Basic types</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Vectors"></a>
<h4 class="subsection">2.1.1 Vectors</h4>
<a name="index-vector"></a>
<p>Vectors can be thought of as contiguous cells containing data. Cells
are accessed through
<a name="index-index"></a>
indexing operations such as
<code>x[5]</code>. More details are given in <a href="#Indexing">Indexing</a>.
</p>
<a name="index-type-3"></a>
<a name="index-mode-1"></a>
<a name="index-atomic"></a>
<p>R has six basic (‘atomic’) vector types: logical, integer, real,
complex, string (or character) and raw. The modes and storage modes for
the different vector types are listed in the following table.
</p>
<blockquote>
<table summary="">
<thead><tr><th>typeof</th><th>mode</th><th>storage.mode</th></tr></thead>
<tr><td><code>logical</code></td><td><code>logical</code></td><td><code>logical</code></td></tr>
<tr><td><code>integer</code></td><td><code>numeric</code></td><td><code>integer</code></td></tr>
<tr><td><code>double</code></td><td><code>numeric</code></td><td><code>double</code></td></tr>
<tr><td><code>complex</code></td><td><code>complex</code></td><td><code>complex</code></td></tr>
<tr><td><code>character</code></td><td><code>character</code></td><td><code>character</code></td></tr>
<tr><td><code>raw</code></td><td><code>raw</code></td><td><code>raw</code></td></tr>
</table>
</blockquote>
<p>Single numbers, such as <code>4.2</code>, and strings, such as <code>"four
point two"</code> are still vectors, of length 1; there are no more basic
types. Vectors with length zero are possible (and useful).
</p>
<p>String vectors have mode and storage mode <code>"character"</code>. A single
element of a character vector is often referred to as a <em>character
string</em>.
</p>
<hr>
<a name="List-objects"></a>
<div class="header">
<p>
Next: <a href="#Language-objects" accesskey="n" rel="next">Language objects</a>, Previous: <a href="#Vector-objects" accesskey="p" rel="prev">Vector objects</a>, Up: <a href="#Basic-types" accesskey="u" rel="up">Basic types</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Lists"></a>
<h4 class="subsection">2.1.2 Lists</h4>
<p>Lists (“generic vectors”) are another kind of data storage. Lists
have elements, each of which can contain any type of R object, i.e.
the elements of a list do not have to be of the same type. List
elements are accessed through three different
<a name="index-index-1"></a>
indexing operations.
These are explained in detail in <a href="#Indexing">Indexing</a>.
</p>
<p>Lists are vectors, and the basic vector types are referred to as
<em>atomic vectors</em> where it is necessary to exclude lists.
</p>
<hr>
<a name="Language-objects"></a>
<div class="header">
<p>
Next: <a href="#Expression-objects" accesskey="n" rel="next">Expression objects</a>, Previous: <a href="#List-objects" accesskey="p" rel="prev">List objects</a>, Up: <a href="#Basic-types" accesskey="u" rel="up">Basic types</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Language-objects-1"></a>
<h4 class="subsection">2.1.3 Language objects</h4>
<p>There are three types of objects that constitute the R language.
They are <em>calls</em>, <em>expressions</em>, and <em>names</em>.
<a name="index-call"></a>
<a name="index-expression-1"></a>
<a name="index-name"></a>
Since R has objects of type <code>"expression"</code> we will try to avoid
the use of the word expression in other contexts. In particular
syntactically correct expressions will be referred to as
<em>statements</em>.
<a name="index-statement"></a>
</p>
<p>These objects have modes <code>"call"</code>, <code>"expression"</code>, and
<code>"name"</code>, respectively.
</p>
<p>They can be created directly from expressions using the <code>quote</code>
mechanism and converted to and from lists by the <code>as.list</code> and
<code>as.call</code> functions.
<a name="index-quote"></a>
<a name="index-as_002elist"></a>
<a name="index-as_002ecall"></a>
Components of the
<a name="index-parsing"></a>
parse tree can be extracted using the standard
indexing operations.
</p>
<table summary="" class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">• <a href="#Symbol-objects" accesskey="1">Symbol objects</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="Symbol-objects"></a>
<div class="header">
<p>
Previous: <a href="#Language-objects" accesskey="p" rel="prev">Language objects</a>, Up: <a href="#Language-objects" accesskey="u" rel="up">Language objects</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Symbol-objects-1"></a>
<h4 class="subsubsection">2.1.3.1 Symbol objects</h4>
<a name="index-symbol"></a>
<p>Symbols refer to R
<a name="index-object-2"></a>
objects. The
<a name="index-name-1"></a>
name of any R object is usually a
symbol. Symbols can be created through the functions <code>as.name</code> and
<code>quote</code>.
</p>
<a name="index-symbol-1"></a>
<a name="index-mode-2"></a>
<p>Symbols have mode <code>"name"</code>, storage mode <code>"symbol"</code>, and type
<code>"symbol"</code>. They can be
<a name="index-coercion-1"></a>
coerced to and from character strings
using <code>as.character</code> and <code>as.name</code>.
<a name="index-as_002echaracter"></a>
<a name="index-as_002ename"></a>
<a name="index-parsing-1"></a>
They naturally appear as atoms of parsed expressions, try e.g.
<code>as.list(quote(x + y))</code>.
</p>
<hr>
<a name="Expression-objects"></a>
<div class="header">
<p>
Next: <a href="#Function-objects" accesskey="n" rel="next">Function objects</a>, Previous: <a href="#Language-objects" accesskey="p" rel="prev">Language objects</a>, Up: <a href="#Basic-types" accesskey="u" rel="up">Basic types</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Expression-objects-1"></a>
<h4 class="subsection">2.1.4 Expression objects</h4>
<p>In R one can have objects of type <code>"expression"</code>. An
<em>expression</em> contains one or more statements. A statement is a
syntactically correct collection of
<a name="index-token"></a>
tokens.
<a name="index-expression-object"></a>
Expression objects are special language objects which contain parsed but
unevaluated R statements. The main difference is that an expression
object can contain several such expressions. Another more subtle
difference is that objects of type <code>"expression"</code> are only
<a name="index-evaluation_002c-expression"></a>
evaluated when
explicitly passed to <code>eval</code>, whereas other language objects may get
evaluated in some unexpected cases.
</p>
<p>An
<a name="index-expression-object-1"></a>
expression object behaves much like a list and its components should
be accessed in the same way as the components of a list.
</p>
<hr>
<a name="Function-objects"></a>
<div class="header">
<p>
Next: <a href="#NULL-object" accesskey="n" rel="next">NULL object</a>, Previous: <a href="#Expression-objects" accesskey="p" rel="prev">Expression objects</a>, Up: <a href="#Basic-types" accesskey="u" rel="up">Basic types</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Function-objects-1"></a>
<h4 class="subsection">2.1.5 Function objects</h4>
<a name="index-function"></a>
<p>In R functions are objects and can be manipulated in much the same
way as any other object. Functions (or more precisely, function
closures) have three basic components: a formal argument list, a body
and an
<a name="index-environment"></a>
environment. The argument list is a comma-separated list of
arguments. An
<a name="index-argument"></a>
argument can be a symbol, or a ‘<samp><var>symbol</var> =
<var>default</var></samp>’ construct, or the special argument ‘<samp>...</samp>’. The
second form of argument is used to specify a default value for an
argument. This value will be used if the function is called without any
value specified for that argument. The ‘<samp>...</samp>’ argument is special
and can contain any number of arguments. It is generally used if the
number of arguments is unknown or in cases where the arguments will be
passed on to another function.
</p>
<p>The body is a parsed R statement. It is usually a collection of
statements in braces but it can be a single statement, a symbol or even
a constant.
</p>
<p>A function’s
<a name="index-function-1"></a>
<a name="index-environment-1"></a>
environment is the environment that was active at the time
that the function was created. Any symbols bound in that environment
are <em>captured</em> and available to the function. This combination of
the code of the function and the bindings in its environment is called a
‘function closure’, a term from functional programming theory. In this
document we generally use the term ‘function’, but use ‘closure’ to
emphasize the importance of the attached environment.
</p>
<p>It is possible to extract and manipulate the three parts of a closure
object using <code>formals</code>, <code>body</code>, and <code>environment</code>
constructs (all three can also be used on the left hand side of
<a name="index-assignment"></a>
assignments).
<a name="index-formals"></a>
<a name="index-body"></a>
<a name="index-environment-20"></a>
The last of these can be used to remove unwanted environment capture.
</p>
<p>When a function is called, a new environment (called the
<em>evaluation environment</em>) is created, whose enclosure (see
<a href="#Environment-objects">Environment objects</a>) is the environment from the function closure.
This new environment is initially populated with the unevaluated
arguments to the function; as evaluation proceeds, local variables are
created within it.
</p>
<a name="index-function-2"></a>
<p>There is also a facility for converting functions to and from list
structures using <code>as.list</code> and <code>as.function</code>.
<a name="index-as_002efunction"></a>
These have been included to provide compatibility with S and their
use is discouraged.
</p>
<hr>
<a name="NULL-object"></a>
<div class="header">
<p>
Next: <a href="#Builtin-objects-and-special-forms" accesskey="n" rel="next">Builtin objects and special forms</a>, Previous: <a href="#Function-objects" accesskey="p" rel="prev">Function objects</a>, Up: <a href="#Basic-types" accesskey="u" rel="up">Basic types</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="NULL"></a>
<h4 class="subsection">2.1.6 NULL</h4>
<p>There is a special object called <code>NULL</code>. It is used whenever there
is a need to indicate or specify that an object is absent. It should not be
confused with a vector or list of zero length.
<a name="index-NULL"></a>
</p>
<p>The <code>NULL</code> object has no type and no modifiable properties. There
is only one <code>NULL</code> object in R, to which all instances refer. To
test for <code>NULL</code> use <code>is.null</code>. You cannot set attributes on
<code>NULL</code>.
</p>
<hr>
<a name="Builtin-objects-and-special-forms"></a>
<div class="header">
<p>
Next: <a href="#Promise-objects" accesskey="n" rel="next">Promise objects</a>, Previous: <a href="#NULL-object" accesskey="p" rel="prev">NULL object</a>, Up: <a href="#Basic-types" accesskey="u" rel="up">Basic types</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Builtin-objects-and-special-forms-1"></a>
<h4 class="subsection">2.1.7 Builtin objects and special forms</h4>
<p>These two kinds of object contain the builtin
<a name="index-function-3"></a>
<a name="index-_002ePrimitive"></a>
<a name="index-_002eInternal"></a>
functions of R, i.e., those that are displayed as <code>.Primitive</code>
in code listings (as well as those accessed via the <code>.Internal</code>
function and hence not user-visible as objects). The difference between
the two lies in the argument handling. Builtin functions have all
their arguments evaluated and passed to the internal function, in
accordance with <em>call-by-value</em>, whereas special functions pass the
unevaluated arguments to the internal function.
</p>
<p>From the R language, these objects are just another kind of function.
The <code>is.primitive</code> function can distinguish them from interpreted
<a name="index-function-4"></a>
functions.
</p>
<hr>
<a name="Promise-objects"></a>
<div class="header">
<p>
Next: <a href="#Dot_002ddot_002ddot" accesskey="n" rel="next">Dot-dot-dot</a>, Previous: <a href="#Builtin-objects-and-special-forms" accesskey="p" rel="prev">Builtin objects and special forms</a>, Up: <a href="#Basic-types" accesskey="u" rel="up">Basic types</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Promise-objects-1"></a>
<h4 class="subsection">2.1.8 Promise objects</h4>
<a name="index-promise"></a>
<p>Promise objects are part of R’s lazy evaluation mechanism. They
contain three slots: a value, an expression, and an
<a name="index-environment-2"></a>
environment. When a
<a name="index-function-5"></a>
<a name="index-function-argument"></a>
function is called the arguments are matched and then each of the formal
arguments is bound to a promise. The expression that was given for that
formal argument and a pointer to the environment the function was called
from are stored in the promise.
</p>
<p>Until that argument is accessed there is no <em>value</em> associated with
the promise. When the argument is accessed, the stored expression is
<a name="index-evaluation_002c-expression-1"></a>
evaluated in the stored environment, and the result is returned. The
result is also saved by
the promise. The <code>substitute</code> function will extract the content
of the expression slot. This allows the programmer to
access either the value or the expression associated with the promise.
</p>
<p>Within the R language, promise objects are almost only seen
implicitly: actual function arguments are of this type. There is also a
<code>delayedAssign</code> function that will make a promise out of an
expression. There is generally no way in R code to check whether an
object is a promise or not, nor is there a way to use R code to
determine the environment of a promise.
</p>
<hr>
<a name="Dot_002ddot_002ddot"></a>
<div class="header">
<p>
Next: <a href="#Environment-objects" accesskey="n" rel="next">Environment objects</a>, Previous: <a href="#Promise-objects" accesskey="p" rel="prev">Promise objects</a>, Up: <a href="#Basic-types" accesskey="u" rel="up">Basic types</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Dot_002ddot_002ddot-1"></a>
<h4 class="subsection">2.1.9 Dot-dot-dot</h4>
<p>The ‘<samp>...</samp>’ object type is stored as a type of pairlist. The
components of ‘<samp>...</samp>’ can be accessed in the usual pairlist manner
from C code, but is not easily accessed as an object in interpreted
code. The object can be captured as a list, so for example in
<code>table</code> one sees
</p>
<div class="example">
<pre class="example"> args <- list(...)
## ....
for (a in args) {
## ....
</pre></div>
<a name="index-function-6"></a>
<a name="index-function-argument-1"></a>
<p>If a function has ‘<samp>...</samp>’ as a formal argument then any actual
arguments that do not match a formal argument are matched with
‘<samp>...</samp>’.
</p>
<hr>
<a name="Environment-objects"></a>
<div class="header">
<p>
Next: <a href="#Pairlist-objects" accesskey="n" rel="next">Pairlist objects</a>, Previous: <a href="#Dot_002ddot_002ddot" accesskey="p" rel="prev">Dot-dot-dot</a>, Up: <a href="#Basic-types" accesskey="u" rel="up">Basic types</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Environments"></a>
<h4 class="subsection">2.1.10 Environments</h4>
<a name="index-environment-3"></a>
<p>Environments can be thought of as consisting of two things. A
<em>frame</em>, consisting of a set of symbol-value pairs, and an
<em>enclosure</em>, a pointer to an enclosing environment. When R
looks up the value for a symbol the frame is examined and if a
matching symbol is found its value will be returned. If not, the
enclosing environment is then accessed and the process repeated.
Environments form a tree structure in which the enclosures play the
role of parents. The tree of environments is rooted in an empty
<a name="index-emptyenv"></a>
environment, available through <code>emptyenv()</code>, which has no parent.
It is the direct parent of the environment of the base package
<a name="index-baseenv"></a>
(available through the <code>baseenv()</code> function). Formerly
<code>baseenv()</code> had the special value <code>NULL</code>, but as from
version 2.4.0, the use of <code>NULL</code> as an environment is defunct.
</p>
<p>Environments are created implicitly by function calls, as described in
<a href="#Function-objects">Function objects</a> and <a href="#Lexical-environment">Lexical environment</a>. In this case the
environment contains the variables local to the function (including the
arguments), and its enclosure is the environment of the currently called
function. Environments may also be created directly by <code>new.env</code>.
<a name="index-new_002eenv"></a>
The frame content of an environment can be accessed and manipulated by
use of <code>ls</code>, <code>get</code> and <code>assign</code> as well as <code>eval</code> and
<code>evalq</code>.
</p>
<p>The <code>parent.env</code> function may be used to access the enclosure of
an environment.
</p>
<p>Unlike most other R objects, environments are not copied when passed
to functions or used in assignments. Thus, if you assign the same
environment to several symbols and change one, the others will change
too. In particular, assigning attributes to an environment can lead to
surprises.
</p>
<hr>
<a name="Pairlist-objects"></a>
<div class="header">
<p>
Next: <a href="#Any_002dtype" accesskey="n" rel="next">Any-type</a>, Previous: <a href="#Environment-objects" accesskey="p" rel="prev">Environment objects</a>, Up: <a href="#Basic-types" accesskey="u" rel="up">Basic types</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Pairlist-objects-1"></a>
<h4 class="subsection">2.1.11 Pairlist objects</h4>
<p>Pairlist objects are similar to Lisp’s dotted-pair lists. They are used
extensively in the internals of R, but are rarely visible in
interpreted code, although they are returned by <code>formals</code>, and can
be created by (e.g.) the <code>pairlist</code> function. A zero-length
pairlist is <code>NULL</code>, as would be expected in Lisp but in contrast to
a zero-length list.
<a name="index-pairlist"></a>
Each such object has three slots, a CAR value, a CDR value and a TAG
value. The TAG value is a text string and CAR and CDR usually
represent, respectively, a list item (head) and the remainder (tail) of
the list with a NULL object as terminator (the CAR/CDR terminology is
traditional Lisp and originally referred to the address and decrement
registers on an early 60’s IBM computer).
</p>
<p>Pairlists are handled in the R language in exactly the same way as
generic vectors (“lists”). In particular, elements are accessed using
the same <code>[[]]</code> syntax. The use of pairlists is deprecated since
generic vectors are usually more efficient to use. When an internal
pairlist is accessed from R it is generally (including when
subsetted) converted to a generic vector.
</p>
<p>In a very few cases pairlists are user-visible: one is <code>.Options</code>.
</p>
<hr>
<a name="Any_002dtype"></a>
<div class="header">
<p>
Previous: <a href="#Pairlist-objects" accesskey="p" rel="prev">Pairlist objects</a>, Up: <a href="#Basic-types" accesskey="u" rel="up">Basic types</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="The-_0060_0060Any_0027_0027-type"></a>
<h4 class="subsection">2.1.12 The “Any” type</h4>
<p>It is not really possible for an object to be of “Any” type, but it is
nevertheless a valid type value. It gets used in certain (rather rare)
circumstances, e.g. <code>as.vector(x, "any")</code>, indicating that type
<a name="index-coercion-2"></a>
coercion should not be done.
</p>
<hr>
<a name="Attributes"></a>
<div class="header">
<p>
Next: <a href="#Special-compound-objects" accesskey="n" rel="next">Special compound objects</a>, Previous: <a href="#Basic-types" accesskey="p" rel="prev">Basic types</a>, Up: <a href="#Objects" accesskey="u" rel="up">Objects</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Attributes-1"></a>
<h3 class="section">2.2 Attributes</h3>
<a name="index-attributes"></a>
<a name="index-object-3"></a>
<p>All objects except <code>NULL</code> can have one or more attributes attached
to them. Attributes are stored as a pairlist where all elements are
named, but should be thought of as a set of name=value pairs. A listing
of the attributes can be obtained using <code>attributes</code> and set by
<code>attributes<-</code>,
<a name="index-attributes-1"></a>
<a name="index-attributes_003c_002d"></a>
individual components are accessed using <code>attr</code> and <code>attr<-</code>.
<a name="index-attr"></a>
<a name="index-attr_003c_002d"></a>
</p>
<p>Some attributes have special accessor
<a name="index-function_002c-accessor"></a>
functions (e.g. <code>levels<-</code>
for factors) and these should be used when available. In addition to
hiding details of implementation they may perform additional operations.
R attempts to intercept calls to <code>attr<-</code> and to
<code>attributes<-</code> that involve the special attributes and enforces
the consistency checks.
</p>
<p>Matrices and arrays are simply vectors with the attribute <code>dim</code> and
optionally <code>dimnames</code> attached to the vector.
</p>
<p>Attributes are used to implement the class structure used in R. If an
object has a <code>class</code> attribute then that attribute will be examined
during
<a name="index-evaluation_002c-symbol"></a>
evaluation. The class structure in R is described in detail
in <a href="#Object_002doriented-programming">Object-oriented programming</a>.
</p>
<table summary="" class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">• <a href="#Names" accesskey="1">Names</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Dimensions" accesskey="2">Dimensions</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Dimnames" accesskey="3">Dimnames</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Classes" accesskey="4">Classes</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Time-series-attributes" accesskey="5">Time series attributes</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Copying-of-attributes" accesskey="6">Copying of attributes</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="Names"></a>
<div class="header">
<p>
Next: <a href="#Dimensions" accesskey="n" rel="next">Dimensions</a>, Previous: <a href="#Attributes" accesskey="p" rel="prev">Attributes</a>, Up: <a href="#Attributes" accesskey="u" rel="up">Attributes</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Names-1"></a>
<h4 class="subsection">2.2.1 Names</h4>
<p>A <code>names</code> attribute, when present, labels the individual elements of
a vector or list. When an object is printed the <code>names</code> attribute,
when present, is used to label the elements. The <code>names</code> attribute
can also be used for indexing purposes, for example,
<code>quantile(x)["25%"]</code>.
</p>
<p>One may get and set the names using <code>names</code> and <code>names<-</code>
constructions.
<a name="index-names"></a>
<a name="index-names_003c_002d"></a>
<a name="index-type-4"></a>
The latter will perform the necessary consistency checks to ensure that
the names attribute has the proper type and length.
</p>
<p>Pairlists and one-dimensional arrays are treated specially. For pairlist
objects, a virtual <code>names</code> attribute is used; the <code>names</code>
attribute is really constructed from the tags of the list components.
For one-dimensional arrays the <code>names</code> attribute really accesses
<code>dimnames[[1]]</code>.
</p>
<hr>
<a name="Dimensions"></a>
<div class="header">
<p>
Next: <a href="#Dimnames" accesskey="n" rel="next">Dimnames</a>, Previous: <a href="#Names" accesskey="p" rel="prev">Names</a>, Up: <a href="#Attributes" accesskey="u" rel="up">Attributes</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Dimensions-1"></a>
<h4 class="subsection">2.2.2 Dimensions</h4>
<p>The <code>dim</code> attribute is used to implement arrays. The content of
the array is stored in a vector in column-major order and the <code>dim</code>
attribute is a vector of integers specifying the respective extents of
the array. R ensures that the length of the vector is the product of
the lengths of the dimensions. The length of one or more dimensions may
be zero.
</p>
<a name="index-vector-1"></a>
<p>A vector is not the same as a one-dimensional array since the latter has
a <code>dim</code> attribute of length one, whereas the former has no
<code>dim</code> attribute.
</p>
<hr>
<a name="Dimnames"></a>
<div class="header">
<p>
Next: <a href="#Classes" accesskey="n" rel="next">Classes</a>, Previous: <a href="#Dimensions" accesskey="p" rel="prev">Dimensions</a>, Up: <a href="#Attributes" accesskey="u" rel="up">Attributes</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Dimnames-1"></a>
<h4 class="subsection">2.2.3 Dimnames</h4>
<p>Arrays may name each dimension separately using the <code>dimnames</code>
attribute which is a list of character vectors. The <code>dimnames</code>
list may itself have names which are then used for extent headings when
printing arrays.
</p>
<hr>
<a name="Classes"></a>
<div class="header">
<p>
Next: <a href="#Time-series-attributes" accesskey="n" rel="next">Time series attributes</a>, Previous: <a href="#Dimnames" accesskey="p" rel="prev">Dimnames</a>, Up: <a href="#Attributes" accesskey="u" rel="up">Attributes</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Classes-1"></a>
<h4 class="subsection">2.2.4 Classes</h4>
<p>R has an elaborate class system<a name="DOCF1" href="#FOOT1"><sup>1</sup></a>, principally controlled via
the <code>class</code> attribute. This attribute is a character vector
containing the list of classes that an object inherits from. This forms
the basis of the “generic methods” functionality in R.
</p>
<p>This attribute can be accessed and manipulated virtually without
restriction by users. There is no checking that an object actually
contains the components that class methods expect. Thus, altering the
<code>class</code> attribute should be done with caution, and when they are
available specific creation and
<a name="index-coercion-3"></a>
coercion functions should be preferred.
</p>
<hr>
<a name="Time-series-attributes"></a>
<div class="header">
<p>
Next: <a href="#Copying-of-attributes" accesskey="n" rel="next">Copying of attributes</a>, Previous: <a href="#Classes" accesskey="p" rel="prev">Classes</a>, Up: <a href="#Attributes" accesskey="u" rel="up">Attributes</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Time-series-attributes-1"></a>
<h4 class="subsection">2.2.5 Time series attributes</h4>
<p>The <code>tsp</code> attribute is used to hold parameters of time series,
start, end, and frequency. This construction is mainly used to handle
series with periodic substructure such as monthly or quarterly data.
</p>
<hr>
<a name="Copying-of-attributes"></a>
<div class="header">
<p>
Previous: <a href="#Time-series-attributes" accesskey="p" rel="prev">Time series attributes</a>, Up: <a href="#Attributes" accesskey="u" rel="up">Attributes</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Copying-of-attributes-1"></a>
<h4 class="subsection">2.2.6 Copying of attributes</h4>
<p>Whether attributes should be copied when an object is altered is a
complex area, but there are some general rules (Becker, Chambers &
Wilks, 1988, pp. 144–6).
</p>
<p>Scalar functions (those which operate element-by-element on a vector and
whose output is similar to the input) should preserve attributes (except
perhaps class).
</p>
<p>Binary operations normally copy most attributes from the longer argument
(and if they are of the same length from both, preferring the values on
the first). Here ‘most’ means all except the <code>names</code>, <code>dim</code>
and <code>dimnames</code> which are set appropriately by the code for the
operator.
</p>
<p>Subsetting (other than by an empty index) generally drops all attributes
except <code>names</code>, <code>dim</code> and <code>dimnames</code> which are reset as
appropriate. On the other hand, subassignment generally preserves
attributes even if the length is changed. Coercion drops all
attributes.
</p>
<p>The default method for sorting drops all attributes except names, which
are sorted along with the object.
</p>
<hr>
<a name="Special-compound-objects"></a>
<div class="header">
<p>
Previous: <a href="#Attributes" accesskey="p" rel="prev">Attributes</a>, Up: <a href="#Objects" accesskey="u" rel="up">Objects</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Special-compound-objects-1"></a>
<h3 class="section">2.3 Special compound objects</h3>
<table summary="" class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">• <a href="#Factors" accesskey="1">Factors</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Data-frame-objects" accesskey="2">Data frame objects</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="Factors"></a>
<div class="header">
<p>
Next: <a href="#Data-frame-objects" accesskey="n" rel="next">Data frame objects</a>, Previous: <a href="#Special-compound-objects" accesskey="p" rel="prev">Special compound objects</a>, Up: <a href="#Special-compound-objects" accesskey="u" rel="up">Special compound objects</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Factors-1"></a>
<h4 class="subsection">2.3.1 Factors</h4>
<p>Factors are used to describe items that can have a finite number of
values (gender, social class, etc.). A factor has a <code>levels</code>
attribute and class <code>"factor"</code>. Optionally, it may also contain a
<code>contrasts</code> attribute which controls the parametrisation used when
the factor is used in a
<a name="index-function_002c-modeling"></a>
<a name="index-modeling-function"></a>
modeling functions.
</p>
<p>A factor may be purely nominal or may have ordered categories. In the
latter case, it should be defined as such and have a <code>class</code> vector
<code>c("ordered"," factor")</code>.
</p>
<p>Factors are currently implemented using an integer array to specify the
actual levels and a second array of names that are mapped to the
integers. Rather unfortunately users often make use of the
implementation in order to make some calculations easier. This,
however, is an implementation issue and is not guaranteed to hold in all
implementations of R.
</p>
<hr>
<a name="Data-frame-objects"></a>
<div class="header">
<p>
Previous: <a href="#Factors" accesskey="p" rel="prev">Factors</a>, Up: <a href="#Special-compound-objects" accesskey="u" rel="up">Special compound objects</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Data-frame-objects-1"></a>
<h4 class="subsection">2.3.2 Data frame objects</h4>
<p>Data frames are the R structures which most closely mimic the SAS or
SPSS data set, i.e. a “cases by variables” matrix of data.
</p>
<p>A data frame is a list of vectors, factors, and/or matrices all having
the same length (number of rows in the case of matrices). In addition,
a data frame generally has a <code>names</code> attribute labeling the
variables and a <code>row.names</code> attribute for labeling the cases.
</p>
<p>A data frame can contain a list that is the same length as the other
components. The list can contain elements of differing lengths thereby
providing a data structure for ragged arrays. However, as of this
writing such arrays are not generally handled correctly.
</p>
<hr>
<a name="Evaluation-of-expressions"></a>
<div class="header">
<p>
Next: <a href="#Functions" accesskey="n" rel="next">Functions</a>, Previous: <a href="#Objects" accesskey="p" rel="prev">Objects</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Evaluation-of-expressions-1"></a>
<h2 class="chapter">3 Evaluation of expressions</h2>
<p>When a user types a command at the prompt (or when an expression is read
from a file) the first thing that happens to it is that the command is
transformed by the
<a name="index-parsing-2"></a>
parser into an internal representation. The
evaluator executes parsed R expressions and returns the value of the
expression. All expressions have a value. This is the core of the
language.
</p>
<p>This chapter describes the basic mechanisms of the evaluator, but avoids
discussion of specific functions or groups of functions which are
described in separate chapters later on or where the help pages should
be sufficient documentation.
</p>
<p>Users can construct expressions and invoke the evaluator on them.
</p>
<table summary="" class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">• <a href="#Simple-evaluation" accesskey="1">Simple evaluation</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Control-structures" accesskey="2">Control structures</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Elementary-arithmetic-operations" accesskey="3">Elementary arithmetic operations</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Indexing" accesskey="4">Indexing</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Scope-of-variables" accesskey="5">Scope of variables</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="Simple-evaluation"></a>
<div class="header">
<p>
Next: <a href="#Control-structures" accesskey="n" rel="next">Control structures</a>, Previous: <a href="#Evaluation-of-expressions" accesskey="p" rel="prev">Evaluation of expressions</a>, Up: <a href="#Evaluation-of-expressions" accesskey="u" rel="up">Evaluation of expressions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Simple-evaluation-1"></a>
<h3 class="section">3.1 Simple evaluation</h3>
<table summary="" class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">• <a href="#Constants" accesskey="1">Constants</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Symbol-lookup" accesskey="2">Symbol lookup</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Function-calls" accesskey="3">Function calls</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Operators" accesskey="4">Operators</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="Constants"></a>
<div class="header">
<p>
Next: <a href="#Symbol-lookup" accesskey="n" rel="next">Symbol lookup</a>, Previous: <a href="#Simple-evaluation" accesskey="p" rel="prev">Simple evaluation</a>, Up: <a href="#Simple-evaluation" accesskey="u" rel="up">Simple evaluation</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Constants-1"></a>
<h4 class="subsection">3.1.1 Constants</h4>
<p>Any number typed directly at the prompt is a constant and is evaluated.
</p>
<div class="example">
<pre class="example">> 1
[1] 1
</pre></div>
<p>Perhaps unexpectedly, the number returned from the expression <code>1</code>
is a numeric. In most cases, the difference between an integer and a
numeric value will be unimportant as R will do the right thing when
using the numbers. There are, however, times when we would like to
explicitly create an integer value for a constant. We can do this by
calling the function <code>as.integer</code> or using various other
techniques. But perhaps the simplest approach is to qualify our
constant with the suffix character ‘L’.
For example, to create the integer value 1, we might use
</p>
<div class="example">
<pre class="example">> 1L
[1]
</pre></div>
<p>We can use the ‘L’ suffix to qualify any number with the intent of
making it an explicit integer. So ‘0x10L’ creates the integer value
16 from the hexadecimal representation. The constant <code>1e3L</code> gives 1000
as an integer rather than a numeric value and is equivalent to <code>1000L</code>.
(Note that the ‘L’ is treated as qualifying the term <code>1e3</code> and not the
<code>3</code>.) If we qualify a value with ‘L’ that is not an integer value,
e.g. <code>1e-3L</code>, we get a warning and the numeric value is created.
A warning is also created if there is an unnecessary decimal point
in the number, e.g. <code>1.L</code>.
</p>
<p>We get a syntax error when using ‘L’ with complex numbers,
e.g. <code>12iL</code> gives an error.
</p>
<p>Constants are fairly boring and to do more we need symbols.
</p>
<hr>
<a name="Symbol-lookup"></a>
<div class="header">
<p>
Next: <a href="#Function-calls" accesskey="n" rel="next">Function calls</a>, Previous: <a href="#Constants" accesskey="p" rel="prev">Constants</a>, Up: <a href="#Simple-evaluation" accesskey="u" rel="up">Simple evaluation</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Symbol-lookup-1"></a>
<h4 class="subsection">3.1.2 Symbol lookup</h4>
<p>When a new variable is created it must have a
<a name="index-name-2"></a>
name so it can be referenced and it usually has a value. The name itself is a
<a name="index-symbol-2"></a>
symbol.
When a symbol is
<a name="index-evaluation_002c-symbol-1"></a>
evaluated its
<a name="index-value"></a>
value is returned. Later we shall
explain in detail how to determine the value associated with a symbol.
</p>
<p>In this small example <code>y</code> is a symbol and its value is 4. A symbol
is an R object too, but one rarely needs to deal with symbols
directly, except when doing “programming on the language”
(<a href="#Computing-on-the-language">Computing on the language</a>).
</p>
<div class="example">
<pre class="example">> y <- 4
> y
[1] 4
</pre></div>
<hr>
<a name="Function-calls"></a>
<div class="header">
<p>
Next: <a href="#Operators" accesskey="n" rel="next">Operators</a>, Previous: <a href="#Symbol-lookup" accesskey="p" rel="prev">Symbol lookup</a>, Up: <a href="#Simple-evaluation" accesskey="u" rel="up">Simple evaluation</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Function-calls-1"></a>
<h4 class="subsection">3.1.3 Function calls</h4>
<p>Most of the computations carried out in R involve the evaluation of
functions. We will also refer to this as
<a name="index-function-invocation"></a>
function <em>invocation</em>.
Functions are invoked by name with a list of arguments separated by
commas.
</p>
<div class="example">
<pre class="example">> mean(1:10)
[1] 5.5
</pre></div>
<p>In this example the function <code>mean</code> was called with one argument,
the vector of integers from 1 to 10.
</p>
<p>R contains a huge number of functions with different purposes. Most
are used for producing a result which is an R object, but others are
used for their side effects, e.g., printing and plotting functions.
</p>
<a name="index-function-7"></a>
<a name="index-function-arguments"></a>
<p>Function calls can have <em>tagged</em> (or <em>named</em>) arguments, as in
<code>plot(x, y, pch = 3)</code>. Arguments without tags are known as
<em>positional</em> since the function must distinguish their meaning from
their sequential positions among the arguments of the call, e.g., that
<code>x</code> denotes the abscissa variable and <code>y</code> the ordinate. The
use of tags/names is an obvious convenience for functions with a large
number of optional arguments.
</p>
<a name="index-function_002c-assignment"></a>
<p>A special type of function calls can appear on the left hand side of
the
<a name="index-assignment-1"></a>
assignment operator as in
</p>
<div class="example">
<pre class="example">> class(x) <- "foo"
</pre></div>
<p>What this construction really does is to call the function
<code>class<-</code> with the original object and the right hand side. This
function performs the modification of the object and returns the result
which is then stored back into the original variable. (At least
conceptually, this is what happens. Some additional effort is made to
avoid unnecessary data duplication.)
</p>
<hr>
<a name="Operators"></a>
<div class="header">
<p>
Previous: <a href="#Function-calls" accesskey="p" rel="prev">Function calls</a>, Up: <a href="#Simple-evaluation" accesskey="u" rel="up">Simple evaluation</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Operators-1"></a>
<h4 class="subsection">3.1.4 Operators</h4>
<p>R allows the use of arithmetic expressions using operators similar to
those of the C programming language, for instance
</p>
<div class="example">
<pre class="example">> 1 + 2
[1] 3
</pre></div>
<p>Expressions can be grouped using parentheses, mixed with function calls,
and assigned to variables in a straightforward manner
</p>
<div class="example">
<pre class="example">> y <- 2 * (a + log(x))
</pre></div>
<p>R contains a number of operators. They are listed in the table
below.
</p>
<blockquote>
<table summary="">
<tr><td width="10%"><code>-</code></td><td width="70%">Minus, can be unary or binary</td></tr>
<tr><td width="10%"><code>+</code></td><td width="70%">Plus, can be unary or binary</td></tr>
<tr><td width="10%"><code>!</code></td><td width="70%">Unary not</td></tr>
<tr><td width="10%"><code>~</code></td><td width="70%">Tilde, used for model formulae, can be either unary or binary</td></tr>
<tr><td width="10%"><code>?</code></td><td width="70%">Help</td></tr>
<tr><td width="10%"><code>:</code></td><td width="70%">Sequence, binary (in model formulae: interaction)</td></tr>
<tr><td width="10%"><code>*</code></td><td width="70%">Multiplication, binary</td></tr>
<tr><td width="10%"><code>/</code></td><td width="70%">Division, binary</td></tr>
<tr><td width="10%"><code>^</code></td><td width="70%">Exponentiation, binary</td></tr>
<tr><td width="10%"><code>%<var>x</var>%</code></td><td width="70%">Special binary operators, <var>x</var> can be replaced by any valid name</td></tr>
<tr><td width="10%"><code>%%</code></td><td width="70%">Modulus, binary</td></tr>
<tr><td width="10%"><code>%/%</code></td><td width="70%">Integer divide, binary</td></tr>
<tr><td width="10%"><code>%*%</code></td><td width="70%">Matrix product, binary</td></tr>
<tr><td width="10%"><code>%o%</code></td><td width="70%">Outer product, binary</td></tr>
<tr><td width="10%"><code>%x%</code></td><td width="70%">Kronecker product, binary</td></tr>
<tr><td width="10%"><code>%in%</code></td><td width="70%">Matching operator, binary (in model formulae: nesting)</td></tr>
<tr><td width="10%"><code><</code></td><td width="70%">Less than, binary</td></tr>
<tr><td width="10%"><code>></code></td><td width="70%">Greater than, binary</td></tr>
<tr><td width="10%"><code>==</code></td><td width="70%">Equal to, binary</td></tr>
<tr><td width="10%"><code>>=</code></td><td width="70%">Greater than or equal to, binary</td></tr>
<tr><td width="10%"><code><=</code></td><td width="70%">Less than or equal to, binary</td></tr>
<tr><td width="10%"><code>&</code></td><td width="70%">And, binary, vectorized</td></tr>
<tr><td width="10%"><code>&&</code></td><td width="70%">And, binary, not vectorized</td></tr>
<tr><td width="10%"><code>|</code></td><td width="70%">Or, binary, vectorized</td></tr>
<tr><td width="10%"><code>||</code></td><td width="70%">Or, binary, not vectorized</td></tr>
<tr><td width="10%"><code><-</code></td><td width="70%">Left assignment, binary</td></tr>
<tr><td width="10%"><code>-></code></td><td width="70%">Right assignment, binary</td></tr>
<tr><td width="10%"><code>$</code></td><td width="70%">List subset, binary</td></tr>
</table>
</blockquote>
<p>Except for the syntax, there is no difference between applying an
operator and calling a function. In fact, <code>x + y</code> can equivalently
be written <code>`+`(x, y)</code>. Notice that since ‘<samp>+</samp>’ is a
non-standard function name, it needs to be quoted.
</p>
<a name="index-vector-2"></a>
<p>R deals with entire vectors of data at a time, and most of the
elementary operators and basic mathematical functions like <code>log</code>
are vectorized (as indicated in the table above). This means that
e.g. adding two vectors of the same length will create a vector
containing the element-wise sums, implicitly looping over the vector
index. This applies also to other operators like <code>-</code>, <code>*</code>,
and <code>/</code> as well as to higher dimensional structures. Notice in
particular that multiplying two matrices does not produce the usual
matrix product (the <code>%*%</code> operator exists for that purpose). Some
finer points relating to vectorized operations will be discussed in
<a href="#Elementary-arithmetic-operations">Elementary arithmetic operations</a>.
</p>
<p>To access individual elements of an atomic vector, one generally uses
the <code>x[i]</code> construction.
</p>
<div class="example">
<pre class="example">> x <- rnorm(5)
> x
[1] -0.12526937 -0.27961154 -1.03718717 -0.08156527 1.37167090
> x[2]
[1] -0.2796115
</pre></div>
<p>List components are more commonly accessed using <code>x$a</code> or
<code>x[[i]]</code>.
</p>
<div class="example">
<pre class="example">> x <- options()
> x$prompt
[1] "> "
</pre></div>
<p>Indexing constructs can also appear on the right hand side of an
<a name="index-assignment-2"></a>
assignment.
</p>
<p>Like the other operators, indexing is really done by functions, and one
could have used <code>`[`(x, 2)</code> instead of <code>x[2]</code>.
</p>
<p>R’s indexing operations contain many advanced features which are
further described in <a href="#Indexing">Indexing</a>.
</p>
<hr>
<a name="Control-structures"></a>
<div class="header">
<p>
Next: <a href="#Elementary-arithmetic-operations" accesskey="n" rel="next">Elementary arithmetic operations</a>, Previous: <a href="#Simple-evaluation" accesskey="p" rel="prev">Simple evaluation</a>, Up: <a href="#Evaluation-of-expressions" accesskey="u" rel="up">Evaluation of expressions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Control-structures-1"></a>
<h3 class="section">3.2 Control structures</h3>
<p>Computation in R consists of sequentially evaluating
<em>statements</em>. Statements, such as <code>x<-1:10</code> or
<code>mean(y)</code>, can be separated by either a semi-colon or a new line.
Whenever the
<a name="index-evaluation_002c-statement"></a>
evaluator is presented with a syntactically complete
statement that statement is evaluated and the <em>value</em> returned.
The result of evaluating a statement can be referred to as the value of
the statement<a name="DOCF2" href="#FOOT2"><sup>2</sup></a> The value can
always be assigned to a symbol.
</p>
<p>Both semicolons and new lines can be used to separate statements. A
semicolon always indicates the end of a statement while a new line
<em>may</em> indicate the end of a statement. If the current statement is
not syntactically complete new lines are simply ignored by the
evaluator. If the session is interactive the prompt changes from
‘<samp>></samp>’ to ‘<samp>+</samp>’.
</p>
<div class="example">
<pre class="example">> x <- 0; x + 5
[1] 5
> y <- 1:10
> 1; 2
[1] 1
[1] 2
</pre></div>
<p>Statements can be grouped together using braces ‘<samp>{</samp>’ and ‘<samp>}</samp>’.
A group of statements is sometimes called a <em>block</em>. Single
statements are evaluated when a new line is typed at the end of the
syntactically complete statement. Blocks are not evaluated until a new
line is entered after the closing brace. In the remainder of this
section, <em>statement</em> refers to either a single statement or a
block.
</p>
<div class="example">
<pre class="example">> { x <- 0
+ x + 5
+ }
[1] 5
</pre></div>
<table summary="" class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">• <a href="#if" accesskey="1">if</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Looping" accesskey="2">Looping</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#repeat" accesskey="3">repeat</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#while" accesskey="4">while</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#for" accesskey="5">for</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#switch" accesskey="6">switch</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="if"></a>
<div class="header">
<p>
Next: <a href="#Looping" accesskey="n" rel="next">Looping</a>, Previous: <a href="#Control-structures" accesskey="p" rel="prev">Control structures</a>, Up: <a href="#Control-structures" accesskey="u" rel="up">Control structures</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="if-1"></a>
<h4 class="subsection">3.2.1 if</h4>
<p>The <code>if</code>/<code>else</code> statement conditionally evaluates two
statements. There is a <em>condition</em> which is evaluated and if the
<em>value</em> is <code>TRUE</code> then the first statement is evaluated;
otherwise the second statement will be evaluated. The
<code>if</code>/<code>else</code> statement returns, as its value, the value of the
statement that was selected. The formal syntax is
</p>
<div class="example">
<pre class="example">if ( <var>statement1</var> )
<var>statement2</var>
else
<var>statement3</var>
</pre></div>
<p>First, <var>statement1</var> is evaluated to yield <var>value1</var>. If
<var>value1</var> is a logical vector with first element <code>TRUE</code> then
<var>statement2</var> is evaluated. If the first element of <var>value1</var> is
<code>FALSE</code> then <var>statement3</var> is evaluated. If <var>value1</var> is a
numeric vector then <var>statement3</var> is evaluated when the first element
of <var>value1</var> is zero and otherwise <var>statement2</var> is evaluated.
Only the first element of <var>value1</var> is used. All other elements are
ignored. If <var>value1</var> has any type other than a logical or a numeric
vector an error is signalled.
</p>
<p><code>if</code>/<code>else</code> statements can be used to avoid numeric problems
such as taking the logarithm of a negative number. Because
<code>if</code>/<code>else</code> statements are the same as other statements you
can assign the value of them. The two examples below are equivalent.
</p>
<div class="example">
<pre class="example">> if( any(x <= 0) ) y <- log(1+x) else y <- log(x)
> y <- if( any(x <= 0) ) log(1+x) else log(x)
</pre></div>
<p>The <code>else</code> clause is optional. The statement <code>if(any(x <= 0))
x <- x[x <= 0]</code> is valid. When the <code>if</code> statement is not in a
block the <code>else</code>, if present, must appear on the same line as
the end of <var>statement2</var>. Otherwise the new line at the end of
<var>statement2</var> completes the <code>if</code> and yields a syntactically
complete statement that is evaluated. A simple solution is to use a
compound statement wrapped in braces, putting the <code>else</code> on the
same line as the closing brace that marks the end of the statement.
</p>
<p><code>if</code>/<code>else</code> statements can be nested.
</p>
<div class="example">
<pre class="example">if ( <var>statement1</var> ) {
<var>statement2</var>
} else if ( <var>statement3</var> ) {
<var>statement4</var>
} else if ( <var>statement5</var> ) {
<var>statement6</var>
} else
<var>statement8</var>
</pre></div>
<p>One of the even numbered statements will be evaluated and the resulting
value returned. If the optional <code>else</code> clause is omitted and all
the odd numbered <var>statement</var>s evaluate to <code>FALSE</code> no statement
will be evaluated and <code>NULL</code> is returned.
</p>
<p>The odd numbered <var>statement</var>s are evaluated, in order, until one
evaluates to <code>TRUE</code> and then the associated even numbered
<var>statement</var> is evaluated. In this example, <var>statement6</var> will
only be evaluated if <var>statement1</var> is <code>FALSE</code> and
<var>statement3</var> is <code>FALSE</code> and <var>statement5</var> is <code>TRUE</code>.
There is no limit to the number of <code>else if</code> clauses that are
permitted.
</p>
<hr>
<a name="Looping"></a>
<div class="header">
<p>
Next: <a href="#repeat" accesskey="n" rel="next">repeat</a>, Previous: <a href="#if" accesskey="p" rel="prev">if</a>, Up: <a href="#Control-structures" accesskey="u" rel="up">Control structures</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Looping-1"></a>
<h4 class="subsection">3.2.2 Looping</h4>
<p>R has three statements that provide explicit
looping.<a name="DOCF3" href="#FOOT3"><sup>3</sup></a> They are <code>for</code>, <code>while</code> and
<code>repeat</code>. The two built-in constructs, <code>next</code> and
<code>break</code>, provide additional control over the evaluation.
R provides other functions for
implicit looping such as <code>tapply</code>, <code>apply</code>, and <code>lapply</code>.
In addition many operations, especially arithmetic ones, are vectorized
so you may not need to use a loop.
</p>
<p>There are two statements that can be used to explicitly control looping.
They are <code>break</code> and <code>next</code>.
<a name="index-break"></a>
<a name="index-next"></a>
The <code>break</code> statement causes an exit from the innermost loop that
is currently being executed. The <code>next</code> statement immediately
causes control to return to the start of the loop. The next iteration
of the loop (if there is one) is then executed. No statement below
<code>next</code> in the current loop is evaluated.
</p>
<p>The value returned by a loop statement is always <code>NULL</code>
and is returned invisibly.
</p>
<hr>
<a name="repeat"></a>
<div class="header">
<p>
Next: <a href="#while" accesskey="n" rel="next">while</a>, Previous: <a href="#Looping" accesskey="p" rel="prev">Looping</a>, Up: <a href="#Control-structures" accesskey="u" rel="up">Control structures</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="repeat-1"></a>
<h4 class="subsection">3.2.3 repeat</h4>
<a name="index-repeat"></a>
<p>The <code>repeat</code> statement causes repeated evaluation of the body until
a break is specifically requested. This means that you need to be
careful when using <code>repeat</code> because of the danger of an infinite
loop. The syntax of the <code>repeat</code> loop is
</p>
<div class="example">
<pre class="example">repeat <var>statement</var>
</pre></div>
<p>When using <code>repeat</code>, <var>statement</var> must be a block statement.
You need to both perform some computation and test whether or not to
break from the loop and usually this requires two statements.
</p>
<hr>
<a name="while"></a>
<div class="header">
<p>
Next: <a href="#for" accesskey="n" rel="next">for</a>, Previous: <a href="#repeat" accesskey="p" rel="prev">repeat</a>, Up: <a href="#Control-structures" accesskey="u" rel="up">Control structures</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="while-1"></a>
<h4 class="subsection">3.2.4 while</h4>
<a name="index-while"></a>
<p>The <code>while</code> statement is very similar to the <code>repeat</code>
statement. The syntax of the <code>while</code> loop is
</p>
<div class="example">
<pre class="example">while ( <var>statement1</var> ) <var>statement2</var>
</pre></div>
<p>where <var>statement1</var> is evaluated and if its value is <code>TRUE</code> then
<var>statement2</var> is evaluated. This process continues until
<var>statement1</var> evaluates to <code>FALSE</code>.
</p>
<hr>
<a name="for"></a>
<div class="header">
<p>
Next: <a href="#switch" accesskey="n" rel="next">switch</a>, Previous: <a href="#while" accesskey="p" rel="prev">while</a>, Up: <a href="#Control-structures" accesskey="u" rel="up">Control structures</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="for-1"></a>
<h4 class="subsection">3.2.5 for</h4>
<a name="index-for"></a>
<p>The syntax of the <code>for</code> loop is
</p>
<div class="example">
<pre class="example">for ( <var>name</var> in <var>vector</var> )
<var>statement1</var>
</pre></div>
<p>where <var>vector</var> can be either a vector or a list. For each element
in <var>vector</var> the variable <var>name</var> is set to the value of that
element and <var>statement1</var> is evaluated. A side effect is that the
variable <var>name</var> still exists after the loop has concluded and it has
the value of the last element of <var>vector</var> that the loop was
evaluated for.
</p>
<hr>
<a name="switch"></a>
<div class="header">
<p>
Previous: <a href="#for" accesskey="p" rel="prev">for</a>, Up: <a href="#Control-structures" accesskey="u" rel="up">Control structures</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="switch-1"></a>
<h4 class="subsection">3.2.6 switch</h4>
<a name="index-switch"></a>
<p>Technically speaking, <code>switch</code> is just another function, but its
semantics are close to those of control structures of other programming
languages.
</p>
<p>The syntax is
</p>
<div class="example">
<pre class="example">switch (<var>statement</var>, <var>list</var>)
</pre></div>
<p>where the elements of <var>list</var> may be named. First, <var>statement</var>
is evaluated and the result, <var>value</var>, obtained. If <var>value</var> is a
number between 1 and the length of <var>list</var> then the corresponding
element of <var>list</var> is evaluated and the result returned. If <var>value</var>
is too large or too small <code>NULL</code> is returned.
</p>
<div class="example">
<pre class="example">> x <- 3
> switch(x, 2+2, mean(1:10), rnorm(5))
[1] 2.2903605 2.3271663 -0.7060073 1.3622045 -0.2892720
> switch(2, 2+2, mean(1:10), rnorm(5))
[1] 5.5
> switch(6, 2+2, mean(1:10), rnorm(5))
NULL
</pre></div>
<p>If <var>value</var> is a character vector then the element of ‘<samp>...</samp>’ with
a name that exactly matches <var>value</var> is evaluated. If there is no
match a single unnamed argument will be used as a default. If no
default is specified, <code>NULL</code> is returned.
</p>
<div class="example">
<pre class="example">> y <- "fruit"
> switch(y, fruit = "banana", vegetable = "broccoli", "Neither")
[1] "banana"
> y <- "meat"
> switch(y, fruit = "banana", vegetable = "broccoli", "Neither")
[1] "Neither"
</pre></div>
<p>A common use of <code>switch</code> is to branch according to the character
value of one of the arguments to a function.
</p>
<div class="example">
<pre class="example">> centre <- function(x, type) {
+ switch(type,
+ mean = mean(x),
+ median = median(x),
+ trimmed = mean(x, trim = .1))
+ }
> x <- rcauchy(10)
> centre(x, "mean")
[1] 0.8760325
> centre(x, "median")
[1] 0.5360891
> centre(x, "trimmed")
[1] 0.6086504
</pre></div>
<p><code>switch</code> returns either the value of the statement that was
evaluated or <code>NULL</code> if no statement was evaluated.
</p>
<p>To choose from a list of alternatives that already exists <code>switch</code>
may not be the best way to select one for evaluation. It is often
better to use <code>eval</code> and the subset operator, <code>[[</code>, directly
via <code>eval(x[[condition]])</code>.
</p>
<hr>
<a name="Elementary-arithmetic-operations"></a>
<div class="header">
<p>
Next: <a href="#Indexing" accesskey="n" rel="next">Indexing</a>, Previous: <a href="#Control-structures" accesskey="p" rel="prev">Control structures</a>, Up: <a href="#Evaluation-of-expressions" accesskey="u" rel="up">Evaluation of expressions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Elementary-arithmetic-operations-1"></a>
<h3 class="section">3.3 Elementary arithmetic operations</h3>
<table summary="" class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">• <a href="#Recycling-rules" accesskey="1">Recycling rules</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Propagation-of-names" accesskey="2">Propagation of names</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Dimensional-attributes" accesskey="3">Dimensional attributes</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#NA-handling" accesskey="4">NA handling</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
</table>
<p>In this section, we discuss the finer points of the rules that apply to
basic operation like addition or multiplication of two vectors or
matrices.
</p>
<hr>
<a name="Recycling-rules"></a>
<div class="header">
<p>
Next: <a href="#Propagation-of-names" accesskey="n" rel="next">Propagation of names</a>, Previous: <a href="#Elementary-arithmetic-operations" accesskey="p" rel="prev">Elementary arithmetic operations</a>, Up: <a href="#Elementary-arithmetic-operations" accesskey="u" rel="up">Elementary arithmetic operations</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Recycling-rules-1"></a>
<h4 class="subsection">3.3.1 Recycling rules</h4>
<p>If one tries to add two structures with a different number of elements,
then the shortest is recycled to length of longest. That is, if for
instance you add <code>c(1, 2, 3)</code> to a six-element vector then you will
really add <code>c(1, 2, 3, 1, 2, 3)</code>. If the length of the longer
vector is not a multiple of the shorter one, a warning is given.
</p>
<p>As from R 1.4.0, any arithmetic operation involving a zero-length
vector has a zero-length result.
</p>
<hr>
<a name="Propagation-of-names"></a>
<div class="header">
<p>
Next: <a href="#Dimensional-attributes" accesskey="n" rel="next">Dimensional attributes</a>, Previous: <a href="#Recycling-rules" accesskey="p" rel="prev">Recycling rules</a>, Up: <a href="#Elementary-arithmetic-operations" accesskey="u" rel="up">Elementary arithmetic operations</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Propagation-of-names-1"></a>
<h4 class="subsection">3.3.2 Propagation of names</h4>
<a name="index-name-3"></a>
<p>propagation of names (first one wins, I think - also if it has no
names?? —- first one *with names* wins, recycling causes shortest to
lose names)
</p>
<hr>
<a name="Dimensional-attributes"></a>
<div class="header">
<p>
Next: <a href="#NA-handling" accesskey="n" rel="next">NA handling</a>, Previous: <a href="#Propagation-of-names" accesskey="p" rel="prev">Propagation of names</a>, Up: <a href="#Elementary-arithmetic-operations" accesskey="u" rel="up">Elementary arithmetic operations</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Dimensional-attributes-1"></a>
<h4 class="subsection">3.3.3 Dimensional attributes</h4>
<p>(matrix+matrix, dimensions must match. vector+matrix: first recycle,
then check if dims fit, error if not)
</p>
<hr>
<a name="NA-handling"></a>
<div class="header">
<p>
Previous: <a href="#Dimensional-attributes" accesskey="p" rel="prev">Dimensional attributes</a>, Up: <a href="#Elementary-arithmetic-operations" accesskey="u" rel="up">Elementary arithmetic operations</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="NA-handling-1"></a>
<h4 class="subsection">3.3.4 NA handling</h4>
<p>Missing values in the statistical sense, that is, variables whose value
is not known, have the value <code>NA</code>. This should not be confused with
the <code>missing</code> property for a function argument that has not been
supplied (see <a href="#Arguments">Arguments</a>).
<a name="index-missing"></a>
<a name="index-NA"></a>
<a name="index-NaN"></a>
</p>
<a name="index-type-5"></a>
<p>As the elements of an atomic vector must be of the same type there are
multiple types of <code>NA</code> values. There is one case where this is
particularly important to the user. The default type of <code>NA</code> is
<code>logical</code>, unless coerced to some other type, so the appearance of
a missing value may trigger logical rather than numeric indexing (see
<a href="#Indexing">Indexing</a> for details).
</p>
<p>Numeric and logical calculations with <code>NA</code> generally return
<code>NA</code>. In cases where the result of the operation would be the same
for all possible values the <code>NA</code> could take, the operation may
return this value. In particular, ‘<samp>FALSE & NA</samp>’ is <code>FALSE</code>,
‘<samp>TRUE | NA</samp>’ is <code>TRUE</code>. <code>NA</code> is not equal to any other
value or to itself; testing for <code>NA</code> is done using <code>is.na</code>.
<a name="index-is_002ena"></a>
However, an <code>NA</code> value will match another <code>NA</code> value in
<code>match</code>.
</p>
<p>Numeric calculations whose result is undefined, such as ‘<samp>0/0</samp>’,
produce the value <code>NaN</code>. This exists only in the <code>double</code>
type and for real or imaginary components of the complex type. The
function <code>is.nan</code> is provided to check specifically for
<a name="index-is_002enan"></a>
<code>NaN</code>, <code>is.na</code> also returns <code>TRUE</code> for <code>NaN</code>.
<a name="index-coercion-4"></a>
Coercing <code>NaN</code> to logical or integer type gives an <code>NA</code> of the
appropriate type, but coercion to character gives the string
<code>"NaN"</code>. <code>NaN</code> values are incomparable so tests of equality
or collation involving <code>NaN</code> will result in <code>NA</code>. They are
regarded as matching any <code>NaN</code> value (and no other value, not even
<code>NA</code>) by <code>match</code>.
</p>
<p>The <code>NA</code> of character type is as from R 1.5.0 distinct from the
string <code>"NA"</code>. Programmers who need to specify an explicit string
<code>NA</code> should use ‘<samp>as.character(NA)</samp>’ rather than <code>"NA"</code>, or
set elements to <code>NA</code> using <code>is.na<-</code>.
</p>
<p>There are constants <code>NA_integer_</code>, <code>NA_real_</code>,
<code>NA_complex_</code> and <code>NA_character_</code> which will generate (in the
parser) an <code>NA</code> value of the appropriate type, and will be used in
deparsing when it is not otherwise possible to identify the type of an
<code>NA</code> (and the <code>control</code> options ask for this to be done).
</p>
<p>There is no <code>NA</code> value for raw vectors.
</p>
<hr>
<a name="Indexing"></a>
<div class="header">
<p>
Next: <a href="#Scope-of-variables" accesskey="n" rel="next">Scope of variables</a>, Previous: <a href="#Elementary-arithmetic-operations" accesskey="p" rel="prev">Elementary arithmetic operations</a>, Up: <a href="#Evaluation-of-expressions" accesskey="u" rel="up">Evaluation of expressions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Indexing-1"></a>
<h3 class="section">3.4 Indexing</h3>
<p>R contains several constructs which allow access to individual
elements or subsets through indexing operations. In the case of the
basic vector types one can access the i-th element using <code>x[i]</code>,
but there is also indexing of lists, matrices, and multi-dimensional
arrays. There are several forms of indexing in addition to indexing
with a single integer. Indexing can be used both to extract part of an
object and to replace parts of an object (or to add parts).
</p>
<p>R has three basic indexing operators, with syntax displayed by the
following examples
</p>
<div class="example">
<pre class="example">x[i]
x[i, j]
x[[i]]
x[[i, j]]
x$a
x$"a"
</pre></div>
<a name="index-_005b"></a>
<a name="index-_005b_005b"></a>
<a name="index-_0024"></a>
<a name="index-index-2"></a>
<p>For vectors and matrices the <code>[[</code> forms are rarely used, although
they have some slight semantic differences from the <code>[</code> form (e.g.
it drops any <code>names</code> or <code>dimnames</code> attribute, and that partial
matching is used for character indices). When indexing
multi-dimensional structures with a single index, <code>x[[i]]</code> or
<code>x[i]</code> will return the <code>i</code>th sequential element of <code>x</code>.
</p>
<p>For lists, one generally uses <code>[[</code> to select any single element,
whereas <code>[</code> returns a list of the selected elements.
</p>
<p>The <code>[[</code> form allows only a single element to be selected using
integer or character indices, whereas <code>[</code> allows indexing by
vectors. Note though that for a list or other recursive object, the
index can be a vector and each element of the vector is applied in
turn to the list, the selected component, the selected component of
that component, and so on. The result is still a single element.
</p>
<p>The form using <code>$</code> applies to recursive objects such as lists and
pairlists. It allows only a literal character string or a symbol as the
index. That is, the index is not computable: for cases where you need
to evaluate an expression to find the index, use <code>x[[expr]]</code>.
Applying <code>$</code> to a non-recursive object is an error.
</p>
<table summary="" class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">• <a href="#Indexing-by-vectors" accesskey="1">Indexing by vectors</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Indexing-matrices-and-arrays" accesskey="2">Indexing matrices and arrays</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Indexing-other-structures" accesskey="3">Indexing other structures</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Subset-assignment" accesskey="4">Subset assignment</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="Indexing-by-vectors"></a>
<div class="header">
<p>
Next: <a href="#Indexing-matrices-and-arrays" accesskey="n" rel="next">Indexing matrices and arrays</a>, Previous: <a href="#Indexing" accesskey="p" rel="prev">Indexing</a>, Up: <a href="#Indexing" accesskey="u" rel="up">Indexing</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Indexing-by-vectors-1"></a>
<h4 class="subsection">3.4.1 Indexing by vectors</h4>
<p>R allows some powerful constructions using vectors as indices. We
shall discuss indexing of simple vectors first. For simplicity, assume
that the expression is <code>x[i]</code>. Then the following possibilities
exist according to the type of <code>i</code>.
</p>
<ul>
<li> <a name="index-index-3"></a>
<strong>Integer</strong>. All elements of <code>i</code> must have the same sign. If
they are positive, the elements of <code>x</code> with those index numbers are
selected. If <code>i</code> contains negative elements, all elements except
those indicated are selected.
<p>If <code>i</code> is positive and exceeds <code>length(x)</code> then the
corresponding selection is <code>NA</code>. Negative out of bounds values
for <code>i</code> are silently disregarded since R version 2.6.0, S compatibly,
as they mean to drop non-existing elements and that is an empty operation
(“no-op”).
</p>
<p>A special case is the zero index, which has null effects: <code>x[0]</code> is
an empty vector and otherwise including zeros among positive or negative
indices has the same effect as if they were omitted.
</p>
</li><li> <strong>Other numeric</strong>. Non-integer values are converted to integer
(by truncation towards zero) before use.
</li><li> <strong>Logical</strong>. The indexing <code>i</code> should generally have the same
length as <code>x</code>. If it is shorter, then its elements will be
recycled as discussed in <a href="#Elementary-arithmetic-operations">Elementary arithmetic operations</a>. If it
is longer, then <code>x</code> is conceptually extended with <code>NA</code>s. The
selected values of <code>x</code> are those for which <code>i</code> is <code>TRUE</code>.
</li><li> <a name="index-partial-matching"></a>
<strong>Character</strong>. The strings in <code>i</code> are matched against the
names attribute of <code>x</code> and the resulting integers are used. For
<code>[[</code> and <code>$</code> partial matching is used if exact matching fails,
so <code>x$aa</code> will match <code>x$aabb</code> if <code>x</code> does not contain a component
named <code>"aa"</code> and <code>"aabb"</code> is the only name which has prefix
<code>"aa"</code>. For <code>[[</code>, partial matching can be controlled via the
<code>exact</code> argument which defaults to <code>NA</code> indicating that
partial matching is allowed, but should result in a warning when it
occurs. Setting <code>exact</code> to <code>TRUE</code> prevents partial matching
from occurring, a <code>FALSE</code> value allows it and does not issue any
warnings. Note that <code>[</code> always requires an exact match. The string
<code>""</code> is treated specially: it indicates ‘no name’ and matches no
element (not even those without a name). Note that partial matching is
only used when extracting and not when replacing.
</li><li> <strong>Factor</strong>. The result is identical to <code>x[as.integer(i)]</code>.
The factor levels are never used. If so desired, use
<code>x[as.character(i)]</code> or a similar construction.
</li><li> <strong>Empty</strong>. The expression <code>x[]</code> returns <code>x</code>, but drops
“irrelevant” attributes from the result. Only <code>names</code> and in
multi-dimensional arrays <code>dim</code> and <code>dimnames</code> attributes are
retained.
</li><li> <strong>NULL</strong>. This is treated as if it were <code>integer(0)</code>.
</li></ul>
<p>Indexing with a missing (i.e. <code>NA</code>) value gives an <code>NA</code>
result. This rule applies also to the case of logical indexing,
i.e. the elements of <code>x</code> that have an <code>NA</code> selector in
<code>i</code> get included in the result, but their value will be <code>NA</code>.
<a name="index-NA-1"></a>
</p>
<p>Notice however, that there are different modes of <code>NA</code>—the
literal constant is of mode <code>"logical"</code>, but it is frequently
automatically coerced to other types. One effect of this is that
<code>x[NA]</code> has the length of <code>x</code>, but <code>x[c(1, NA)]</code> has
length 2. That is because the rules for logical indices apply in the
former case, but those for integer indices in the latter.
</p>
<p>Indexing with <code>[</code> will also carry out the relevant subsetting of
any names attributes.
</p>
<hr>
<a name="Indexing-matrices-and-arrays"></a>
<div class="header">
<p>
Next: <a href="#Indexing-other-structures" accesskey="n" rel="next">Indexing other structures</a>, Previous: <a href="#Indexing-by-vectors" accesskey="p" rel="prev">Indexing by vectors</a>, Up: <a href="#Indexing" accesskey="u" rel="up">Indexing</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Indexing-matrices-and-arrays-1"></a>
<h4 class="subsection">3.4.2 Indexing matrices and arrays</h4>
<a name="index-index-4"></a>
<p>Subsetting multi-dimensional structures generally follows the same rules
as single-dimensional indexing for each index variable, with the
relevant component of <code>dimnames</code> taking the place of <code>names</code>.
A couple of special rules apply, though:
</p>
<p>Normally, a structure is accessed using the number of indices
corresponding to its dimension. It is however also possible to use a
single index in which case the <code>dim</code> and <code>dimnames</code> attributes
are disregarded and the result is effectively that of <code>c(m)[i]</code>.
Notice that <code>m[1]</code> is usually very different from <code>m[1, ]</code> or
<code>m[, 1]</code>.
</p>
<p>It is possible to use a matrix of integers as an index. In this case,
the number of columns of the matrix should match the number of
dimensions of the structure, and the result will be a vector with length
as the number of rows of the matrix. The following example shows how
to extract the elements <code>m[1, 1]</code> and <code>m[2, 2]</code> in one
operation.
</p>
<div class="example">
<pre class="example">> m <- matrix(1:4, 2)
> m
[,1] [,2]
[1,] 1 3
[2,] 2 4
> i <- matrix(c(1, 1, 2, 2), 2, byrow = TRUE)
> i
[,1] [,2]
[1,] 1 1
[2,] 2 2
> m[i]
[1] 1 4
</pre></div>
<p>Indexing matrices may not contain negative indices. <code>NA</code> and
zero values are allowed: rows in an index matrix containing a zero are
ignored, whereas rows containing an <code>NA</code> produce an <code>NA</code> in
the result.
</p>
<p>Both in the case of using a single
<a name="index-index-5"></a>
index and in matrix indexing, a <code>names</code> attribute is used if
present, as had the structure been one-dimensional.
</p>
<p>If an indexing operation causes the result to have one of its extents of
length one, as in selecting a single slice of a three-dimensional matrix
with (say) <code>m[2, , ]</code>, the corresponding dimension is generally
dropped from the result. If a single-dimensional structure results, a
vector is obtained. This is occasionally undesirable and can be turned
off by adding the ‘<samp>drop = FALSE</samp>’ to the indexing operation. Notice
that this is an additional argument to the <code>[</code> function and doesn’t
add to the index count. Hence the correct way of selecting the first
row of a matrix as a <em>1</em> by <em>n</em> matrix is <code>m[1, , drop =
FALSE]</code>. Forgetting to disable the dropping feature is a common cause
of failure in general subroutines where an index occasionally, but not
usually has length one. This rule still applies to a one-dimensional
array, where any subsetting will give a vector result unless ‘<samp>drop
= FALSE</samp>’ is used.
</p>
<p>Notice that vectors are distinct from one-dimensional arrays in that the
latter have <code>dim</code> and <code>dimnames</code> attributes (both of length
one). One-dimensional arrays are not easily obtained from subsetting
operations but they can be constructed explicitly and are returned by
<code>table</code>. This is sometimes useful because the elements of the
<code>dimnames</code> list may themselves be named, which is not the case for
the <code>names</code> attribute.
</p>
<p>Some operations such as <code>m[FALSE, ]</code> result in structures in which
a dimension has zero extent. R generally tries to handle these
structures sensibly.
</p>
<hr>
<a name="Indexing-other-structures"></a>
<div class="header">
<p>
Next: <a href="#Subset-assignment" accesskey="n" rel="next">Subset assignment</a>, Previous: <a href="#Indexing-matrices-and-arrays" accesskey="p" rel="prev">Indexing matrices and arrays</a>, Up: <a href="#Indexing" accesskey="u" rel="up">Indexing</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Indexing-other-structures-1"></a>
<h4 class="subsection">3.4.3 Indexing other structures</h4>
<p>The operator <code>[</code> is a generic function which allows class methods
to be added, and the <code>$</code> and <code>[[</code> operators likewise. Thus,
it is possible to have user-defined indexing operations for any
structure. Such a function, say <code>[.foo</code> is called with a set of
arguments of which the first is the structure being indexed and the rest
are the indices. In the case of <code>$</code>, the index argument is of mode
<code>"symbol"</code> even when using the <code>x$"abc"</code> form. It is
important to be aware that class methods do not necessarily behave in
the same way as the basic methods, for example with respect to partial
matching.
</p>
<p>The most important example of a class method for <code>[</code> is that used
for data frames. It is not described in detail here (see the help
page for <code>[.data.frame</code>), but in broad terms, if two indices are
supplied (even if one is empty) it creates matrix-like indexing for a
structure that is basically a list of vectors of the same length. If a
single index is supplied, it is interpreted as indexing the list of
columns—in that case the <code>drop</code> argument is ignored, with a
warning.
</p>
<p>The basic operators <code>$</code> and <code>[[</code> can be applied to
environments. Only character indices are allowed and no partial
matching is done.
</p>
<hr>
<a name="Subset-assignment"></a>
<div class="header">
<p>
Previous: <a href="#Indexing-other-structures" accesskey="p" rel="prev">Indexing other structures</a>, Up: <a href="#Indexing" accesskey="u" rel="up">Indexing</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Subset-assignment-1"></a>
<h4 class="subsection">3.4.4 Subset assignment</h4>
<a name="index-assignment-3"></a>
<a name="index-complex-assignment"></a>
<p>Assignment to subsets of a structure is a special case of a general
mechanism for complex assignment:
</p><div class="example">
<pre class="example">x[3:5] <- 13:15
</pre></div>
<p>The result of this command is as if the following had been executed
</p><div class="example">
<pre class="example">`*tmp*` <- x
x <- "[<-"(`*tmp*`, 3:5, value=13:15)
rm(`*tmp*`)
</pre></div>
<p>Note that the index is first converted to a numeric index and then the
elements are replaced sequentially along the numeric index, as if a
<code>for</code> loop had been used. Any existing variable called
<code>`*tmp*`</code> will be overwritten and deleted, and this variable name
should not be used in code.
</p>
<p>The same mechanism can be applied to functions other than <code>[</code>. The
replacement function has the same name with <code><-</code> pasted on. Its last
argument, which must be called <code>value</code>, is the new value to be
assigned. For example,
</p><div class="example">
<pre class="example">names(x) <- c("a","b")
</pre></div>
<p>is equivalent to
</p><div class="example">
<pre class="example">`*tmp*` <- x
x <- "names<-"(`*tmp*`, value=c("a","b"))
rm(`*tmp*`)
</pre></div>
<p>Nesting of complex assignments is evaluated recursively
</p><div class="example">
<pre class="example">names(x)[3] <- "Three"
</pre></div>
<p>is equivalent to
</p><div class="example">
<pre class="example">`*tmp*` <- x
x <- "names<-"(`*tmp*`, value="[<-"(names(`*tmp*`), 3, value="Three"))
rm(`*tmp*`)
</pre></div>
<p>Complex assignments in the enclosing environment (using <code><<-</code>) are
also permitted:
</p><div class="example">
<pre class="example">names(x)[3] <<- "Three"
</pre></div>
<p>is equivalent to
</p><div class="example">
<pre class="example">`*tmp*` <<- get(x, envir=parent.env(), inherits=TRUE)
names(`*tmp*`)[3] <- "Three"
x <<- `*tmp*`
rm(`*tmp*`)
</pre></div>
<p>and also to
</p><div class="example">
<pre class="example">`*tmp*` <- get(x,envir=parent.env(), inherits=TRUE)
x <<- "names<-"(`*tmp*`, value="[<-"(names(`*tmp*`), 3, value="Three"))
rm(`*tmp*`)
</pre></div>
<p>Only the target variable is evaluated in the enclosing environment, so
</p><div class="example">
<pre class="example">e<-c(a=1,b=2)
i<-1
local({
e <- c(A=10,B=11)
i <-2
e[i] <<- e[i]+1
})
</pre></div>
<p>uses the local value of <code>i</code> on both the LHS and RHS, and the local
value of <code>e</code> on the RHS of the superassignment statement. It sets
<code>e</code> in the outer environment to
</p><div class="example">
<pre class="example"> a b
1 12
</pre></div>
<p>That is, the superassignment is equivalent to the four lines
</p><div class="example">
<pre class="example">`*tmp*` <- get(e, envir=parent.env(), inherits=TRUE)
`*tmp*`[i] <- e[i]+1
e <<- `*tmp*`
rm(`*tmp*`)
</pre></div>
<p>Similarly
</p><div class="example">
<pre class="example">x[is.na(x)] <<- 0
</pre></div>
<p>is equivalent to
</p><div class="example">
<pre class="example">`*tmp*` <- get(x,envir=parent.env(), inherits=TRUE)
`*tmp*`[is.na(x)] <- 0
x <<- `*tmp*`
rm(`*tmp*`)
</pre></div>
<p>and not to
</p><div class="example">
<pre class="example">`*tmp*` <- get(x,envir=parent.env(), inherits=TRUE)
`*tmp*`[is.na(`*tmp*`)] <- 0
x <<- `*tmp*`
rm(`*tmp*`)
</pre></div>
<p>These two candidate interpretations differ only if there is also a
local variable <code>x</code>. It is a good idea to avoid having a local
variable with the same name as the target variable of a
superassignment. As this case was handled incorrectly in versions
1.9.1 and earlier there must not be a serious need for such code.
</p>
<hr>
<a name="Scope-of-variables"></a>
<div class="header">
<p>
Previous: <a href="#Indexing" accesskey="p" rel="prev">Indexing</a>, Up: <a href="#Evaluation-of-expressions" accesskey="u" rel="up">Evaluation of expressions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Scope-of-variables-1"></a>
<h3 class="section">3.5 Scope of variables</h3>
<a name="index-scope"></a>
<a name="index-name-4"></a>
<p>Almost every programming language has a set of scoping rules, allowing
the same name to be used for different objects. This allows, e.g., a
local variable in a function to have the same name as a global object.
</p>
<p>R uses a <em>lexical scoping</em> model, similar to languages like
Pascal. However, R is a <em>functional programming language</em> and
allows dynamic creation and manipulation of functions and language
objects, and has additional features reflecting this fact.
</p>
<table summary="" class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">• <a href="#Global-environment" accesskey="1">Global environment</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Lexical-environment" accesskey="2">Lexical environment</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Stacks" accesskey="3">Stacks</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Search-path" accesskey="4">Search path</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="Global-environment"></a>
<div class="header">
<p>
Next: <a href="#Lexical-environment" accesskey="n" rel="next">Lexical environment</a>, Previous: <a href="#Scope-of-variables" accesskey="p" rel="prev">Scope of variables</a>, Up: <a href="#Scope-of-variables" accesskey="u" rel="up">Scope of variables</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Global-environment-1"></a>
<h4 class="subsection">3.5.1 Global environment</h4>
<p>The global
<a name="index-environment-5"></a>
environment is the root of the user workspace. An
<a name="index-assignment-4"></a>
assignment operation from the command line will cause the relevant
object to belong to the global environment. Its enclosing environment
is the next environment on the search path, and so on back to the
empty environment that is the enclosure of the base environment.
</p>
<hr>
<a name="Lexical-environment"></a>
<div class="header">
<p>
Next: <a href="#Stacks" accesskey="n" rel="next">Stacks</a>, Previous: <a href="#Global-environment" accesskey="p" rel="prev">Global environment</a>, Up: <a href="#Scope-of-variables" accesskey="u" rel="up">Scope of variables</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Lexical-environment-1"></a>
<h4 class="subsection">3.5.2 Lexical environment</h4>
<p>Every call to a
<a name="index-function-8"></a>
function creates a
<a name="index-frame"></a>
<a name="index-environment-6"></a>
<em>frame</em> which contains the local
variables created in the function, and is evaluated in an environment,
which in combination creates a new environment.
</p>
<p>Notice the terminology: A frame is a set of variables, an environment is
a nesting of frames (or equivalently: the innermost frame plus the
enclosing environment).
</p>
<p>Environments may be assigned to variables or be contained in other
objects. However, notice that they are not standard objects—in
particular, they are not copied on assignment.
</p>
<p>A closure (mode <code>"function"</code>) object will contain the environment
in which it is created as part of its definition (By default. The
environment can be manipulated using <code>environment<-</code>). When the
function is subsequently called, its
<a name="index-environment_002c-evaluation"></a>
evaluation environment is created with the closure’s environment as
enclosure. Notice that this is not
necessarily the environment of the caller!
</p>
<p>Thus, when a variable is requested inside a
<a name="index-function-9"></a>
function, it is first sought
in the
<a name="index-environment_002c-evaluation-1"></a>
evaluation environment, then in the enclosure, the enclosure of
the enclosure, etc.; once the global environment or the environment of
a package is reached, the
search continues up the search path
to the environment of the base package. If the variable is not
found there, the search will proceed next to the empty environment, and
will fail.
</p>
<hr>
<a name="Stacks"></a>
<div class="header">
<p>
Next: <a href="#Search-path" accesskey="n" rel="next">Search path</a>, Previous: <a href="#Lexical-environment" accesskey="p" rel="prev">Lexical environment</a>, Up: <a href="#Scope-of-variables" accesskey="u" rel="up">Scope of variables</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="The-call-stack"></a>
<h4 class="subsection">3.5.3 The call stack</h4>
<p>Every time a
<a name="index-function-10"></a>
function is invoked a new evaluation frame is created. At
any point in time during the computation the currently active
environments are accessible through the <em>call stack</em>. Each time a
function is invoked a special construct called a context is created
internally and is placed on a list of contexts. When a function has
finished evaluating its context is removed from the call stack.
</p>
<p>Making variables defined higher up the call stack available is called
<a name="index-scope-1"></a>
dynamic scope. The binding for a variable is then determined by the most
recent (in time) definition of the variable. This contradicts the
default scoping rules in R, which use the bindings in the
<a name="index-environment-7"></a>
environment
in which the function was defined (lexical scope). Some functions,
particularly those that use and manipulate model formulas, need to
simulate dynamic scope by directly accessing the call stack.
</p>
<p>Access to the
<a name="index-call-stack"></a>
call stack is provided through a family of functions which
have names that start with ‘<samp>sys.</samp>’. They are listed briefly below.
</p>
<a name="index-evaluation"></a>
<dl compact="compact">
<dt><code>sys.call</code></dt>
<dd><p>Get the call for the specified context.
</p></dd>
<dt><code>sys.frame</code></dt>
<dd><p>Get the evaluation frame for the specified context.
</p></dd>
<dt><code>sys.nframe</code></dt>
<dd><p>Get the environment frame for all active contexts.
</p></dd>
<dt><code>sys.function</code></dt>
<dd><p>Get the function being invoked in the specified context.
</p></dd>
<dt><code>sys.parent</code></dt>
<dd><p>Get the parent of the current function invocation.
</p></dd>
<dt><code>sys.calls</code></dt>
<dd><p>Get the calls for all the active contexts.
</p></dd>
<dt><code>sys.frames</code></dt>
<dd><p>Get the evaluation frames for all the active contexts.
</p></dd>
<dt><code>sys.parents</code></dt>
<dd><p>Get the numeric labels for all active contexts.
</p></dd>
<dt><code>sys.on.exit</code></dt>
<dd><p>Set a function to be executed when the specified context is exited.
</p></dd>
<dt><code>sys.status</code></dt>
<dd><p>Calls <code>sys.frames</code>, <code>sys.parents</code> and <code>sys.calls</code>.
</p></dd>
<dt><code>parent.frame</code></dt>
<dd><p>Get the evaluation frame for the specified parent context.
</p></dd>
</dl>
<hr>
<a name="Search-path"></a>
<div class="header">
<p>
Previous: <a href="#Stacks" accesskey="p" rel="prev">Stacks</a>, Up: <a href="#Scope-of-variables" accesskey="u" rel="up">Scope of variables</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Search-path-1"></a>
<h4 class="subsection">3.5.4 Search path</h4>
<p>In addition to the evaluation
<a name="index-environment-8"></a>
<a name="index-search-path"></a>
environment structure, R has a search
path of environments which are searched for variables not found
elsewhere. This is used for two things: packages of functions and
attached user data.
</p>
<p>The first element of the search path is the global environment and the
last is the base package. An <code>Autoloads</code> environment is used for
holding proxy objects that may be loaded on demand. Other environments
are inserted in the path using <code>attach</code> or <code>library</code>.
</p>
<a name="index-namespace"></a>
<p>Packages which have a <em>namespace</em> have a different search path.
When a search for an R object is started from an object in such a
package, the package itself is searched first, then its imports, then
the base namespace and finally the global environment and the rest of the
regular search path. The effect is that references to other objects in
the same package will be resolved to the package, and objects cannot be
masked by objects of the same name in the global environment or in other
packages.
</p>
<hr>
<a name="Functions"></a>
<div class="header">
<p>
Next: <a href="#Object_002doriented-programming" accesskey="n" rel="next">Object-oriented programming</a>, Previous: <a href="#Evaluation-of-expressions" accesskey="p" rel="prev">Evaluation of expressions</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Functions-1"></a>
<h2 class="chapter">4 Functions</h2>
<table summary="" class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">• <a href="#Writing-functions" accesskey="1">Writing functions</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Functions-as-objects" accesskey="2">Functions as objects</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Evaluation" accesskey="3">Evaluation</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="Writing-functions"></a>
<div class="header">
<p>
Next: <a href="#Functions-as-objects" accesskey="n" rel="next">Functions as objects</a>, Previous: <a href="#Functions" accesskey="p" rel="prev">Functions</a>, Up: <a href="#Functions" accesskey="u" rel="up">Functions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Writing-functions-1"></a>
<h3 class="section">4.1 Writing functions</h3>
<p>While R can be very useful as a data analysis tool most users very
quickly find themselves wanting to write their own
<a name="index-function-11"></a>
functions. This is
one of the real advantages of R. Users can program it and they can,
if they want to, change the system level functions to functions that
they find more appropriate.
</p>
<p>R also provides facilities that make it easy to document any
functions that you have created. See <a href="http://cran.r-project.org/doc/manuals/R-exts.html#Writing-R-documentation">Writing R documentation</a> in <cite>Writing R Extensions</cite>.
</p>
<table summary="" class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">• <a href="#Syntax-and-examples" accesskey="1">Syntax and examples</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Arguments" accesskey="2">Arguments</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="Syntax-and-examples"></a>
<div class="header">
<p>
Next: <a href="#Arguments" accesskey="n" rel="next">Arguments</a>, Previous: <a href="#Writing-functions" accesskey="p" rel="prev">Writing functions</a>, Up: <a href="#Writing-functions" accesskey="u" rel="up">Writing functions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Syntax-and-examples-1"></a>
<h4 class="subsection">4.1.1 Syntax and examples</h4>
<p>The syntax for writing a
<a name="index-function-12"></a>
function is
</p>
<div class="example">
<pre class="example">function ( <var>arglist</var> ) <var>body</var>
</pre></div>
<p>The first component of the function declaration is the keyword
<code>function</code> which indicates to R that you want to create a
function.
</p>
<p>An
<a name="index-argument-1"></a>
argument list is a comma separated list of formal arguments. A
formal argument can be a symbol, a statement of the form
‘<samp><var>symbol</var> = <var>expression</var></samp>’, or the special formal argument
‘<samp>...</samp>’.
</p>
<p>The <em>body</em> can be any valid R expression. Generally, the body
is a group of expressions contained in curly braces (‘<samp>{</samp>’ and
‘<samp>}</samp>’).
</p>
<p>Generally
<a name="index-function-13"></a>
functions are assigned to symbols but they don’t need to be.
The value returned by the call to <code>function</code> is a function. If
this is not given a name it is referred to as an
<a name="index-function_002c-anonymous"></a>
anonymous
function. Anonymous functions are most frequently used as arguments to
other functions such as the <code>apply</code> family or <code>outer</code>.
</p>
<p>Here is a simple function: <code>echo <- function(x) print(x)</code>. So
<code>echo</code> is a function that takes a single argument and when
<code>echo</code> is invoked it prints its argument.
</p>
<hr>
<a name="Arguments"></a>
<div class="header">
<p>
Previous: <a href="#Syntax-and-examples" accesskey="p" rel="prev">Syntax and examples</a>, Up: <a href="#Writing-functions" accesskey="u" rel="up">Writing functions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Arguments-1"></a>
<h4 class="subsection">4.1.2 Arguments</h4>
<p>The formal arguments to the function define the variables whose values
will be supplied at the time the function is invoked. The names of
these arguments can be used within the function body where they obtain
the value supplied at the time of function invocation.
</p>
<a name="index-argument_002c-default-values"></a>
<p>Default values for arguments can be specified using the special form
‘<samp><var>name</var> = <var>expression</var></samp>’. In this case, if the user does
not specify a value for the argument when the function is invoked the
expression will be associated with the corresponding symbol. When a
value is needed the <var>expression</var> is
<a name="index-evaluation_002c-expression-2"></a>
evaluated in the evaluation
frame of the function.
</p>
<p>Default behaviours can also be specified by using the function
<code>missing</code>. When <code>missing</code> is called with the
<a name="index-name-5"></a>
name of a formal
argument it returns <code>TRUE</code> if the formal argument was not matched
with any actual argument and has not been subsequently modified in the
body of the function. An argument that is <code>missing</code> will thus
have its default value, if any. The <code>missing</code> function does not
force evaluation of the argument.
</p>
<p>The special type of argument ‘<samp>...</samp>’ can contain any number of
supplied arguments. It is used for a variety of purposes. It allows
you to write a
<a name="index-function-14"></a>
function that takes an arbitrary number of arguments. It
can be used to absorb some arguments into an intermediate function which
can then be extracted by functions called subsequently.
</p>
<hr>
<a name="Functions-as-objects"></a>
<div class="header">
<p>
Next: <a href="#Evaluation" accesskey="n" rel="next">Evaluation</a>, Previous: <a href="#Writing-functions" accesskey="p" rel="prev">Writing functions</a>, Up: <a href="#Functions" accesskey="u" rel="up">Functions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Functions-as-objects-1"></a>
<h3 class="section">4.2 Functions as objects</h3>
<p>Functions are first class objects in R. They can be used anywhere
that an R object is required. In particular they can be passed as
arguments to functions and returned as values from functions. See
<a href="#Function-objects">Function objects</a> for the details.
</p>
<hr>
<a name="Evaluation"></a>
<div class="header">
<p>
Previous: <a href="#Functions-as-objects" accesskey="p" rel="prev">Functions as objects</a>, Up: <a href="#Functions" accesskey="u" rel="up">Functions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Evaluation-1"></a>
<h3 class="section">4.3 Evaluation</h3>
<table summary="" class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">• <a href="#Evaluation-environment" accesskey="1">Evaluation environment</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Argument-matching" accesskey="2">Argument matching</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Argument-evaluation" accesskey="3">Argument evaluation</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Scope" accesskey="4">Scope</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="Evaluation-environment"></a>
<div class="header">
<p>
Next: <a href="#Argument-matching" accesskey="n" rel="next">Argument matching</a>, Previous: <a href="#Evaluation" accesskey="p" rel="prev">Evaluation</a>, Up: <a href="#Evaluation" accesskey="u" rel="up">Evaluation</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Evaluation-environment-1"></a>
<h4 class="subsection">4.3.1 Evaluation environment</h4>
<p>When a
<a name="index-function-15"></a>
function is called or invoked a new
<a name="index-evaluation-1"></a>
evaluation frame is created.
In this frame the formal arguments are matched with the supplied
arguments according to the rules given in <a href="#Argument-matching">Argument matching</a>. The
statements in the body of the function are evaluated sequentially in
this
<a name="index-environment-9"></a>
environment frame.
</p>
<p>The enclosing frame of the evaluation frame is the environment frame
associated with the function being invoked. This may be different from
S. While many functions have <code>.GlobalEnv</code> as their environment
this does not have to be true and functions defined in packages with
namespaces (normally) have the package namespace as their environment.
</p>
<hr>
<a name="Argument-matching"></a>
<div class="header">
<p>
Next: <a href="#Argument-evaluation" accesskey="n" rel="next">Argument evaluation</a>, Previous: <a href="#Evaluation-environment" accesskey="p" rel="prev">Evaluation environment</a>, Up: <a href="#Evaluation" accesskey="u" rel="up">Evaluation</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Argument-matching-1"></a>
<h4 class="subsection">4.3.2 Argument matching</h4>
<p>This subsection applies to closures but not to primitive functions. The
latter typically ignore tags and do positional matching, but their help
pages should be consulted for exceptions, which include <code>log</code>,
<code>round</code>, <code>signif</code>, <code>rep</code> and <code>seq.int</code>.
</p>
<p>The first thing that occurs in a
<a name="index-function-16"></a>
function evaluation is the matching of
formal to the actual or supplied arguments.
This is done by a three-pass process:
</p>
<ol>
<li> <strong>Exact matching on tags</strong>.
<a name="index-name-6"></a>
For each named supplied argument the list of formal arguments is
searched for an item whose name matches exactly. It is an error to have
the same formal argument match several actuals or vice versa.
</li><li> <strong>Partial matching on tags</strong>.
Each remaining named supplied argument is compared to the remaining formal
arguments using partial matching. If the name of the supplied argument
matches exactly with the first part of a formal argument then the two
arguments are considered to be matched. It is an error to have multiple
partial matches. Notice that if <code>f <- function(fumble,
fooey) fbody</code>, then <code>f(f = 1, fo = 2)</code> is illegal, even though the
2nd actual argument only matches <code>fooey</code>. <code>f(f = 1, fooey =
2)</code> <em>is</em> legal though since the second argument matches exactly and
is removed from consideration for partial matching. If the formal
arguments contain ‘<samp>...</samp>’ then partial matching is only applied to
arguments that precede it.
</li><li> <strong>Positional matching</strong>.
Any unmatched formal arguments are bound to <em>unnamed</em> supplied
arguments, in order. If there is a ‘<samp>...</samp>’ argument, it will take up
the remaining arguments, tagged or not.
</li></ol>
<p>If any arguments remain unmatched an error is declared.
</p>
<p>Argument matching is augmented by the functions <code>match.arg</code>,
<code>match.call</code> and <code>match.fun</code>.
<a name="index-match_002earg"></a>
<a name="index-match_002ecall"></a>
<a name="index-match_002efun"></a>
Access to the partial matching algorithm used by R is via
<code>pmatch</code>.
</p>
<hr>
<a name="Argument-evaluation"></a>
<div class="header">
<p>
Next: <a href="#Scope" accesskey="n" rel="next">Scope</a>, Previous: <a href="#Argument-matching" accesskey="p" rel="prev">Argument matching</a>, Up: <a href="#Evaluation" accesskey="u" rel="up">Evaluation</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Argument-evaluation-1"></a>
<h4 class="subsection">4.3.3 Argument evaluation</h4>
<p>One of the most important things to know about the
<a name="index-evaluation_002c-argument"></a>
evaluation of
arguments to a
<a name="index-function-17"></a>
function is that supplied arguments and default arguments
are treated differently. The supplied arguments to a function are
evaluated in the evaluation frame of the calling function. The default
arguments to a function are evaluated in the evaluation frame of the
function.
</p>
<p>The semantics of invoking a function in R argument are
<em>call-by-value</em>. In general, supplied arguments behave as if they
are local variables initialized with the value supplied and the
<a name="index-name-7"></a>
name of
the corresponding formal argument. Changing the value of a supplied
argument within a function will not affect the value of the variable in
the calling frame.
</p>
<p>R has a form of lazy evaluation of function arguments. Arguments are
not evaluated until needed. It is important to realize that in some
cases the argument will never be evaluated. Thus, it is bad style to
use arguments to functions to cause side-effects. While in <strong>C</strong> it is
common to use the form, <code>foo(x = y)</code> to invoke <code>foo</code> with the
value of <code>y</code> and simultaneously to assign the value of <code>y</code> to
<code>x</code> this same style should not be used in R. There is no
guarantee that the argument will ever be evaluated and hence the
<a name="index-assignment-5"></a>
assignment may not take place.
</p>
<p>It is also worth noting that the effect of <code>foo(x <- y)</code> if the
argument is evaluated is to change the value of <code>x</code> in the calling
<a name="index-environment-10"></a>
environment and not in the
<a name="index-environment_002c-evaluation-2"></a>
evaluation environment of <code>foo</code>.
</p>
<p>It is possible to access the actual (not default) expressions used as
arguments inside the function. The mechanism is implemented via
promises. When a
<a name="index-function-18"></a>
function is being evaluated the actual expression used as an argument is
stored in the promise together with a pointer to the environment the
function was called from. When (if) the argument is evaluated the
stored expression is evaluated in the environment that the function was
called from. Since only a pointer to the environment is used any
changes made to that environment will be in effect during this
evaluation. The resulting value is then also stored in a separate spot
in the promise. Subsequent evaluations retrieve this stored value (a
second evaluation is not carried out). Access to the unevaluated
expression is also available using <code>substitute</code>.
</p>
<p>When a
<a name="index-function-19"></a>
function is called, each formal argument is assigned a promise in the
local environment of the call with the expression slot containing the
actual argument (if it exists) and the environment slot containing the
environment of the caller. If no actual argument for a formal argument
is given in the call and there is a default expression, it is similarly
assigned to the expression slot of the formal argument, but with the
<a name="index-environment-11"></a>
environment set
to the local environment.
</p>
<p>The process of filling the value slot of a promise by
<a name="index-evaluation-2"></a>
evaluating the
contents of the expression slot in the promise’s environment is called
<em>forcing</em> the promise. A promise will only be forced once, the
value slot content being used directly later on.
</p>
<p>A promise is forced when its value is needed. This usually happens
inside internal
<a name="index-function-20"></a>
<a name="index-function_002c-internal"></a>
functions, but a promise can also be forced by direct evaluation of the
promise itself. This is occasionally useful when a default expression
depends on the value of another formal argument or other variable in the
local environment. This is seen in the following example where the lone
<code>label</code> ensures that the label is based on the value of <code>x</code>
before it is changed in the next line.
</p>
<div class="example">
<pre class="example">function(x, label = deparse(x)) {
label
x <- x + 1
print(label)
}
</pre></div>
<p>The expression slot of a promise can itself involve other promises.
This happens whenever an unevaluated argument is passed as an argument
to another function. When forcing a promise, other promises in its
expression will also be forced recursively as they are evaluated.
</p>
<hr>
<a name="Scope"></a>
<div class="header">
<p>
Previous: <a href="#Argument-evaluation" accesskey="p" rel="prev">Argument evaluation</a>, Up: <a href="#Evaluation" accesskey="u" rel="up">Evaluation</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Scope-1"></a>
<h4 class="subsection">4.3.4 Scope</h4>
<a name="index-scope-2"></a>
<p>Scope or the scoping rules are simply the set of rules used by the
<a name="index-evaluation_002c-symbol-2"></a>
evaluator to find a value for a
<a name="index-symbol-3"></a>
symbol. Every computer language has a
set of such rules. In R the rules are fairly simple but there do
exist mechanisms for subverting the usual, or default rules.
</p>
<p>R adheres to a set of rules that are called <em>lexical scope</em>.
This means the variable
<a name="index-binding"></a>
bindings in effect at the time the expression
was created are used to provide values for any unbound symbols in the
expression.
</p>
<p>Most of the interesting properties of
<a name="index-scope-3"></a>
scope are involved with evaluating
<a name="index-function-21"></a>
functions and we concentrate on this issue. A symbol can be either
<a name="index-binding-1"></a>
bound or unbound. All of the formal arguments to a function provide
bound symbols in the body of the function. Any other symbols in the
body of the function are either local variables or unbound variables. A
local variable is one that is defined within the function. Because R
has no formal definition of variables, they are simply used as needed,
it can be difficult to determine whether a variable is local or not.
Local variables must first be defined, this is typically done by having
them on the left-hand side of an
<a name="index-assignment-6"></a>
assignment.
</p>
<p>During the evaluation process if an unbound symbol is detected then R
attempts to find a value for it. The scoping rules determine how this
process proceeds. In R the
<a name="index-environment-12"></a>
environment of the function is searched
first, then its enclosure and so on until the global environment is reached.
</p>
<p>The global environment heads a search list of environments that are searched
sequentially for a matching symbol. The value of the first match is then used.
</p>
<p>When this set of rules is combined with the fact that
<a name="index-function-22"></a>
functions can be
returned as values from other functions then some rather nice, but at
first glance peculiar, properties obtain.
</p>
<p>A simple example:
</p>
<div class="example">
<pre class="example">f <- function() {
y <- 10
g <- function(x) x + y
return(g)
}
h <- f()
h(3)
</pre></div>
<a name="index-evaluation-3"></a>
<p>A rather interesting question is what happens when <code>h</code> is
evaluated. To describe this we need a bit more notation. Within a
<a name="index-function-23"></a>
function body variables can be bound, local or unbound. The bound
variables are those that match the formal arguments to the function.
The local variables are those that were created or defined within the
function body. The unbound variables are those that are neither local
nor bound. When a function body is evaluated there is no problem
determining values for local variables or for bound variables. Scoping
rules determine how the language will find values for the unbound
variables.
</p>
<p>When <code>h(3)</code> is evaluated we see that its body is that of
<code>g</code>. Within that body <code>x</code> is bound to the formal argument
and <code>y</code> is unbound. In a language with
<a name="index-scope-4"></a>
lexical scope <code>x</code> will be associated with the value 3 and
<code>y</code> with the value 10 local to <code>f</code> so <code>h(3)</code> should return the value 13.
In R this is indeed what happens.
</p>
<p>In S, because of the different scoping rules one will get an error
indicating that <code>y</code> is not found, unless there is a variable
<code>y</code> in your workspace in which case its value will be used.
</p>
<hr>
<a name="Object_002doriented-programming"></a>
<div class="header">
<p>
Next: <a href="#Computing-on-the-language" accesskey="n" rel="next">Computing on the language</a>, Previous: <a href="#Functions" accesskey="p" rel="prev">Functions</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Object_002doriented-programming-1"></a>
<h2 class="chapter">5 Object-oriented programming</h2>
<a name="index-object_002doriented"></a>
<p>Object-oriented programming is a style of programming that has become
popular in recent years. Much of the popularity comes from the fact
that it makes it easier to write and maintain complicated systems. It
does this through several different mechanisms.
</p>
<p>Central to any object-oriented language are the concepts of class and of
methods. A <em>class</em> is a definition of an object. Typically a
class contains several <em>slots</em> that are used to hold class-specific
information. An object in the language must be an instance of some
class. Programming is based on objects or instances of classes.
</p>
<p>Computations are carried out via <em>methods</em>. Methods are basically
<a name="index-function-24"></a>
functions that are specialized to carry out specific calculations on
objects, usually of a specific class. This is what makes the language
object oriented. In R, <em>generic functions</em> are used to
determine the appropriate method. The generic function is responsible
for determining the class of its argument(s) and uses that information
to select the appropriate method.
</p>
<p>Another feature of most object-oriented languages is the concept of
inheritance. In most programming problems there are usually many
objects that are related to one another. The programming is
considerably simplified if some components can be reused.
</p>
<p>If a class inherits from another class then generally it gets all the
slots in the parent class and can extend it by adding new slots. On
method dispatching (via the generic functions) if a method for the class
does not exist then a method for the parent is sought.
</p>
<p>In this chapter we discuss how this general strategy has been
implemented in R and discuss some of the limitations within the
current design. One of the advantages that most object systems impart
is greater consistency. This is achieved via the rules that are checked
by the compiler or interpreter. Unfortunately because of the way that
the object system is incorporated into R this advantage does not
obtain. Users are cautioned to use the object system in a
straightforward manner. While it is possible to perform some rather
interesting feats these tend to lead to obfuscated code and may depend
on implementation details that will not be carried forward.
</p>
<p>The greatest use of object oriented programming in R is through
<code>print</code> methods, <code>summary</code> methods and <code>plot</code> methods.
These methods allow us to have one generic
<a name="index-function_002c-generic"></a>
function call, <code>plot</code>
say, that dispatches on the type of its argument and calls a plotting
function that is specific to the data supplied.
</p>
<p>In order to make the concepts clear we will consider the implementation
of a small system designed to teach students about probability. In this
system the objects are probability functions and the methods we will
consider are methods for finding moments and for plotting.
Probabilities can always be represented in terms of the cumulative
distribution function but can often be represented in other ways. For
example as a density, when it exists or as a moment generating function
when it exists.
</p>
<table summary="" class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">• <a href="#Definition" accesskey="1">Definition</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Inheritance" accesskey="2">Inheritance</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Method-dispatching" accesskey="3">Method dispatching</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#UseMethod" accesskey="4">UseMethod</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#NextMethod" accesskey="5">NextMethod</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Group-methods" accesskey="6">Group methods</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Writing-methods" accesskey="7">Writing methods</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="Definition"></a>
<div class="header">
<p>
Next: <a href="#Inheritance" accesskey="n" rel="next">Inheritance</a>, Previous: <a href="#Object_002doriented-programming" accesskey="p" rel="prev">Object-oriented programming</a>, Up: <a href="#Object_002doriented-programming" accesskey="u" rel="up">Object-oriented programming</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Definition-1"></a>
<h3 class="section">5.1 Definition</h3>
<p>Rather than having a full-fledged
<a name="index-object_002doriented-1"></a>
object-oriented system R has a
class system and a mechanism for dispatching based on the class of an
object. The dispatch mechanism for interpreted code relies on four
special objects that are stored in the evaluation frame. These special
objects are <code>.Generic</code>, <code>.Class</code>, <code>.Method</code> and
<code>.Group</code>. There is a separate dispatch mechanism used for internal
functions and types that will be discussed elsewhere.
</p>
<p>The class system is facilitated through the <code>class</code> attribute.
This attribute is a character vector of class names. So to create an
object of class <code>"foo"</code> one simply attaches a class attribute with
the string ‘<samp>"foo"</samp>’ in it. Thus, virtually anything can be turned
in to an object of class <code>"foo"</code>.
</p>
<p>The object system makes use of
<a name="index-function_002c-generic-1"></a>
<em>generic functions</em> via two
dispatching functions, <code>UseMethod</code> and <code>NextMethod</code>. The
typical use of the object system is to begin by calling a generic
function. This is typically a very simple function and consists of a
single line of code. The system function <code>mean</code> is just such a
function,
</p>
<div class="example">
<pre class="example">> mean
function (x, ...)
UseMethod("mean")
</pre></div>
<p>When <code>mean</code> is called it can have any number of arguments but its
first argument is special and the class of that first argument is used
to determine which method should be called. The variable <code>.Class</code>
is set to the class attribute of <code>x</code>, <code>.Generic</code> is set to the
string <code>"mean"</code> and a search is made for the correct method to
invoke. The class attributes of any other arguments to <code>mean</code> are
ignored.
</p>
<p>Suppose that <code>x</code> had a class attribute that contained <code>"foo"</code>
and <code>"bar"</code>, in that order. Then R would first search for a
function called <code>mean.foo</code> and if it did not find one it would then
search for a function <code>mean.bar</code> and if that search was also
unsuccessful then a final search for <code>mean.default</code> would be made.
If the last search is unsuccessful R reports an error. It is a good
idea to always write a default method. Note that the functions
<code>mean.foo</code> etc. are referred to, in this context, as methods.
</p>
<p><code>NextMethod</code> provides another mechanism for dispatching. A
<a name="index-function-25"></a>
function may have a call to <code>NextMethod</code> anywhere in it. The
determination of which method should then be invoked is based primarily
on the current values of <code>.Class</code> and <code>.Generic</code>. This is
somewhat problematic since the method is really an ordinary function and
users may call it directly. If they do so then there will be no values
for <code>.Generic</code> or <code>.Class</code>.
</p>
<p>If a method is invoked directly and it contains a call to
<code>NextMethod</code> then the first argument to <code>NextMethod</code> is used
to determine the
<a name="index-function_002c-generic-2"></a>
generic function. An error is signalled if this
argument has not been supplied; it is therefore a good idea to always
supply this argument.
</p>
<p>In the case that a method is invoked directly the class attribute of the
first argument to the method is used as the value of <code>.Class</code>.
</p>
<p>Methods themselves employ <code>NextMethod</code> to provide a form of
inheritance. Commonly a specific method performs a few operations to
set up the data and then it calls the next appropriate method through a
call to <code>NextMethod</code>.
</p>
<p>Consider the following simple example. A point in two-dimensional
Euclidean space can be specified by its Cartesian (x-y) or polar
(r-theta) coordinates. Hence, to store information about the location
of the point, we could define two classes, <code>"xypoint"</code> and
<code>"rthetapoint"</code>. All the ‘xypoint’ data structures are lists with
an x-component and a y-component. All ‘rthetapoint’ objects are lists
with an r-component and a theta-component.
</p>
<p>Now, suppose we want to get the x-position from either type of object.
This can easily be achieved through
<a name="index-function_002c-generic-3"></a>
generic functions. We define the
generic function <code>xpos</code> as follows.
</p>
<div class="example">
<pre class="example">xpos <- function(x, ...)
UseMethod("xpos")
</pre></div>
<p>Now we can define methods:
</p>
<div class="example">
<pre class="example">xpos.xypoint <- function(x) x$x
xpos.rthetapoint <- function(x) x$r * cos(x$theta)
</pre></div>
<p>The user simply calls the function <code>xpos</code> with either
representation as the argument. The internal dispatching method finds
the class of the object and calls the appropriate methods.
</p>
<p>It is pretty easy to add other representations. One need not write a
new generic function only the methods. This makes it easy to add to
existing systems since the user is only responsible for dealing with the
new representation and not with any of the existing representations.
</p>
<p>The bulk of the uses of this methodology are to provide specialized
printing for objects of different types; there are about 40 methods for
<code>print</code>.
</p>
<hr>
<a name="Inheritance"></a>
<div class="header">
<p>
Next: <a href="#Method-dispatching" accesskey="n" rel="next">Method dispatching</a>, Previous: <a href="#Definition" accesskey="p" rel="prev">Definition</a>, Up: <a href="#Object_002doriented-programming" accesskey="u" rel="up">Object-oriented programming</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Inheritance-1"></a>
<h3 class="section">5.2 Inheritance</h3>
<a name="index-evaluation-4"></a>
<p>The class attribute of an object can have several elements. When a
<a name="index-function_002c-generic-4"></a>
generic function is called the first inheritance is mainly handled
through <code>NextMethod</code>. <code>NextMethod</code> determines the method
currently being evaluated, finds the next class from th
</p>
<p>FIXME: something is missing here
</p>
<hr>
<a name="Method-dispatching"></a>
<div class="header">
<p>
Next: <a href="#UseMethod" accesskey="n" rel="next">UseMethod</a>, Previous: <a href="#Inheritance" accesskey="p" rel="prev">Inheritance</a>, Up: <a href="#Object_002doriented-programming" accesskey="u" rel="up">Object-oriented programming</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Method-dispatching-1"></a>
<h3 class="section">5.3 Method dispatching</h3>
<a name="index-function_002c-generic-5"></a>
<p>Generic functions should consist of a single statement. They should
usually be of the form <code>foo <- function(x, ...) UseMethod("foo",
x)</code>. When <code>UseMethod</code> is called, it determines the appropriate
method and then that method is invoked with the same arguments, in
the same order as the call to the generic, as if the call had been made
directly to the method.
</p>
<p>In order to determine the correct method the class attribute of the
first argument to the generic is obtained and used to find the correct
method. The
<a name="index-name-8"></a>
name of the generic function is combined with the first element of the
class attribute into the form, <code><var>generic</var>.<var>class</var></code> and a
function with that name is sought. If the function is found then it is
used. If no such function is found then the second element of the class
attribute is used, and so on until all the elements of the class
attribute have been exhausted. If no method has been found at that
point then the method <code><var>generic</var>.<var>default</var></code> is used. If
the first argument to the generic function has no class attribute then
<code><var>generic</var>.<var>default</var></code> is used. Since the introduction of
namespaces the methods may not be accessible by their names
(i.e. <code>get("<var>generic</var>.<var>class</var>")</code> may fail), but they will
be accessible by <code>getS3method("<var>generic</var>","<var>class</var>")</code>.
</p>
<a name="index-object-4"></a>
<p>Any object can have a <code>class</code> attribute. This attribute can have
any number of elements. Each of these is a string that defines a class.
When a generic function is invoked the class of its first argument is
examined.
</p>
<hr>
<a name="UseMethod"></a>
<div class="header">
<p>
Next: <a href="#NextMethod" accesskey="n" rel="next">NextMethod</a>, Previous: <a href="#Method-dispatching" accesskey="p" rel="prev">Method dispatching</a>, Up: <a href="#Object_002doriented-programming" accesskey="u" rel="up">Object-oriented programming</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="UseMethod-1"></a>
<h3 class="section">5.4 UseMethod</h3>
<a name="index-UseMethod"></a>
<p><code>UseMethod</code> is a special function and it behaves differently from
other function calls. The syntax of a call to it is
<code>UseMethod(<var>generic</var>, <var>object</var>)</code>, where <var>generic</var> is
the name of the generic function, <var>object</var> is the object used to
determine which method should be chosen. <code>UseMethod</code> can only be
called from the body of a function.
</p>
<a name="index-evaluation-5"></a>
<p><code>UseMethod</code> changes the evaluation model in two ways. First, when
it is invoked it determines the next method (function) to be called. It
then invokes that function using the current evaluation
<a name="index-environment-13"></a>
environment; this process will be described shortly. The second way in
which <code>UseMethod</code> changes the evaluation environment is that it
does not return control to the calling function. This means, that any
statements after a call to <code>UseMethod</code> are guaranteed not to be
executed.
</p>
<p>When <code>UseMethod</code> is invoked the generic function is the specified
value in the call to <code>UseMethod</code>. The object to dispatch on is
either the supplied second argument or the first argument to the current
function. The class of the argument is determined and the first element
of it is combined with the name of the generic to determine the
appropriate method. So, if the generic had name <code>foo</code> and the
class of the object is <code>"bar"</code>, then R will search for a method
named <code>foo.bar</code>. If no such method exists then the inheritance
mechanism described above is used to locate an appropriate method.
</p>
<p>Once a method has been determined R invokes it in a special way.
Rather than creating a new evaluation
<a name="index-environment-14"></a>
environment R uses the
environment of the current function call (the call to the generic). Any
<a name="index-assignment-7"></a>
assignments or evaluations that were made before the call to
<code>UseMethod</code> will be in effect. The arguments that were used in the
call to the generic are rematched to the formal arguments of the
selected method.
</p>
<p>When the method is invoked it is called with arguments that are the same
in number and have the same names as in the call to the generic. They
are matched to the arguments of the method according to the standard
R rules for argument matching. However the object, i.e. the first
argument has been evaluated.
</p>
<p>The call to <code>UseMethod</code> has the effect of placing some special
objects in the evaluation frame. They are <code>.Class</code>,
<code>.Generic</code> and <code>.Method</code>. These special objects are used to
by R to handle the method dispatch and inheritance. <code>.Class</code> is
the class of the object, <code>.Generic</code> is the name of the generic
function and <code>.Method</code> is the name of the method currently being
invoked. If the method was invoked through one of the internal
interfaces then there may also be an object called <code>.Group</code>. This
will be described in Section <a href="#Group-methods">Group methods</a>. After the initial
call to <code>UseMethod</code> these special variables, not the object itself,
control the selection of subsequent methods.
</p>
<p>The body of the method is then evaluated in the standard fashion. In
particular variable look-up in the body follows the rules for the
method. So if the method has an associated environment then that is
used. In effect we have replaced the call to the generic by a call to
the method. Any local
<a name="index-assignment-8"></a>
assignments in the frame of the generic will be
carried forward into the call to the method. Use of this <em>feature</em>
is discouraged. It is important to realize that control will never
return to the generic and hence any expressions after a call to
<code>UseMethod</code> will never be executed.
</p>
<p>Any arguments to the generic that were evaluated prior to the call to
<code>UseMethod</code> remain evaluated.
</p>
<p>If the first argument to <code>UseMethod</code> is not supplied it is assumed
to be the name of the current function. If two arguments are supplied
to <code>UseMethod</code> then the first is the name of the method and the
second is assumed to be the object that will be dispatched on. It is
evaluated so that the required method can be determined. In this case
the first argument in the call to the generic is not evaluated and is
discarded. There is no way to change the other arguments in the call to
the method; these remain as they were in the call to the generic. This
is in contrast to <code>NextMethod</code> where the arguments in the call to
the next method can be altered.
</p>
<hr>
<a name="NextMethod"></a>
<div class="header">
<p>
Next: <a href="#Group-methods" accesskey="n" rel="next">Group methods</a>, Previous: <a href="#UseMethod" accesskey="p" rel="prev">UseMethod</a>, Up: <a href="#Object_002doriented-programming" accesskey="u" rel="up">Object-oriented programming</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="NextMethod-1"></a>
<h3 class="section">5.5 NextMethod</h3>
<a name="index-NextMethod"></a>
<p><code>NextMethod</code> is used to provide a simple inheritance mechanism.
</p>
<p>Methods invoked as a result of a call to <code>NextMethod</code> behave as if
they had been invoked from the previous method. The arguments to the
inherited method are in the same order and have the same names as the
call to the current method. This means that they are the same as for
the call to the generic. However, the expressions for the arguments are
the names of the corresponding formal arguments of the current method.
Thus the arguments will have values that correspond to their value at
the time NextMethod was invoked.
</p>
<p>Unevaluated arguments remain unevaluated. Missing arguments remain
missing.
</p>
<p>The syntax for a call to <code>NextMethod</code> is <code>NextMethod(generic,
object, ...)</code>. If the <code>generic</code> is not supplied the value of
<code>.Generic</code> is used. If the <code>object</code> is not supplied the first
argument in the call to the current method is used. Values in the
‘<samp>...</samp>’ argument are used to modify the arguments of the next method.
</p>
<p>It is important to realize that the choice of the next method depends on
the current values of <code>.Generic</code> and <code>.Class</code> and not on the
object. So changing the object in a call to <code>NextMethod</code> affects
the arguments received by the next method but does not affect the choice
of the next method.
</p>
<p>Methods can be called directly. If they are then there will be no
<code>.Generic</code>, <code>.Class</code> or <code>.Method</code>. In this case the
<code>generic</code> argument of <code>NextMethod</code> must be specified. The
value of <code>.Class</code> is taken to be the class attribute of the object
which is the first argument to the current function. The value of
<code>.Method</code> is the name of the current function. These choices for
default values ensure that the behaviour of a method doesn’t change
depending on whether it is called directly or via a call to a generic.
</p>
<p>An issue for discussion is the behaviour of the ‘<samp>...</samp>’ argument to
<code>NextMethod</code>. The White Book describes the behaviour as follows:
</p>
<a name="index-name-9"></a>
<p>- named arguments replace the corresponding arguments in the call to
the current method. Unnamed arguments go at the start of the argument
list.
</p>
<p>What I would like to do is:
</p>
<p>-first do the argument matching for NextMethod;
-if the object or generic are changed fine
-first if a named list element matches an argument (named or not) the
list value replaces the argument value.
- the first unnamed list element
</p>
<p>Values for lookup:
Class: comes first from .Class, second from the first argument to the
method and last from the object specified in the call to NextMethod
</p>
<p>Generic: comes first from .Generic, if nothing then from the first
argument to the method and if it’s still missing from the call to
NextMethod
</p>
<p>Method: this should just be the current function name.
</p>
<hr>
<a name="Group-methods"></a>
<div class="header">
<p>
Next: <a href="#Writing-methods" accesskey="n" rel="next">Writing methods</a>, Previous: <a href="#NextMethod" accesskey="p" rel="prev">NextMethod</a>, Up: <a href="#Object_002doriented-programming" accesskey="u" rel="up">Object-oriented programming</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Group-methods-1"></a>
<h3 class="section">5.6 Group methods</h3>
<p>For several types of
<a name="index-function_002c-internal-1"></a>
internal functions R provides a dispatching
mechanism for operators. This means that operators such as <code>==</code> or
<code><</code> can have their behaviour modified for members of special
classes. The functions and operators have been grouped into three
categories and group methods can be written for each of these
categories. There is currently no mechanism to add groups. It is
possible to write methods specific to any function within a group.
</p>
<p>The following table lists the functions for the different Groups.
</p>
<dl compact="compact">
<dt>‘<samp>Math</samp>’</dt>
<dd><p>abs, acos, acosh, asin, asinh, atan, atanh, ceiling, cos, cosh, cospi, cumsum,
exp, floor, gamma, lgamma, log, log10, round, signif, sin, sinh, sinpi,
tan, tanh, tanpi, trunc
</p>
</dd>
<dt>‘<samp>Summary</samp>’</dt>
<dd><p>all, any, max, min, prod, range, sum
</p>
</dd>
<dt>‘<samp>Ops</samp>’</dt>
<dd><p><code>+</code>, <code>-</code>, <code>*</code>, <code>/</code>, <code>^</code>, <code><</code> , <code>></code>,
<code><=</code>, <code>>=</code>, <code>!=</code>, <code>==</code>, <code>%%</code>, <code>%/%</code>,
<code>&</code>, <code>|</code>, <code>!</code>
</p></dd>
</dl>
<p>For operators in the Ops group a special method is invoked if the two
operands taken together suggest a single method. Specifically, if both
operands correspond to the same method or if one operand corresponds to
a method that takes precedence over that of the other operand. If they
do not suggest a single method then the default method is used. Either
a group method or a class method dominates if the other operand has no
corresponding method. A class method dominates a group method.
</p>
<p>When the group is Ops the special variable <code>.Method</code> is a string
vector with two elements. The elements of <code>.Method</code> are set to the
name of the method if the corresponding argument is a member of the
class that was used to determine the method. Otherwise the
corresponding element of <code>.Method</code> is set to the zero length
string, <code>""</code>.
</p>
<hr>
<a name="Writing-methods"></a>
<div class="header">
<p>
Previous: <a href="#Group-methods" accesskey="p" rel="prev">Group methods</a>, Up: <a href="#Object_002doriented-programming" accesskey="u" rel="up">Object-oriented programming</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Writing-methods-1"></a>
<h3 class="section">5.7 Writing methods</h3>
<p>Users can easily write their own methods and generic functions. A
<a name="index-function_002c-generic-6"></a>
generic function is simply a function with a call to <code>UseMethod</code>.
A method is simply a function that has been invoked via method dispatch.
This can be as a result of a call to either <code>UseMethod</code> or
<code>NextMethod</code>.
</p>
<p>It is worth remembering that methods can be called directly. That means
that they can be entered without a call to <code>UseMethod</code> having been
made and hence the special variables <code>.Generic</code>, <code>.Class</code> and
<code>.Method</code> will not have been instantiated. In that case the
default rules detailed above will be used to determine these.
</p>
<p>The most common use of
<a name="index-function_002c-generic-7"></a>
generic functions is to provide <code>print</code> and
<code>summary</code> methods for statistical objects, generally the output of
some model fitting process. To do this, each model attaches a class
attribute to its output and then provides a special method that takes
that output and provides a nice readable version of it. The user then
needs only remember that <code>print</code> or <code>summary</code> will provide
nice output for the results of any analysis.
</p>
<hr>
<a name="Computing-on-the-language"></a>
<div class="header">
<p>
Next: <a href="#System-and-foreign-language-interfaces" accesskey="n" rel="next">System and foreign language interfaces</a>, Previous: <a href="#Object_002doriented-programming" accesskey="p" rel="prev">Object-oriented programming</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Computing-on-the-language-1"></a>
<h2 class="chapter">6 Computing on the language</h2>
<p>R belongs to a class of programming languages in which subroutines
have the ability to modify or construct other subroutines and evaluate
the result as an integral part of the language itself. This is similar
to Lisp and Scheme and other languages of the “functional programming”
variety, but in contrast to FORTRAN and the ALGOL family. The Lisp
family takes this feature to the extreme by the “everything is a list”
paradigm in which there is no distinction between programs and data.
</p>
<p>R presents a friendlier interface to programming than Lisp does, at
least to someone used to mathematical formulas and C-like control
structures, but the engine is really very Lisp-like. R allows direct
access to
<a name="index-parsing-3"></a>
parsed expressions and functions and allows you to alter and
subsequently execute them, or create entirely new functions from
scratch.
</p>
<p>There is a number of standard applications of this facility, such as
calculation of analytical derivatives of expressions, or the generation
of polynomial functions from a vector of coefficients. However, there
are also uses that are much more fundamental to the workings of the
interpreted part of R. Some of these are essential to the reuse of
functions as components in other functions, as the (admittedly not very
pretty) calls to <code>model.frame</code> that are constructed in several
modeling and plotting routines. Other uses simply allow elegant
interfaces to useful functionality. As an example, consider the
<code>curve</code> function, which allows you to draw the graph of a function
given as an expression like <code>sin(x)</code> or the facilities for plotting
mathematical expressions.
</p>
<p>In this chapter, we give an introduction to the set of facilities that
are available for computing on the language.
</p>
<table summary="" class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">• <a href="#Direct-manipulation-of-language-objects" accesskey="1">Direct manipulation of language objects</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Substitutions" accesskey="2">Substitutions</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#More-on-evaluation" accesskey="3">More on evaluation</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Evaluation-of-expression-objects" accesskey="4">Evaluation of expression objects</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Manipulation-of-function-calls" accesskey="5">Manipulation of function calls</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Manipulation-of-functions" accesskey="6">Manipulation of functions</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="Direct-manipulation-of-language-objects"></a>
<div class="header">
<p>
Next: <a href="#Substitutions" accesskey="n" rel="next">Substitutions</a>, Previous: <a href="#Computing-on-the-language" accesskey="p" rel="prev">Computing on the language</a>, Up: <a href="#Computing-on-the-language" accesskey="u" rel="up">Computing on the language</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Direct-manipulation-of-language-objects-1"></a>
<h3 class="section">6.1 Direct manipulation of language objects</h3>
<p>There are three kinds of language objects that are available for
modification, calls, expressions, and functions. At this point, we
shall concentrate on the call objects. These are sometimes referred to
as “unevaluated expressions”, although this terminology is somewhat
confusing. The most direct method of obtaining a call object is to use
<code>quote</code> with an expression argument, e.g.,
</p>
<div class="example">
<pre class="example">> e1 <- quote(2 + 2)
> e2 <- quote(plot(x, y))
</pre></div>
<p>The arguments are not evaluated, the result is simply the parsed
argument. The objects <code>e1</code> and <code>e2</code> may be evaluated later
using <code>eval</code>, or simply manipulated as data. It is perhaps most
immediately obvious why the <code>e2</code> object has mode <code>"call"</code>,
since it involves a call to the <code>plot</code> function with some
arguments. However, <code>e1</code> actually has exactly the same structure
as a call to the binary operator <code>+</code> with two arguments, a fact
that gets clearly displayed by the following
</p>
<div class="example">
<pre class="example">> quote("+"(2, 2))
2 + 2
</pre></div>
<p>The components of a call object are accessed using a list-like syntax,
and may in fact be converted to and from lists using <code>as.list</code> and
<code>as.call</code>
</p>
<div class="example">
<pre class="example">> e2[[1]]
plot
> e2[[2]]
x
> e2[[3]]
y
</pre></div>
<p>When keyword argument matching is used, the keywords can be used as list
tags:
</p>
<div class="example">
<pre class="example">> e3 <- quote(plot(x = age, y = weight))
> e3$x
age
> e3$y
weight
</pre></div>
<p>All the components of the call object have mode <code>"name"</code> in the
preceding examples. This is true for identifiers in calls, but the
components of a call can also be constants—which can be of any type,
although the first component had better be a function if the call is to
be evaluated successfully—or other call objects, corresponding to
subexpressions. Objects of mode
<a name="index-name-10"></a>
name can be constructed from character
strings using <code>as.name</code>, so one might modify the <code>e2</code> object
as follows
</p>
<div class="example">
<pre class="example">> e2[[1]] <- as.name("+")
> e2
x + y
</pre></div>
<p>To illustrate the fact that subexpressions are simply components that
are themselves calls, consider
</p>
<div class="example">
<pre class="example">> e1[[2]] <- e2
> e1
x + y + 2
</pre></div>
<p>All grouping parentheses in input are preserved in parsed expressions.
They are represented as a function call with one argument, so that
<code>4 - (2 - 2)</code> becomes <code>"-"(4, "(" ("-"(2, 2)))</code> in prefix
notation. In evaluations, the ‘<samp>(</samp>’ operator just returns its
argument.
</p>
<p>This is a bit unfortunate, but it is not easy to write a
<a name="index-parsing-4"></a>
parser/deparser
combination that both preserves user input, stores it in minimal form
and ensures that parsing a deparsed expression gives the same expression
back.
</p>
<p>As it happens, R’s parser is not perfectly invertible, nor is its
deparser, as the following examples show
</p>
<div class="example">
<pre class="example">> str(quote(c(1,2)))
language c(1, 2)
> str(c(1,2))
num [1:2] 1 2
> deparse(quote(c(1,2)))
[1] "c(1, 2)"
> deparse(c(1,2))
[1] "c(1, 2)"
> quote("-"(2, 2))
2 - 2
> quote(2 - 2)
2 - 2
</pre></div>
<p>Deparsed expressions should, however, evaluate to an equivalent value
to the original expression (up to rounding error).
</p>
<p>...internal storage of flow control constructs...note Splus
incompatibility...
</p>
<hr>
<a name="Substitutions"></a>
<div class="header">
<p>
Next: <a href="#More-on-evaluation" accesskey="n" rel="next">More on evaluation</a>, Previous: <a href="#Direct-manipulation-of-language-objects" accesskey="p" rel="prev">Direct manipulation of language objects</a>, Up: <a href="#Computing-on-the-language" accesskey="u" rel="up">Computing on the language</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Substitutions-1"></a>
<h3 class="section">6.2 Substitutions</h3>
<p>It is in fact not often that one wants to modify the innards of an
expression like in the previous section. More frequently, one wants to
simply get at an expression in order to deparse it and use it for
labeling plots, for instance. An example of this is seen at the
beginning of <code>plot.default</code>:
<a name="index-substitute"></a>
</p>
<div class="example">
<pre class="example">xlabel <- if (!missing(x))
deparse(substitute(x))
</pre></div>
<p>This causes the variable or expression given as the <code>x</code> argument to
<code>plot</code> to be used for labeling the x-axis later on.
</p>
<p>The function used to achieve this is <code>substitute</code> which takes the
expression <code>x</code> and substitutes the expression that was passed
through the formal argument <code>x</code>. Notice that for this to happen,
<code>x</code> must carry information about the expression that creates its
value. This is related to the
<a name="index-evaluation_002c-lazy-1"></a>
lazy evaluation scheme of R
(see <a href="#Promise-objects">Promise objects</a>). A formal argument is really a
<em>promise</em>, an object with three slots, one for the expression that
defines it, one for the environment in which to evaluate that expression,
and one for the value of that expression once evaluated. <code>substitute</code>
will recognize a promise variable and substitute the value of its
expression slot. If <code>substitute</code> is invoked inside a function, the
local variables of the function are also subject to substitution.
</p>
<p>The argument to <code>substitute</code> does not have to be a simple
identifier, it can be an expression involving several variables and
substitution will occur for each of these. Also, <code>substitute</code> has
an additional argument which can be an environment or a list in which
the variables are looked up. For example:
</p>
<div class="example">
<pre class="example">> substitute(a + b, list(a = 1, b = quote(x)))
1 + x
</pre></div>
<p>Notice that quoting was necessary to substitute the <code>x</code>. This kind
of construction comes in handy in connection with the facilities for
putting math expression in graphs, as the following case shows
</p>
<div class="example">
<pre class="example">> plot(0)
> for (i in 1:4)
+ text(1, 0.2 * i,
+ substitute(x[ix] == y, list(ix = i, y = pnorm(i))))
</pre></div>
<p>It is important to realize that the substitutions are purely lexical;
there is no checking that the resulting call objects make sense if they
are evaluated. <code>substitute(x <- x + 1, list(x = 2))</code> will happily
return <code>2 <- 2 + 1</code>. However, some parts of R make up their own
rules for what makes sense and what does not and might actually have a
use for such ill-formed expressions. For example, using the “math in
graphs” feature often involves constructions that are syntactically
correct, but which would be meaningless to evaluate, like
‘<samp>{}>=40*" years"</samp>’.
</p>
<p>Substitute will not evaluate its first argument. This leads to the
puzzle of how to do substitutions on an object that is contained in a
variable. The solution is to use <code>substitute</code> once more, like this
</p>
<div class="example">
<pre class="example">> expr <- quote(x + y)
> substitute(substitute(e, list(x = 3)), list(e = expr))
substitute(x + y, list(x = 3))
> eval(substitute(substitute(e, list(x = 3)), list(e = expr)))
3 + y
</pre></div>
<p>The exact rules for substitutions are as follows: Each
<a name="index-symbol-4"></a>
symbol in the
<a name="index-parsing-5"></a>
parse tree for the first is matched against the second argument, which
can be a tagged list or an environment frame. If it is a simple local
object, its value is inserted, <em>except</em> if matching against the
global environment. If it is a promise (usually a function argument),
the promise expression is substituted. If the symbol is not matched, it
is left untouched. The special exception for substituting at the top
level is admittedly peculiar. It has been inherited from S and the
rationale is most likely that there is no control over which variables
might be bound at that level so that it would be better to just make
substitute act as <code>quote</code>.
</p>
<p>The rule of promise substitution is slightly different from that of
S if the local variable is modified before <code>substitute</code> is
used. R will then use the new value of the variable, whereas S
will unconditionally use the argument expression—unless it was a
constant, which has the curious consequence that <code>f((1))</code> may be
very different from <code>f(1)</code> in S. The R rule is considerably
cleaner, although it does have consequences in connection with
<a name="index-evaluation_002c-lazy-2"></a>
lazy
evaluation that comes as a surprise to some. Consider
</p>
<div class="example">
<pre class="example">logplot <- function(y, ylab = deparse(substitute(y))) {
y <- log(y)
plot(y, ylab = ylab)
}
</pre></div>
<p>This looks straightforward, but one will discover that the y label
becomes an ugly <code>c(...)</code> expression. It happens because the rules
of lazy evaluation cause the evaluation of the <code>ylab</code> expression
to happen <em>after</em> <code>y</code> has been modified. The solution is to
force <code>ylab</code> to be evaluated first, i.e.,
</p>
<div class="example">
<pre class="example">logplot <- function(y, ylab = deparse(substitute(y))) {
ylab
y <- log(y)
plot(y, ylab = ylab)
}
</pre></div>
<p>Notice that one should not use <code>eval(ylab)</code> in this situation. If
<code>ylab</code> is a language or expression object, then that would cause
the object to be evaluated as well, which would not at all be desirable
if a math expression like <code>quote(log[e](y))</code> was being passed.
</p>
<p>A variant on <code>substitute</code> is <code>bquote</code>, which is used to replace some subexpressions with their values. The example from above
</p><div class="example">
<pre class="example">> plot(0)
> for (i in 1:4)
+ text(1, 0.2 * i,
+ substitute(x[ix] == y, list(ix = i, y = pnorm(i))))
</pre></div>
<p>could be written more compactly as
</p><div class="example">
<pre class="example">plot(0)
for(i in 1:4)
text(1, 0.2*i, bquote( x[.(i)] == .(pnorm(i)) ))
</pre></div>
<p>The expression is quoted except for the contents of <code>.()</code>
subexpressions, which are replaced with their values. There is an
optional argument to compute the values in a different
environment. The syntax for <code>bquote</code> is borrowed from the LISP
backquote macro.
</p>
<hr>
<a name="More-on-evaluation"></a>
<div class="header">
<p>
Next: <a href="#Evaluation-of-expression-objects" accesskey="n" rel="next">Evaluation of expression objects</a>, Previous: <a href="#Substitutions" accesskey="p" rel="prev">Substitutions</a>, Up: <a href="#Computing-on-the-language" accesskey="u" rel="up">Computing on the language</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="More-on-evaluation-1"></a>
<h3 class="section">6.3 More on evaluation</h3>
<a name="index-evaluation-6"></a>
<p>The <code>eval</code> function was introduced earlier in this chapter as a
means of evaluating call objects. However, this is not the full story.
It is also possible to specify the
<a name="index-environment-15"></a>
environment in which the evaluation
is to take place. By default this is the evaluation frame from which
<code>eval</code> is called, but quite frequently it needs to be set to
something else.
<a name="index-eval"></a>
</p>
<p>Very often, the relevant evaluation frame is that of the parent of the
current frame (cf. ???). In particular, when the object to evaluate
is the result of a <code>substitute</code> operation of the function
arguments, it will contain variables that make sense to the caller only
(notice that there is no reason to expect that the variables of the
caller are in the
<a name="index-scope-5"></a>
lexical scope of the callee). Since evaluation in the
parent frame occurs frequently, an <code>eval.parent</code> function exists as
a shorthand for <code>eval(expr, sys.frame(sys.parent()))</code>.
</p>
<p>Another case that occurs frequently is evaluation in a list or a data
frame. For instance, this happens in connection with the
<code>model.frame</code> function when a <code>data</code> argument is given.
Generally, the terms of the model formula need to be evaluated in
<code>data</code>, but they may occasionally also contain references to items
in the caller of <code>model.frame</code>. This is sometimes useful in
connection with simulation studies. So for this purpose one needs not
only to evaluate an expression in a list, but also to specify an
enclosure into which the search continues if the variable is not in the
list. Hence, the call has the form
</p>
<div class="example">
<pre class="example">eval(expr, data, sys.frame(sys.parent()))
</pre></div>
<p>Notice that evaluation in a given environment may actually change that
environment, most obviously in cases involving the
<a name="index-assignment-9"></a>
assignment operator,
such as
</p>
<div class="example">
<pre class="example">eval(quote(total <- 0), environment(robert$balance)) # <span class="roman">rob Rob</span>
</pre></div>
<p>This is also true when evaluating in lists, but the original list does
not change because one is really working on a copy.
</p>
<hr>
<a name="Evaluation-of-expression-objects"></a>
<div class="header">
<p>
Next: <a href="#Manipulation-of-function-calls" accesskey="n" rel="next">Manipulation of function calls</a>, Previous: <a href="#More-on-evaluation" accesskey="p" rel="prev">More on evaluation</a>, Up: <a href="#Computing-on-the-language" accesskey="u" rel="up">Computing on the language</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Evaluation-of-expression-objects-1"></a>
<h3 class="section">6.4 Evaluation of expression objects</h3>
<p>Objects of mode <code>"expression"</code> are defined in <a href="#Expression-objects">Expression objects</a>. They are very similar to lists of call objects.
</p>
<div class="example">
<pre class="example">> ex <- expression(2 + 2, 3 + 4)
> ex[[1]]
2 + 2
> ex[[2]]
3 + 4
> eval(ex)
[1] 7
</pre></div>
<p>Notice that evaluating an expression object evaluates each call in turn,
but the final value is that of the last call. In this respect it
behaves almost identically to the compound language object
<code>quote({2 + 2; 3 + 4})</code>. However, there is a subtle difference:
Call objects are indistinguishable from subexpressions in a parse tree.
This means that they are automatically evaluated in the same way a
subexpression would be. Expression objects can be recognized during
evaluation and in a sense retain their quotedness. The evaluator will
not evaluate an expression object recursively, only when it is passed
directly to <code>eval</code> function as above. The difference can be seen
like this:
</p>
<div class="example">
<pre class="example">> eval(substitute(mode(x), list(x = quote(2 + 2))))
[1] "numeric"
> eval(substitute(mode(x), list(x = expression(2 + 2))))
[1] "expression"
</pre></div>
<p>The deparser represents an expression object by the call
that creates it. This is similar to the way it handles numerical
vectors and several other objects that do not have a specific external
representation. However, it does lead to the following bit of
confusion:
</p>
<div class="example">
<pre class="example">> e <- quote(expression(2 + 2))
> e
expression(2 + 2)
> mode(e)
[1] "call"
> ee <- expression(2 + 2)
> ee
expression(2 + 2)
> mode(ee)
[1] "expression"
</pre></div>
<p>I.e., <code>e</code> and <code>ee</code> look identical when printed, but one is a
call that generates an expression object and the other is the object
itself.
</p>
<hr>
<a name="Manipulation-of-function-calls"></a>
<div class="header">
<p>
Next: <a href="#Manipulation-of-functions" accesskey="n" rel="next">Manipulation of functions</a>, Previous: <a href="#Evaluation-of-expression-objects" accesskey="p" rel="prev">Evaluation of expression objects</a>, Up: <a href="#Computing-on-the-language" accesskey="u" rel="up">Computing on the language</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Manipulation-of-function-calls-1"></a>
<h3 class="section">6.5 Manipulation of function calls</h3>
<p>It is possible for a
<a name="index-function-26"></a>
function to find out how it has been called by
looking at the result of <code>sys.call</code> as in the following example of
a function that simply returns its own call:
</p>
<div class="example">
<pre class="example">> f <- function(x, y, ...) sys.call()
> f(y = 1, 2, z = 3, 4)
f(y = 1, 2, z = 3, 4)
</pre></div>
<p>However, this is not really useful except for debugging because it
requires the function to keep track of argument matching in order to
interpret the call. For instance, it must be able to see that the 2nd
actual argument gets matched to the first formal one (<code>x</code> in the
above example).
</p>
<p>More often one requires the call with all actual arguments bound to the
corresponding formals. To this end, the function <code>match.call</code> is
used. Here’s a variant of the preceding example, a function that
returns its own call with arguments matched
</p>
<div class="example">
<pre class="example">> f <- function(x, y, ...) match.call()
> f(y = 1, 2, z = 3, 4)
f(x = 2, y = 1, z = 3, 4)
</pre></div>
<p>Notice that the second argument now gets matched to <code>x</code> and appears
in the corresponding position in the result.
</p>
<p>The primary use of this technique is to call another function with the
same arguments, possibly deleting some and adding others. A typical
application is seen at the start of the <code>lm</code> function:
</p>
<div class="example">
<pre class="example"> mf <- cl <- match.call()
mf$singular.ok <- mf$model <- mf$method <- NULL
mf$x <- mf$y <- mf$qr <- mf$contrasts <- NULL
mf$drop.unused.levels <- TRUE
mf[[1]] <- as.name("model.frame")
mf <- eval(mf, sys.frame(sys.parent()))
</pre></div>
<p>Notice that the resulting call is
<a name="index-evaluation-7"></a>
evaluated in the parent frame, in
which one can be certain that the involved expressions make sense. The
call can be treated as a list object where the first element is the name
of the function and the remaining elements are the actual argument
expressions, with the corresponding formal argument names as tags.
Thus, the technique to eliminate undesired arguments is to assign
<code>NULL</code>, as seen in lines 2 and 3, and to add an argument one uses
tagged list
<a name="index-assignment-10"></a>
assignment (here to pass <code>drop.unused.levels = TRUE</code>)
as in line 4. To change the name of the function called, assign to the
first element of the list and make sure that the value is a name, either
using the <code>as.name("model.frame")</code> construction here or
<code>quote(model.frame)</code>.
</p>
<p>The <code>match.call</code> function has an <code>expand.dots</code> argument which
is a switch which if set to <code>FALSE</code> lets all ‘<samp>...</samp>’ arguments
be collected as a single argument with the tag ‘<samp>...</samp>’.
<a name="index-match_002ecall-1"></a>
</p>
<div class="example">
<pre class="example">> f <- function(x, y, ...) match.call(expand.dots = FALSE)
> f(y = 1, 2, z = 3, 4)
f(x = 2, y = 1, ... = list(z = 3, 4))
</pre></div>
<p>The ‘<samp>...</samp>’ argument is a list (a pairlist to be precise), not a call
to <code>list</code> like it is in S:
</p>
<div class="example">
<pre class="example">> e1 <- f(y = 1, 2, z = 3, 4)$...
> e1
$z
[1] 3
[[2]]
[1] 4
</pre></div>
<p>One reason for using this form of <code>match.call</code> is simply to get rid
of any ‘<samp>...</samp>’ arguments in order not to be passing unspecified
arguments on to functions that may not know them. Here’s an example
paraphrased from <code>plot.formula</code>:
</p>
<div class="example">
<pre class="example">m <- match.call(expand.dots = FALSE)
m$... <- NULL
m[[1]] <- "model.frame"
</pre></div>
<p>A more elaborate application is in <code>update.default</code> where a set of
optional extra arguments can add to, replace, or cancel those of the
original call:
</p>
<div class="example">
<pre class="example">extras <- match.call(expand.dots = FALSE)$...
if (length(extras) > 0) {
existing <- !is.na(match(names(extras), names(call)))
for (a in names(extras)[existing]) call[[a]] <- extras[[a]]
if (any(!existing)) {
call <- c(as.list(call), extras[!existing])
call <- as.call(call)
}
}
</pre></div>
<p>Notice that care is taken to modify existing arguments individually in
case <code>extras[[a]] == NULL</code>. Concatenation does not work on call
objects without the coercion as shown; this is arguably a bug.
</p>
<p>Two further functions exist for the construction of function calls,
namely <code>call</code> and <code>do.call</code>.
</p>
<p>The function <code>call</code> allows creation of a call object from the
function name and the list of arguments
</p>
<div class="example">
<pre class="example">> x <- 10.5
> call("round", x)
round(10.5)
</pre></div>
<p>As seen, the value of <code>x</code> rather than the
<a name="index-symbol-5"></a>
symbol is inserted in the
call, so it is distinctly different from <code>round(x)</code>. The form is
used rather rarely, but is occasionally useful where the name of a
function is available as a character variable.
</p>
<p>The function <code>do.call</code> is related, but evaluates the call immediately
and takes the arguments from an object of mode <code>"list"</code> containing
all the arguments. A natural use of this is when one wants to apply a
function like <code>cbind</code> to all elements of a list or data frame.
<a name="index-do_002ecall"></a>
</p>
<div class="example">
<pre class="example">is.na.data.frame <- function (x) {
y <- do.call("cbind", lapply(x, "is.na"))
rownames(y) <- row.names(x)
y
}
</pre></div>
<p>Other uses include variations over constructions like <code>do.call("f",
list(...))</code>. However, one should be aware that this involves evaluation
of the arguments before the actual function call, which may defeat
aspects of lazy evaluation and argument substitution in the function
itself. A similar remark applies to the <code>call</code> function.
</p>
<hr>
<a name="Manipulation-of-functions"></a>
<div class="header">
<p>
Previous: <a href="#Manipulation-of-function-calls" accesskey="p" rel="prev">Manipulation of function calls</a>, Up: <a href="#Computing-on-the-language" accesskey="u" rel="up">Computing on the language</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Manipulation-of-functions-1"></a>
<h3 class="section">6.6 Manipulation of functions</h3>
<p>It is often useful to be able to manipulate the components of a
<a name="index-function-27"></a>
function
or closure. R provides a set of interface functions for this
purpose.
</p>
<dl compact="compact">
<dt><code>body</code>
<a name="index-body-1"></a>
</dt>
<dd><p>Returns the expression that is the body of the function.
</p></dd>
<dt><code>formals</code>
<a name="index-formals-1"></a>
</dt>
<dd><p>Returns a list of the formal arguments to the function. This is a
<code>pairlist</code>.
</p></dd>
<dt><code>environment</code>
<a name="index-environment-21"></a>
</dt>
<dd><a name="index-environment-16"></a>
<p>Returns the environment associated with the function.
</p></dd>
<dt><code>body<-</code>
<a name="index-body_003c_002d"></a>
</dt>
<dd><p>This sets the body of the function to the supplied expression.
</p></dd>
<dt><code>formals<-</code>
<a name="index-formals_003c_002d"></a>
</dt>
<dd><p>Sets the formal arguments of the function to the supplied list.
</p></dd>
<dt><code>environment<-</code>
<a name="index-environment_003c_002d"></a>
</dt>
<dd><p>Sets the environment of the function to the specified environment.
</p></dd>
</dl>
<p>It is also possible to alter the bindings of different variables in the
environment of the function, using code along the lines of <code>evalq(x
<- 5, environment(f))</code>.
</p>
<p>It is also possible to convert a
<a name="index-function-28"></a>
function to a list using
<code>as.list</code>. The result is the concatenation of the list of formal
arguments with the function body. Conversely such a list can be
converted to a function using <code>as.function</code>. This functionality is
mainly included for S compatibility. Notice that environment
information is lost when <code>as.list</code> is used, whereas
<code>as.function</code> has an argument that allows the environment to be
set.
</p>
<hr>
<a name="System-and-foreign-language-interfaces"></a>
<div class="header">
<p>
Next: <a href="#Exception-handling" accesskey="n" rel="next">Exception handling</a>, Previous: <a href="#Computing-on-the-language" accesskey="p" rel="prev">Computing on the language</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="System-and-foreign-language-interfaces-1"></a>
<h2 class="chapter">7 System and foreign language interfaces</h2>
<table summary="" class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">• <a href="#Operating-system-access" accesskey="1">Operating system access</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Foreign-language-interfaces" accesskey="2">Foreign language interfaces</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#g_t_002eInternal-and-_002ePrimitive" accesskey="3">.Internal and .Primitive</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="Operating-system-access"></a>
<div class="header">
<p>
Next: <a href="#Foreign-language-interfaces" accesskey="n" rel="next">Foreign language interfaces</a>, Previous: <a href="#System-and-foreign-language-interfaces" accesskey="p" rel="prev">System and foreign language interfaces</a>, Up: <a href="#System-and-foreign-language-interfaces" accesskey="u" rel="up">System and foreign language interfaces</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Operating-system-access-1"></a>
<h3 class="section">7.1 Operating system access</h3>
<p>Access to the operating system shell is via the R function
<code>system</code>.
<a name="index-system"></a>
The details will differ by platform (see the on-line help), and about
all that can safely be assumed is that the first argument will be a
string <code>command</code> that will be passed for execution (not necessarily
by a shell) and the second argument will be <code>internal</code> which if
true will collect the output of the command into an R character
vector.
</p>
<p>The functions <code>system.time</code>
<a name="index-system_002etime"></a>
and <code>proc.time</code>
<a name="index-proc_002etime"></a>
are available for timing (although the information available may be
limited on non-Unix-like platforms).
</p>
<p>Information from the operating system
<a name="index-environment-17"></a>
environment can be accessed and manipulated with
</p><blockquote>
<table summary="">
<tr><td width="30%"><code>Sys.getenv</code></td><td width="70%">OS environment variables
<a name="index-Sys_002egetenv"></a></td></tr>
<tr><td width="30%"><code>Sys.putenv</code>
<a name="index-Sys_002eputenv"></a></td></tr>
<tr><td width="30%"><code>Sys.getlocale</code></td><td width="70%">System locale
<a name="index-Sys_002egetlocale"></a></td></tr>
<tr><td width="30%"><code>Sys.putlocale</code>
<a name="index-Sys_002eputlocale"></a></td></tr>
<tr><td width="30%"><code>Sys.localeconv</code>
<a name="index-Sys_002elocaleconv"></a></td></tr>
<tr><td width="30%"><code>Sys.time</code></td><td width="70%">Current time
<a name="index-Sys_002etime"></a></td></tr>
<tr><td width="30%"><code>Sys.timezone</code></td><td width="70%">Time zone
<a name="index-Sys_002etimezone"></a></td></tr>
</table>
</blockquote>
<p>A uniform set of file access functions is provided on all platforms:
</p><blockquote>
<table summary="">
<tr><td width="30%"><code>file.access</code></td><td width="70%">Ascertain File Accessibility
<a name="index-file_002eaccess"></a></td></tr>
<tr><td width="30%"><code>file.append</code></td><td width="70%">Concatenate files
<a name="index-file_002eappend"></a></td></tr>
<tr><td width="30%"><code>file.choose</code></td><td width="70%">Prompt user for file name
<a name="index-file_002echoose"></a></td></tr>
<tr><td width="30%"><code>file.copy</code></td><td width="70%">Copy files
<a name="index-file_002ecopy"></a></td></tr>
<tr><td width="30%"><code>file.create</code></td><td width="70%">Create or truncate a files
<a name="index-file_002ecreate"></a></td></tr>
<tr><td width="30%"><code>file.exists</code></td><td width="70%">Test for existence
<a name="index-file_002eexists"></a></td></tr>
<tr><td width="30%"><code>file.info</code></td><td width="70%">Miscellaneous file information
<a name="index-file_002einfo"></a></td></tr>
<tr><td width="30%"><code>file.remove</code></td><td width="70%">remove files
<a name="index-file_002eremove"></a></td></tr>
<tr><td width="30%"><code>file.rename</code></td><td width="70%">rename files
<a name="index-file_002erename"></a></td></tr>
<tr><td width="30%"><code>file.show</code></td><td width="70%">Display a text file
<a name="index-file_002eshow"></a></td></tr>
<tr><td width="30%"><code>unlink</code></td><td width="70%">Remove files or directories.
<a name="index-unlink"></a></td></tr>
</table>
</blockquote>
<p>There are also functions for manipulating file names and paths in a
platform-independent way.
</p><blockquote>
<table summary="">
<tr><td width="30%"><code>basename</code></td><td width="70%">File name without directory
<a name="index-basename"></a></td></tr>
<tr><td width="30%"><code>dirname</code></td><td width="70%">Directory name
<a name="index-dirname"></a></td></tr>
<tr><td width="30%"><code>file.path</code></td><td width="70%">Construct path to file
<a name="index-file_002epath"></a></td></tr>
<tr><td width="30%"><code>path.expand</code></td><td width="70%">Expand <code>~</code> in Unix path
<a name="index-path_002eexpand"></a></td></tr>
</table>
</blockquote>
<hr>
<a name="Foreign-language-interfaces"></a>
<div class="header">
<p>
Next: <a href="#g_t_002eInternal-and-_002ePrimitive" accesskey="n" rel="next">.Internal and .Primitive</a>, Previous: <a href="#Operating-system-access" accesskey="p" rel="prev">Operating system access</a>, Up: <a href="#System-and-foreign-language-interfaces" accesskey="u" rel="up">System and foreign language interfaces</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Foreign-language-interfaces-1"></a>
<h3 class="section">7.2 Foreign language interfaces</h3>
<a name="index-_002eC"></a>
<a name="index-_002eFortran"></a>
<a name="index-_002eCall"></a>
<a name="index-_002eExternal"></a>
<p>See <a href="http://cran.r-project.org/doc/manuals/R-exts.html#System-and-foreign-language-interfaces">System and foreign language interfaces</a> in <cite>Writing R
Extensions</cite> for the details of adding functionality to R via compiled
code.
</p>
<p>Functions <code>.C</code> and <code>.Fortran</code> provide a standard interface to
compiled code that has been linked into R, either at build time or
via <code>dyn.load</code>. They are primarily intended for compiled <strong>C</strong> and
FORTRAN code respectively, but the <code>.C</code> function can be used with
other languages which can generate C interfaces, for example C++.
</p>
<p>Functions <code>.Call</code> and <code>.External</code> provide interfaces which allow
compiled code (primarily compiled <strong>C</strong> code) to manipulate R objects.
</p>
<hr>
<a name="g_t_002eInternal-and-_002ePrimitive"></a>
<div class="header">
<p>
Previous: <a href="#Foreign-language-interfaces" accesskey="p" rel="prev">Foreign language interfaces</a>, Up: <a href="#System-and-foreign-language-interfaces" accesskey="u" rel="up">System and foreign language interfaces</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="g_t_002eInternal-and-_002ePrimitive-1"></a>
<h3 class="section">7.3 .Internal and .Primitive</h3>
<a name="index-_002eInternal-1"></a>
<a name="index-_002ePrimitive-1"></a>
<p>The <code>.Internal</code> and <code>.Primitive</code> interfaces are used to call
<strong>C</strong> code compiled into R at build time.
See <a href="http://cran.r-project.org/doc/manuals/R-ints.html#g_t_002eInternal-vs-_002ePrimitive">.Internal vs .Primitive</a> in <cite>R Internals</cite>.
</p>
<hr>
<a name="Exception-handling"></a>
<div class="header">
<p>
Next: <a href="#Debugging" accesskey="n" rel="next">Debugging</a>, Previous: <a href="#System-and-foreign-language-interfaces" accesskey="p" rel="prev">System and foreign language interfaces</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Exception-handling-1"></a>
<h2 class="chapter">8 Exception handling</h2>
<p>The exception handling facilities in R are provided through two
mechanisms. Functions such as <code>stop</code> or <code>warning</code> can be
called directly or options such as <code>"warn"</code> can be used to control
the handling of problems.
</p>
<table summary="" class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">• <a href="#stop" accesskey="1">stop</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#warning" accesskey="2">warning</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#on_002eexit" accesskey="3">on.exit</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Error-options" accesskey="4">Error options</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="stop"></a>
<div class="header">
<p>
Next: <a href="#warning" accesskey="n" rel="next">warning</a>, Previous: <a href="#Exception-handling" accesskey="p" rel="prev">Exception handling</a>, Up: <a href="#Exception-handling" accesskey="u" rel="up">Exception handling</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="stop-1"></a>
<h3 class="section">8.1 stop</h3>
<a name="index-stop"></a>
<p>A call to <code>stop</code> halts the evaluation of the current expression,
prints the message argument and returns execution to top-level.
</p>
<hr>
<a name="warning"></a>
<div class="header">
<p>
Next: <a href="#on_002eexit" accesskey="n" rel="next">on.exit</a>, Previous: <a href="#stop" accesskey="p" rel="prev">stop</a>, Up: <a href="#Exception-handling" accesskey="u" rel="up">Exception handling</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="warning-1"></a>
<h3 class="section">8.2 warning</h3>
<a name="index-warning"></a>
<a name="index-warnings"></a>
<p>The function <code>warning</code> takes a single argument that is a character
string. The behaviour of a call to <code>warning</code> depends on the value
of the option <code>"warn"</code>. If <code>"warn"</code> is negative warnings are
ignored. If it is zero, they are stored and printed after the top-level
function has completed. If it is one, they are printed as they occur
and if it is 2 (or larger) warnings are turned into errors.
</p>
<p>If <code>"warn"</code> is zero (the default), a variable <code>last.warning</code>
is created and the messages associated with each call to <code>warning</code>
are stored, sequentially, in this vector. If there are fewer than 10
warnings they are printed after the function has finished evaluating.
If there are more than 10 then a message indicating how many warnings
occurred is printed. In either case <code>last.warning</code> contains the
vector of messages, and <code>warnings</code> provides a way to access and
print it.
</p>
<hr>
<a name="on_002eexit"></a>
<div class="header">
<p>
Next: <a href="#Error-options" accesskey="n" rel="next">Error options</a>, Previous: <a href="#warning" accesskey="p" rel="prev">warning</a>, Up: <a href="#Exception-handling" accesskey="u" rel="up">Exception handling</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="on_002eexit-1"></a>
<h3 class="section">8.3 on.exit</h3>
<a name="index-on_002eexit"></a>
<p>A function can insert a call to <code>on.exit</code> at any point in the body
of a function. The effect of a call to <code>on.exit</code> is to store the
value of the body so that it will be executed when the function exits.
This allows the function to change some system parameters and to ensure
that they are reset to appropriate values when the function is finished.
The <code>on.exit</code> is guaranteed to be executed when the function exits
either directly or as the result of a warning.
</p>
<p>An error in the evaluation of the <code>on.exit</code> code causes an
immediate jump to top-level without further processing of the
<code>on.exit</code> code.
</p>
<p><code>on.exit</code> takes a single argument which is an expression to be
evaluated when the function is exited.
</p>
<hr>
<a name="Error-options"></a>
<div class="header">
<p>
Previous: <a href="#on_002eexit" accesskey="p" rel="prev">on.exit</a>, Up: <a href="#Exception-handling" accesskey="u" rel="up">Exception handling</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Error-options-1"></a>
<h3 class="section">8.4 Error options</h3>
<p>There are a number of <code>options</code> variables that can be used to
control how R handles errors and warnings. They are listed in the
table below.
</p>
<dl compact="compact">
<dt>‘<samp>warn</samp>’</dt>
<dd><p>Controls the printing of warnings.
</p></dd>
<dt>‘<samp>warning.expression</samp>’</dt>
<dd><p>Sets an expression that is to be evaluated when a warning occurs. The
normal printing of warnings is suppressed if this option is set.
</p></dd>
<dt>‘<samp>error</samp>’</dt>
<dd><p>Installs an expression that will be evaluated when an error occurs.
The normal printing of error messages and warning messages precedes the
evaluation of the expression.
</p></dd>
</dl>
<p>Expressions installed by <code>options("error")</code> are evaluated before
calls to <code>on.exit</code> are carried out.
</p>
<p>One can use <code>options(error = expression(q("yes")))</code> to get R to
quit when an error has been signalled. In this case an error will cause
R to shut down and the global environment will be saved.
</p>
<hr>
<a name="Debugging"></a>
<div class="header">
<p>
Next: <a href="#Parser" accesskey="n" rel="next">Parser</a>, Previous: <a href="#Exception-handling" accesskey="p" rel="prev">Exception handling</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Debugging-1"></a>
<h2 class="chapter">9 Debugging</h2>
<p>Debugging code has always been a bit of an art. R provides several
tools that help users find problems in their code. These tools halt
execution at particular points in the code and the current state of the
computation can be inspected.
</p>
<p>Most debugging takes place either through calls to <code>browser</code> or
<code>debug</code>. Both of these functions rely on the same internal
mechanism and both provide the user with a special prompt. Any command
can be typed at the prompt. The evaluation
<a name="index-environment-18"></a>
environment for the command
is the currently active environment. This allows you to examine the
current state of any variables etc.
</p>
<p>There are five special commands that R interprets differently. They
are,
</p>
<dl compact="compact">
<dt>‘<samp><span class="key">RET</span></samp>’</dt>
<dd><p>Go to the next statement if the function is being debugged. Continue
execution if the browser was invoked.
</p></dd>
<dt>‘<samp>c</samp>’</dt>
<dt>‘<samp>cont</samp>’</dt>
<dd><p>Continue the execution.
</p></dd>
<dt>‘<samp>n</samp>’</dt>
<dd><p>Execute the next statement in the function. This works from the browser
as well.
</p></dd>
<dt>‘<samp>where</samp>’</dt>
<dd><p>Show the call stack
</p></dd>
<dt>‘<samp>Q</samp>’</dt>
<dd><p>Halt execution and jump to the top-level immediately.
</p></dd>
</dl>
<a name="index-name-11"></a>
<p>If there is a local variable with the same name as one of the special
commands listed above then its value can be accessed by using
<code>get</code>. A call to <code>get</code> with the name in quotes will retrieve
the value in the current
<a name="index-environment-19"></a>
environment.
</p>
<p>The debugger provides access only to interpreted expressions. If a
function calls a foreign language (such as <strong>C</strong>) then no access to the
statements in that language is provided. Execution will halt on the
next statement that is evaluated in R. A symbolic debugger such as
<code>gdb</code> can be used to debug compiled code.
</p>
<table summary="" class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">• <a href="#browser" accesskey="1">browser</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#debug_002fundebug" accesskey="2">debug/undebug</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#trace_002funtrace" accesskey="3">trace/untrace</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#traceback" accesskey="4">traceback</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="browser"></a>
<div class="header">
<p>
Next: <a href="#debug_002fundebug" accesskey="n" rel="next">debug/undebug</a>, Previous: <a href="#Debugging" accesskey="p" rel="prev">Debugging</a>, Up: <a href="#Debugging" accesskey="u" rel="up">Debugging</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="browser-1"></a>
<h3 class="section">9.1 browser</h3>
<a name="index-browser"></a>
<p>A call to the function <code>browser</code> causes R to halt execution at
that point and to provide the user with a special prompt. Arguments to
<code>browser</code> are ignored.
</p>
<div class="example">
<pre class="example">> foo <- function(s) {
+ c <- 3
+ browser()
+ }
> foo(4)
Called from: foo(4)
Browse[1]> s
[1] 4
Browse[1]> get("c")
[1] 3
Browse[1]>
</pre></div>
<hr>
<a name="debug_002fundebug"></a>
<div class="header">
<p>
Next: <a href="#trace_002funtrace" accesskey="n" rel="next">trace/untrace</a>, Previous: <a href="#browser" accesskey="p" rel="prev">browser</a>, Up: <a href="#Debugging" accesskey="u" rel="up">Debugging</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="debug_002fundebug-1"></a>
<h3 class="section">9.2 debug/undebug</h3>
<a name="index-debug"></a>
<a name="index-undebug"></a>
<p>The debugger can be invoked on any function by using the command
<code>debug(<var>fun</var>)</code>. Subsequently, each time that function is
evaluated the debugger is invoked. The debugger allows you to control
the evaluation of the statements in the body of the function. Before
each statement is executed the statement is printed out and a special
prompt provided. Any command can be given, those in the table above
have special meaning.
</p>
<p>Debugging is turned off by a call to <code>undebug</code> with the function as
an argument.
</p>
<div class="example">
<pre class="example">> debug(mean.default)
> mean(1:10)
debugging in: mean.default(1:10)
debug: {
if (na.rm)
x <- x[!is.na(x)]
trim <- trim[1]
n <- length(c(x, recursive = TRUE))
if (trim > 0) {
if (trim >= 0.5)
return(median(x, na.rm = FALSE))
lo <- floor(n * trim) + 1
hi <- n + 1 - lo
x <- sort(x, partial = unique(c(lo, hi)))[lo:hi]
n <- hi - lo + 1
}
sum(x)/n
}
Browse[1]>
debug: if (na.rm) x <- x[!is.na(x)]
Browse[1]>
debug: trim <- trim[1]
Browse[1]>
debug: n <- length(c(x, recursive = TRUE))
Browse[1]> c
exiting from: mean.default(1:10)
[1] 5.5
</pre></div>
<hr>
<a name="trace_002funtrace"></a>
<div class="header">
<p>
Next: <a href="#traceback" accesskey="n" rel="next">traceback</a>, Previous: <a href="#debug_002fundebug" accesskey="p" rel="prev">debug/undebug</a>, Up: <a href="#Debugging" accesskey="u" rel="up">Debugging</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="trace_002funtrace-1"></a>
<h3 class="section">9.3 trace/untrace</h3>
<a name="index-trace"></a>
<a name="index-untrace"></a>
<p>Another way of monitoring the behaviour of R is through the
<code>trace</code> mechanism. <code>trace</code> is called with a single argument
that is the name of the function you want to trace. The name does not
need to be quoted but for some functions you will need to quote the name
in order to avoid a syntax error.
</p>
<p>When <code>trace</code> has been invoked on a function then every time that
function is evaluated the call to it is printed out. This mechanism is
removed by calling <code>untrace</code> with the function as an argument.
</p>
<div class="example">
<pre class="example">> trace("[<-")
> x <- 1:10
> x[3] <- 4
trace: "[<-"(*tmp*, 3, value = 4)
</pre></div>
<hr>
<a name="traceback"></a>
<div class="header">
<p>
Previous: <a href="#trace_002funtrace" accesskey="p" rel="prev">trace/untrace</a>, Up: <a href="#Debugging" accesskey="u" rel="up">Debugging</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="traceback-1"></a>
<h3 class="section">9.4 traceback</h3>
<a name="index-traceback"></a>
<p>When an error has caused a jump to top-level a special variable called
<code>.Traceback</code> is placed into the base environment.
<code>.Traceback</code> is a character vector with one entry for each function
call that was active at the time the error occurred. An examination of
<code>.Traceback</code> can be carried out by a call to <code>traceback</code>.
</p>
<hr>
<a name="Parser"></a>
<div class="header">
<p>
Next: <a href="#Function-and-Variable-Index" accesskey="n" rel="next">Function and Variable Index</a>, Previous: <a href="#Debugging" accesskey="p" rel="prev">Debugging</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Parser-1"></a>
<h2 class="chapter">10 Parser</h2>
<a name="index-parsing-6"></a>
<p>The parser is what converts the textual representation of R code into
an internal form which may then be passed to the R evaluator which
causes the specified instructions to be carried out. The internal form
is itself an R object and can be saved and otherwise manipulated
within the R system.
</p>
<table summary="" class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">• <a href="#The-parsing-process" accesskey="1">The parsing process</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Comments" accesskey="2">Comments</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Tokens" accesskey="3">Tokens</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Expressions" accesskey="4">Expressions</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Directives" accesskey="5">Directives</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="The-parsing-process"></a>
<div class="header">
<p>
Next: <a href="#Comments" accesskey="n" rel="next">Comments</a>, Previous: <a href="#Parser" accesskey="p" rel="prev">Parser</a>, Up: <a href="#Parser" accesskey="u" rel="up">Parser</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="The-parsing-process-1"></a>
<h3 class="section">10.1 The parsing process</h3>
<table summary="" class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">• <a href="#Modes-of-parsing" accesskey="1">Modes of parsing</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Internal-representation" accesskey="2">Internal representation</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Deparsing" accesskey="3">Deparsing</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="Modes-of-parsing"></a>
<div class="header">
<p>
Next: <a href="#Internal-representation" accesskey="n" rel="next">Internal representation</a>, Previous: <a href="#The-parsing-process" accesskey="p" rel="prev">The parsing process</a>, Up: <a href="#The-parsing-process" accesskey="u" rel="up">The parsing process</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Modes-of-parsing-1"></a>
<h4 class="subsection">10.1.1 Modes of parsing</h4>
<p>Parsing in R occurs in three different variants:
</p>
<ul>
<li> The read-eval-print loop
</li><li> Parsing of text files
</li><li> Parsing of character strings
</li></ul>
<p>The read-eval-print loop forms the basic command line interface to R.
Textual input is read until a complete R expression is available.
Expressions may be split over several input lines. The primary prompt
(by default ‘<samp>> </samp>’) indicates that the parser is ready for a new
expression, and a continuation prompt (by default ‘<samp>+ </samp>’) indicates
that the parser expects the remainder of an incomplete expression. The
expression is converted to internal form during input and the parsed
expression is passed to the evaluator and the result is printed (unless
specifically made invisible). If the parser finds itself in a state
which is incompatible with the language syntax, a “Syntax Error” is
flagged and the parser resets itself and resumes input at the beginning
of the next input line.
</p>
<p>Text files can be parsed using the <code>parse</code> function. In
particular, this is done during execution of the <code>source</code>
function, which allows commands to be stored in an external file and
executed as if they had been typed at the keyboard. Note, though, that
the entire file is parsed and syntax checked before any evaluation takes
place.
</p>
<p>Character strings, or vectors thereof, can be parsed using the
<code>text=</code> argument to <code>parse</code>. The strings are treated exactly
as if they were the lines of an input file.
</p>
<hr>
<a name="Internal-representation"></a>
<div class="header">
<p>
Next: <a href="#Deparsing" accesskey="n" rel="next">Deparsing</a>, Previous: <a href="#Modes-of-parsing" accesskey="p" rel="prev">Modes of parsing</a>, Up: <a href="#The-parsing-process" accesskey="u" rel="up">The parsing process</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Internal-representation-1"></a>
<h4 class="subsection">10.1.2 Internal representation</h4>
<a name="index-parsing-7"></a>
<p>Parsed expressions are stored in an R object containing the parse
tree. A fuller description of such objects can be found in
<a href="#Language-objects">Language objects</a> and <a href="#Expression-objects">Expression objects</a>. Briefly, every
elementary R expression is stored in
<a name="index-function-29"></a>
function call form, as a list
with the first element containing the function name and the remainder
containing the arguments, which may in turn be further R expressions.
The list elements can be named, corresponding to tagged matching of
formal and actual arguments. Note that <em>all</em> R syntax elements
are treated in this way, e.g. the assignment <code>x <- 1</code> is encoded
as <code>"<-"(x, 1)</code>.
</p>
<hr>
<a name="Deparsing"></a>
<div class="header">
<p>
Previous: <a href="#Internal-representation" accesskey="p" rel="prev">Internal representation</a>, Up: <a href="#The-parsing-process" accesskey="u" rel="up">The parsing process</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Deparsing-1"></a>
<h4 class="subsection">10.1.3 Deparsing</h4>
<p>Any R object can be converted to an R expression using
<code>deparse</code>. This is frequently used in connection with output of
results, e.g. for labeling plots. Notice that only objects of mode
<code>"expression"</code> can be expected to be unchanged by reparsing the
output of deparsing. For instance, the numeric vector <code>1:5</code> will
deparse as <code>"c(1, 2, 3, 4, 5)"</code>, which will reparse as a call to
the function <code>c</code>. As far as possible, evaluating the deparsed and
reparsed expression gives the same result as evaluating the original,
but there are a couple of awkward exceptions, mostly involving
expressions that weren’t generated from a textual representation in the
first place.
</p>
<hr>
<a name="Comments"></a>
<div class="header">
<p>
Next: <a href="#Tokens" accesskey="n" rel="next">Tokens</a>, Previous: <a href="#The-parsing-process" accesskey="p" rel="prev">The parsing process</a>, Up: <a href="#Parser" accesskey="u" rel="up">Parser</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Comments-1"></a>
<h3 class="section">10.2 Comments</h3>
<a name="index-comments"></a>
<p>Comments in R are ignored by the parser. Any text from a
<a name="index-_0023"></a>
<code>#</code> character
to the end of the line is taken to be a comment, unless
the <code>#</code> character is inside a quoted string. For example,
</p>
<div class="example">
<pre class="example">> x <- 1 # This is a comment...
> y <- " #... but this is not."
</pre></div>
<hr>
<a name="Tokens"></a>
<div class="header">
<p>
Next: <a href="#Expressions" accesskey="n" rel="next">Expressions</a>, Previous: <a href="#Comments" accesskey="p" rel="prev">Comments</a>, Up: <a href="#Parser" accesskey="u" rel="up">Parser</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Tokens-1"></a>
<h3 class="section">10.3 Tokens</h3>
<p>Tokens are the elementary building blocks of a programming language.
They are recognised during <em>lexical analysis</em> which (conceptually,
at least) takes place prior to the syntactic analysis performed by the
parser itself.
</p>
<table summary="" class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">• <a href="#Literal-constants" accesskey="1">Literal constants</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Identifiers" accesskey="2">Identifiers</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Reserved-words" accesskey="3">Reserved words</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Special-operators" accesskey="4">Special operators</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Separators" accesskey="5">Separators</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Operator-tokens" accesskey="6">Operator tokens</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Grouping" accesskey="7">Grouping</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Indexing-tokens" accesskey="8">Indexing tokens</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="Literal-constants"></a>
<div class="header">
<p>
Next: <a href="#Identifiers" accesskey="n" rel="next">Identifiers</a>, Previous: <a href="#Tokens" accesskey="p" rel="prev">Tokens</a>, Up: <a href="#Tokens" accesskey="u" rel="up">Tokens</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Constants-2"></a>
<h4 class="subsection">10.3.1 Constants</h4>
<p>There are five types of constants: integer, logical, numeric, complex and string.
</p>
<p>In addition, there are four special constants, <code>NULL</code>, <code>NA</code>,
<code>Inf</code>, and <code>NaN</code>.
</p>
<p><code>NULL</code> is used to indicate the empty object. <code>NA</code> is used for
absent (“Not Available”) data values. <code>Inf</code> denotes infinity and
<code>NaN</code> is not-a-number in the <acronym>IEEE</acronym> floating point calculus
(results of the operations respectively <em>1/0</em> and <em>0/0</em>, for
instance).
</p>
<p>Logical constants are either <code>TRUE</code> or <code>FALSE</code>.
</p>
<p>Numeric constants follow a similar syntax to that of the <strong>C</strong> language.
They consist of an integer part consisting of zero or more digits,
followed optionally by ‘<samp>.</samp>’ and a fractional part of zero or more
digits optionally followed by an exponent part consisting of an ‘<samp>E</samp>’
or an ‘<samp>e</samp>’, an optional sign and a string of one or more digits.
Either the fractional or the decimal part can be empty, but not both at
once.
</p>
<div class="example">
<pre class="example"><span class="roman">Valid numeric constants:</span> 1 10 0.1 .2 1e-7 1.2e+7
</pre></div>
<p>Numeric constants can also be hexadecimal, starting with ‘<samp>0x</samp>’ or
‘<samp>0x</samp>’ followed by zero or more digits, ‘<samp>a-f</samp>’ or ‘<samp>A-F</samp>’.
Hexadecimal floating point constants are supported using C99 syntax, e.g.
‘<samp>0x1.1p1</samp>’.
</p>
<p>There is now a separate class of integer constants. They are created
by using the qualifier <code>L</code> at the end of the number. For
example, <code>123L</code> gives an integer value rather than a numeric
value. The suffix <code>L</code> can be used to qualify any non-complex
number with the intent of creating an integer. So it can be used with
numbers given by hexadecimal or scientific notation. However, if the
value is not a valid integer, a warning is emitted and the numeric
value created. The following shows examples of valid integer
constants, values which will generate a warning and give numeric
constants and syntax errors.
</p>
<div class="example">
<pre class="example"><span class="roman">Valid integer constants:</span> 1L, 0x10L, 1000000L, 1e6L
<span class="roman">Valid numeric constants:</span> 1.1L, 1e-3L, 0x1.1p-2
<span class="roman">Syntax error:</span> 12iL 0x1.1
</pre></div>
<p>A warning is emitted for decimal values that contain an unnecessary
decimal point, e.g. <code>1.L</code>. It is an error to have a decimal
point in a hexadecimal constant without the binary exponent.
</p>
<p>Note also that a preceding sign (<code>+</code> or <code>-</code>) is treated as a
unary operator, not as part of the constant.
</p>
<p>Up-to-date information on the currently accepted formats can be found by
<code>?NumericConstants</code>.
</p>
<p>Complex constants have the form of a decimal numeric constant followed
by ‘<samp>i</samp>’. Notice that only purely imaginary numbers are actual
constants, other complex numbers are parsed a unary or binary operations
on numeric and imaginary numbers.
</p>
<div class="example">
<pre class="example"><span class="roman">Valid complex constants:</span> 2i 4.1i 1e-2i
</pre></div>
<p>String constants are delimited by a pair of single (‘<samp>'</samp>’) or double
(‘<samp>"</samp>’) quotes and can contain all other printable characters.
Quotes and other special characters within strings are specified using
<em>escape sequences</em>:
</p>
<dl compact="compact">
<dt><code>\'</code></dt>
<dd><p>single quote
</p></dd>
<dt><code>\"</code></dt>
<dd><p>double quote
</p></dd>
<dt><code>\n</code></dt>
<dd><p>newline
</p></dd>
<dt><code>\r</code></dt>
<dd><p>carriage return
</p></dd>
<dt><code>\t</code></dt>
<dd><p>tab character
</p></dd>
<dt><code>\b</code></dt>
<dd><p>backspace
</p></dd>
<dt><code>\a</code></dt>
<dd><p>bell
</p></dd>
<dt><code>\f</code></dt>
<dd><p>form feed
</p></dd>
<dt><code>\v</code></dt>
<dd><p>vertical tab
</p></dd>
<dt><code>\\</code></dt>
<dd><p>backslash itself
</p></dd>
<dt><code>\<var>nnn</var></code></dt>
<dd><p>character with given octal code – sequences of one, two or three digits
in the range <code>0 ... 7</code> are accepted.
</p></dd>
<dt><code>\x<var>nn</var></code></dt>
<dd><p>character with given hex code – sequences of one or two hex digits
(with entries <code>0 ... 9 A ... F a ... f</code>).
</p></dd>
<dt><code>\u<var>nnnn</var> \u{<var>nnnn</var>}</code></dt>
<dd><p>(where multibyte locales are supported, otherwise an error).
Unicode character with given hex code – sequences of up to four hex
digits. The character needs to be valid in the current locale.
</p></dd>
<dt><code>\U<var>nnnnnnnn</var> \U{<var>nnnnnnnn</var>}</code></dt>
<dd><p>(where multibyte locales are supported and not on Windows, otherwise an
error). Unicode character with given hex code – sequences of up to
eight hex digits.
</p></dd>
</dl>
<p>A single quote may also be embedded directly in a double-quote delimited
string and vice versa.
</p>
<p>A ‘nul’ (<code>\0</code>) is not allowed in a character string, so using
<code>\0</code> in a string constant terminates the constant (usually with a
warning): further characters up to the closing quote are scanned but
ignored.
</p>
<hr>
<a name="Identifiers"></a>
<div class="header">
<p>
Next: <a href="#Reserved-words" accesskey="n" rel="next">Reserved words</a>, Previous: <a href="#Literal-constants" accesskey="p" rel="prev">Literal constants</a>, Up: <a href="#Tokens" accesskey="u" rel="up">Tokens</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Identifiers-1"></a>
<h4 class="subsection">10.3.2 Identifiers</h4>
<a name="index-identifier"></a>
<p>Identifiers consist of a sequence of letters, digits, the period
(‘<samp>.</samp>’) and the underscore. They must not start with a digit or
an underscore, or with a period followed by a digit.
</p>
<p>The definition of a letter depends on the current locale: the precise
set of characters allowed is given by the C expression <code>(isalnum(c)
|| c == ‘.’ || c == ‘_’)</code> and will include accented letters in many
Western European locales.
</p>
<p>Notice that identifiers starting with a period are not by default listed
by the <code>ls</code> function and that ‘<samp>...</samp>’ and ‘<samp>..1</samp>’,
‘<samp>..2</samp>’, etc. are special.
</p>
<p>Notice also that objects can have names that are not identifiers. These
are generally accessed via <code>get</code> and <code>assign</code>, although they
can also be represented by text strings in some limited circumstances
when there is no ambiguity (e.g. <code>"x" <- 1</code>). As <code>get</code> and
<code>assign</code> are not restricted to names that are identifiers they do
not recognise subscripting operators or replacement functions. The
following pairs are <em>not</em> equivalent
<a name="index-get"></a>
<a name="index-assign"></a>
</p>
<blockquote>
<table summary="">
<tr><td><code>x$a<-1</code></td><td><code>assign("x$a",1)</code></td></tr>
<tr><td><code>x[[1]]</code></td><td><code>get("x[[1]]")</code></td></tr>
<tr><td><code>names(x)<-nm</code></td><td><code>assign("names(x)",nm)</code></td></tr>
</table>
</blockquote>
<hr>
<a name="Reserved-words"></a>
<div class="header">
<p>
Next: <a href="#Special-operators" accesskey="n" rel="next">Special operators</a>, Previous: <a href="#Identifiers" accesskey="p" rel="prev">Identifiers</a>, Up: <a href="#Tokens" accesskey="u" rel="up">Tokens</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Reserved-words-1"></a>
<h4 class="subsection">10.3.3 Reserved words</h4>
<p>The following identifiers have a special meaning and cannot be used
for object names
</p>
<div class="example">
<pre class="example">if else repeat while function for in next break
TRUE FALSE NULL Inf NaN
NA NA_integer_ NA_real_ NA_complex_ NA_character_
... ..1 ..2 <span class="roman">etc.</span>
</pre></div>
<hr>
<a name="Special-operators"></a>
<div class="header">
<p>
Next: <a href="#Separators" accesskey="n" rel="next">Separators</a>, Previous: <a href="#Reserved-words" accesskey="p" rel="prev">Reserved words</a>, Up: <a href="#Tokens" accesskey="u" rel="up">Tokens</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Special-operators-1"></a>
<h4 class="subsection">10.3.4 Special operators</h4>
<p>R allows user-defined infix operators. These have the form of a
string of characters delimited by the ‘<samp>%</samp>’ character. The string
can contain any printable character except ‘<samp>%</samp>’. The escape sequences
for strings do not apply here.
</p>
<p>Note that the following operators are predefined
</p>
<div class="example">
<pre class="example">%% %*% %/% %in% %o% %x%
</pre></div>
<hr>
<a name="Separators"></a>
<div class="header">
<p>
Next: <a href="#Operator-tokens" accesskey="n" rel="next">Operator tokens</a>, Previous: <a href="#Special-operators" accesskey="p" rel="prev">Special operators</a>, Up: <a href="#Tokens" accesskey="u" rel="up">Tokens</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Separators-1"></a>
<h4 class="subsection">10.3.5 Separators</h4>
<p>Although not strictly tokens, stretches of whitespace characters
(spaces, tabs and formfeeds, on Windows and UTF-8 locales other Unicode
whitespace characters<a name="DOCF4" href="#FOOT4"><sup>4</sup></a>) serve to delimit tokens in case of
ambiguity, (compare <code>x<-5</code> and <code>x < -5</code>).
</p>
<p>Newlines have a function which is a combination of token separator and
expression terminator. If an expression can terminate at the end of
the line the parser will assume it does so, otherwise the newline is
treated as whitespace. Semicolons (‘<samp>;</samp>’) may be used to separate
elementary
<a name="index-expression-2"></a>
expressions on the same line.
</p>
<p>Special rules apply to the <code>else</code> keyword: inside a compound
expression, a newline before <code>else</code> is discarded, whereas at the
outermost level, the newline terminates the <code>if</code> construction and a
subsequent <code>else</code> causes a syntax error. This somewhat anomalous
behaviour occurs because R should be usable in interactive mode and
then it must decide whether the input expression is complete,
incomplete, or invalid as soon as the user presses <tt class="key">RET</tt>.
</p>
<p>The comma (‘<samp>,</samp>’) is used to separate function arguments and multiple
indices.
</p>
<hr>
<a name="Operator-tokens"></a>
<div class="header">
<p>
Next: <a href="#Grouping" accesskey="n" rel="next">Grouping</a>, Previous: <a href="#Separators" accesskey="p" rel="prev">Separators</a>, Up: <a href="#Tokens" accesskey="u" rel="up">Tokens</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Operator-tokens-1"></a>
<h4 class="subsection">10.3.6 Operator tokens</h4>
<p>R uses the following operator tokens
</p>
<blockquote>
<table summary="">
<tr><td width="30%"><code>+ - * / %% ^</code></td><td width="60%">arithmetic</td></tr>
<tr><td width="30%"><code>> >= < <= == !=</code></td><td width="60%">relational</td></tr>
<tr><td width="30%"><code>! & |</code></td><td width="60%">logical</td></tr>
<tr><td width="30%"><code>~</code></td><td width="60%">model formulae</td></tr>
<tr><td width="30%"><code>-> <-</code></td><td width="60%">assignment</td></tr>
<tr><td width="30%"><code>$</code></td><td width="60%">list indexing</td></tr>
<tr><td width="30%"><code>:</code></td><td width="60%">sequence</td></tr>
</table>
</blockquote>
<p>(Several of the operators have different meaning inside model formulas)
</p>
<hr>
<a name="Grouping"></a>
<div class="header">
<p>
Next: <a href="#Indexing-tokens" accesskey="n" rel="next">Indexing tokens</a>, Previous: <a href="#Operator-tokens" accesskey="p" rel="prev">Operator tokens</a>, Up: <a href="#Tokens" accesskey="u" rel="up">Tokens</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Grouping-1"></a>
<h4 class="subsection">10.3.7 Grouping</h4>
<p>Ordinary parentheses—‘<samp>(</samp>’ and ‘<samp>)</samp>’—are used for explicit
grouping within expressions and to delimit the argument lists for
function definitions and function calls.
</p>
<p>Braces—‘<samp>{</samp>’ and ‘<samp>}</samp>’—delimit blocks of expressions in
function definitions, conditional expressions, and iterative constructs.
</p>
<hr>
<a name="Indexing-tokens"></a>
<div class="header">
<p>
Previous: <a href="#Grouping" accesskey="p" rel="prev">Grouping</a>, Up: <a href="#Tokens" accesskey="u" rel="up">Tokens</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Indexing-tokens-1"></a>
<h4 class="subsection">10.3.8 Indexing tokens</h4>
<p>Indexing of arrays and vectors is performed using the single and double
brackets, ‘<samp>[]</samp>’ and ‘<samp>[[]]</samp>’. Also, indexing tagged lists
may be done using the ‘<samp>$</samp>’ operator.
</p>
<hr>
<a name="Expressions"></a>
<div class="header">
<p>
Next: <a href="#Directives" accesskey="n" rel="next">Directives</a>, Previous: <a href="#Tokens" accesskey="p" rel="prev">Tokens</a>, Up: <a href="#Parser" accesskey="u" rel="up">Parser</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Expressions-1"></a>
<h3 class="section">10.4 Expressions</h3>
<p>An R program consists of a sequence of R expressions. An
expression can be a simple expression consisting of only a constant or
an identifier, or it can be a compound expression constructed from other
parts (which may themselves be expressions).
</p>
<p>The following sections detail the various syntactical constructs that
are available.
</p>
<table summary="" class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">• <a href="#Function-calls-_0028expressions_0029" accesskey="1">Function calls (expressions)</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Infix-and-prefix-operators" accesskey="2">Infix and prefix operators</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Index-constructions" accesskey="3">Index constructions</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Compound-expressions" accesskey="4">Compound expressions</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Flow-control-elements" accesskey="5">Flow control elements</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top">• <a href="#Function-definitions" accesskey="6">Function definitions</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="Function-calls-_0028expressions_0029"></a>
<div class="header">
<p>
Next: <a href="#Infix-and-prefix-operators" accesskey="n" rel="next">Infix and prefix operators</a>, Previous: <a href="#Expressions" accesskey="p" rel="prev">Expressions</a>, Up: <a href="#Expressions" accesskey="u" rel="up">Expressions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Function-calls-2"></a>
<h4 class="subsection">10.4.1 Function calls</h4>
<a name="index-function-30"></a>
<p>A function call takes the form of a function reference followed by a
comma-separated list of arguments within a set of parentheses.
</p>
<div class="example">
<pre class="example"><var>function_reference</var> ( <var>arg1</var>, <var>arg2</var>, ...... , <var>argn</var> )
</pre></div>
<p>The function reference can be either
</p><ul>
<li> an identifier (the name of the function)
</li><li> a text string (ditto, but handy if the function has a name which is not
a valid identifier)
</li><li> an expression (which should evaluate to a function object)
</li></ul>
<p>Each argument can be tagged (<code><var>tag</var>=<var>expr</var></code>), or just be a
simple expression. It can also be empty or it can be one of the special
tokens ‘<samp>...</samp>’, ‘<samp>..2</samp>’, etc.
</p>
<p>A tag can be an identifier or a text string.
</p>
<p>Examples:
</p>
<div class="example">
<pre class="example">f(x)
g(tag = value, , 5)
"odd name"("strange tag" = 5, y)
(function(x) x^2)(5)
</pre></div>
<hr>
<a name="Infix-and-prefix-operators"></a>
<div class="header">
<p>
Next: <a href="#Index-constructions" accesskey="n" rel="next">Index constructions</a>, Previous: <a href="#Function-calls-_0028expressions_0029" accesskey="p" rel="prev">Function calls (expressions)</a>, Up: <a href="#Expressions" accesskey="u" rel="up">Expressions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Infix-and-prefix-operators-1"></a>
<h4 class="subsection">10.4.2 Infix and prefix operators</h4>
<p>The order of precedence (highest first) of the operators is
</p>
<div class="example">
<pre class="example">::
$ @
^
- + <span class="roman">(unary)</span>
:
%<var>xyz</var>%
* /
+ - <span class="roman">(binary)</span>
> >= < <= == !=
!
& &&
| ||
~ <span class="roman">(unary and binary)</span>
-> ->>
= <span class="roman">(as assignment)</span>
<- <<-
</pre></div>
<p>Note that <code>:</code> precedes binary +/-, but not <code>^</code>. Hence,
<code>1:3-1</code> is <em>0 1 2</em>, but <code>1:2^3</code> is <code>1:8</code>.
</p>
<p>The exponentiation operator ‘<samp>^</samp>’ and the
<a name="index-assignment-11"></a>
left assignment plus minus operators
‘<samp><- - = <<-</samp>’ group right to left, all other operators group left to
right. That is, <code>2 ^ 2 ^ 3</code> is <em>2 ^ 8</em>, not <em>4 ^ 3</em>,
whereas <code>1 - 1 - 1</code> is <em>-1</em>, not 1.
</p>
<p>Notice that the operators <code>%%</code> and <code>%/%</code> for integer
remainder and divide have higher precedence than multiply and divide.
</p>
<p>Although it is not strictly an operator, it also needs mentioning that
the ‘<samp>=</samp>’ sign is used for tagging arguments in
function calls and
for assigning default values in function definitions.
</p>
<p>The ‘<samp>$</samp>’ sign is in some sense an operator, but does not allow
arbitrary right hand sides and is discussed under <a href="#Index-constructions">Index constructions</a>. It has higher precedence than any of the other
operators.
</p>
<p>The parsed form of a unary or binary operation is completely equivalent
to a function call with the operator as the function name and the
operands as the function arguments.
</p>
<p>Parentheses are recorded as equivalent to a unary operator, with name
<code>"("</code>, even in cases where the parentheses could be inferred from
operator precedence (e.g., <code>a * (b + c)</code>).
</p>
<p>Notice that the
<a name="index-assignment-12"></a>
assignment symbols are operators just like the arithmetic, relational,
and logical ones. Any expression is allowed also on the target side of
an assignment, as far as the parser is concerned (<code>2 + 2 <- 5</code> is a
valid expression as far as the parser is concerned. The evaluator will
object, though). Similar comments apply to the model formula operator.
</p>
<hr>
<a name="Index-constructions"></a>
<div class="header">
<p>
Next: <a href="#Compound-expressions" accesskey="n" rel="next">Compound expressions</a>, Previous: <a href="#Infix-and-prefix-operators" accesskey="p" rel="prev">Infix and prefix operators</a>, Up: <a href="#Expressions" accesskey="u" rel="up">Expressions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Index-constructions-1"></a>
<h4 class="subsection">10.4.3 Index constructions</h4>
<p>R has three indexing constructs, two of which are syntactically
similar although with somewhat different semantics:
</p>
<div class="example">
<pre class="example"><var>object</var> [ <var>arg1</var>, ...... , <var>argn</var> ]
<var>object</var> [[ <var>arg1</var>, ...... , <var>argn</var> ]]
</pre></div>
<a name="index-_005b-1"></a>
<a name="index-_005b_005b-1"></a>
<p>The <var>object</var> can formally be any valid expression, but it is
understood to denote or evaluate to a subsettable object. The arguments
generally evaluate to numerical or character indices, but other kinds of
arguments are possible (notably <code>drop = FALSE</code>).
</p>
<p>Internally, these index constructs are stored as function calls with
function name <code>"["</code> respectively <code>"[["</code>.
</p>
<p>The third index construction is
</p>
<div class="example">
<pre class="example"><var>object</var> $ <var>tag</var>
</pre></div>
<a name="index-_0024-1"></a>
<p>Here, <var>object</var> is as above, whereas <var>tag</var> is an identifier or a
text string. Internally, it is stored as a function call with name
<code>"$"</code>
</p>
<hr>
<a name="Compound-expressions"></a>
<div class="header">
<p>
Next: <a href="#Flow-control-elements" accesskey="n" rel="next">Flow control elements</a>, Previous: <a href="#Index-constructions" accesskey="p" rel="prev">Index constructions</a>, Up: <a href="#Expressions" accesskey="u" rel="up">Expressions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Compound-expressions-1"></a>
<h4 class="subsection">10.4.4 Compound expressions</h4>
<p>A compound expression is of the form
</p>
<div class="example">
<pre class="example">{ <var>expr1</var> ; <var>expr2</var> ; ...... ; <var>exprn</var> }
</pre></div>
<p>The semicolons may be replaced by newlines. Internally, this is stored
as a function call with <code>"{"</code> as the function name and the
expressions as arguments.
</p>
<hr>
<a name="Flow-control-elements"></a>
<div class="header">
<p>
Next: <a href="#Function-definitions" accesskey="n" rel="next">Function definitions</a>, Previous: <a href="#Compound-expressions" accesskey="p" rel="prev">Compound expressions</a>, Up: <a href="#Expressions" accesskey="u" rel="up">Expressions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Flow-control-elements-1"></a>
<h4 class="subsection">10.4.5 Flow control elements</h4>
<p>R contains the following control structures as special syntactic
constructs
</p>
<div class="example">
<pre class="example">if ( <var>cond</var> ) <var>expr</var>
if ( <var>cond</var> ) <var>expr1</var> else <var>expr2</var>
while ( <var>cond</var> ) <var>expr</var>
repeat <var>expr</var>
for ( <var>var</var> in <var>list</var> ) <var>expr</var>
</pre></div>
<p>The expressions in these constructs will typically be compound
expressions.
</p>
<p>Within the loop constructs (<code>while</code>, <code>repeat</code>, <code>for</code>),
one may use <code>break</code> (to terminate the loop) and <code>next</code> (to
skip to the next iteration).
</p>
<p>Internally, the constructs are stored as function calls:
</p>
<div class="example">
<pre class="example">"if"(<var>cond</var>, <var>expr</var>)
"if"(<var>cond</var>, <var>expr1</var>, <var>expr2</var>)
"while"(<var>cond</var>, <var>expr</var>)
"repeat"(<var>expr</var>)
"for"(<var>var</var>, <var>list</var>, <var>expr</var>)
"break"()
"next"()
</pre></div>
<hr>
<a name="Function-definitions"></a>
<div class="header">
<p>
Previous: <a href="#Flow-control-elements" accesskey="p" rel="prev">Flow control elements</a>, Up: <a href="#Expressions" accesskey="u" rel="up">Expressions</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Function-definitions-1"></a>
<h4 class="subsection">10.4.6 Function definitions</h4>
<p>A
<a name="index-function-31"></a>
function definition is of the form
</p>
<div class="example">
<pre class="example">function ( <var>arglist</var> ) <var>body</var>
</pre></div>
<p>The function body is an expression, often a compound expression. The
<var>arglist</var> is a comma-separated list of items each of which can be an
identifier, or of the form ‘<samp><var>identifier</var> = <var>default</var></samp>’, or
the special token ‘<samp>...</samp>’. The <var>default</var> can be any valid
expression.
</p>
<p>Notice that function arguments unlike list tags, etc., cannot have
“strange names” given as text strings.
</p>
<p>Internally, a function definition is stored as a function call with
function name <code>function</code> and two arguments, the <var>arglist</var> and
the <var>body</var>. The <var>arglist</var> is stored as a tagged pairlist where
the tags are the argument names and the values are the default
expressions.
</p>
<hr>
<a name="Directives"></a>
<div class="header">
<p>
Previous: <a href="#Expressions" accesskey="p" rel="prev">Expressions</a>, Up: <a href="#Parser" accesskey="u" rel="up">Parser</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Directives-1"></a>
<h3 class="section">10.5 Directives</h3>
<a name="index-_0023line"></a>
<p>The parser currently only supports one directive, <code>#line</code>.
This is similar to the C-preprocessor directive of the same name. The
syntax is
</p>
<div class="example">
<pre class="example"><var>#line</var> <var>nn</var> [ <code>"filename"</code> ]
</pre></div>
<p>where <var>nn</var> is an integer line number, and the optional <var>filename</var>
(in required double quotes) names the source file.
</p>
<p>Unlike the C directive, <code>#line</code> must appear as the first five characters
on a line. As in C, <var>nn</var> and <code>"filename"</code> entries may be separated
from it by whitespace. And unlike C, any following text on the line will be
treated as a comment and ignored.
</p>
<p>This directive tells the parser that the following line should be assumed to
be line <var>nn</var> of file <var>filename</var>. (If the filename is not given,
it is assumed to be the same as for the previous directive.) This is not
typically used by users, but may be used by preprocessors so that
diagnostic messages refer to the original file.
</p>
<hr>
<a name="Function-and-Variable-Index"></a>
<div class="header">
<p>
Next: <a href="#Concept-Index" accesskey="n" rel="next">Concept Index</a>, Previous: <a href="#Parser" accesskey="p" rel="prev">Parser</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Function-and-Variable-Index-1"></a>
<h2 class="unnumbered">Function and Variable Index</h2>
<table summary=""><tr><th valign="top">Jump to: </th><td><a class="summary-letter" href="#Function-and-Variable-Index_vr_symbol-1"><b>#</b></a>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_symbol-2"><b>$</b></a>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_symbol-3"><b>.</b></a>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_symbol-4"><b>[</b></a>
<br>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_letter-A"><b>A</b></a>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_letter-B"><b>B</b></a>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_letter-D"><b>D</b></a>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_letter-E"><b>E</b></a>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_letter-F"><b>F</b></a>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_letter-G"><b>G</b></a>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_letter-I"><b>I</b></a>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_letter-M"><b>M</b></a>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_letter-N"><b>N</b></a>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_letter-O"><b>O</b></a>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_letter-P"><b>P</b></a>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_letter-Q"><b>Q</b></a>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_letter-R"><b>R</b></a>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_letter-S"><b>S</b></a>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_letter-T"><b>T</b></a>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_letter-U"><b>U</b></a>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_letter-W"><b>W</b></a>
</td></tr></table>
<table summary="" class="index-vr" border="0">
<tr><td></td><th align="left">Index Entry</th><td> </td><th align="left"> Section</th></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Function-and-Variable-Index_vr_symbol-1">#</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_0023"><code>#</code></a>:</td><td> </td><td valign="top"><a href="#Comments">Comments</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Function-and-Variable-Index_vr_symbol-2">$</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_0024"><code>$</code></a>:</td><td> </td><td valign="top"><a href="#Indexing">Indexing</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_0024-1"><code>$</code></a>:</td><td> </td><td valign="top"><a href="#Index-constructions">Index constructions</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Function-and-Variable-Index_vr_symbol-3">.</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_002eC"><code>.C</code></a>:</td><td> </td><td valign="top"><a href="#Foreign-language-interfaces">Foreign language interfaces</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_002eCall"><code>.Call</code></a>:</td><td> </td><td valign="top"><a href="#Foreign-language-interfaces">Foreign language interfaces</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_002eExternal"><code>.External</code></a>:</td><td> </td><td valign="top"><a href="#Foreign-language-interfaces">Foreign language interfaces</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_002eFortran"><code>.Fortran</code></a>:</td><td> </td><td valign="top"><a href="#Foreign-language-interfaces">Foreign language interfaces</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_002eInternal-1"><code>.Internal</code></a>:</td><td> </td><td valign="top"><a href="#g_t_002eInternal-and-_002ePrimitive">.Internal and .Primitive</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_002ePrimitive-1"><code>.Primitive</code></a>:</td><td> </td><td valign="top"><a href="#g_t_002eInternal-and-_002ePrimitive">.Internal and .Primitive</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Function-and-Variable-Index_vr_symbol-4">[</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_005b"><code>[</code></a>:</td><td> </td><td valign="top"><a href="#Indexing">Indexing</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_005b-1"><code>[</code></a>:</td><td> </td><td valign="top"><a href="#Index-constructions">Index constructions</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_005b_005b"><code>[[</code></a>:</td><td> </td><td valign="top"><a href="#Indexing">Indexing</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_005b_005b-1"><code>[[</code></a>:</td><td> </td><td valign="top"><a href="#Index-constructions">Index constructions</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Function-and-Variable-Index_vr_letter-A">A</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-as_002ecall"><code>as.call</code></a>:</td><td> </td><td valign="top"><a href="#Language-objects">Language objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-as_002echaracter"><code>as.character</code></a>:</td><td> </td><td valign="top"><a href="#Symbol-objects">Symbol objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-as_002efunction"><code>as.function</code></a>:</td><td> </td><td valign="top"><a href="#Function-objects">Function objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-as_002elist"><code>as.list</code></a>:</td><td> </td><td valign="top"><a href="#Language-objects">Language objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-as_002ename"><code>as.name</code></a>:</td><td> </td><td valign="top"><a href="#Symbol-objects">Symbol objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-assign"><code>assign</code></a>:</td><td> </td><td valign="top"><a href="#Identifiers">Identifiers</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-attr"><code>attr</code></a>:</td><td> </td><td valign="top"><a href="#Attributes">Attributes</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-attr_003c_002d"><code>attr<-</code></a>:</td><td> </td><td valign="top"><a href="#Attributes">Attributes</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-attributes-1"><code>attributes</code></a>:</td><td> </td><td valign="top"><a href="#Attributes">Attributes</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-attributes_003c_002d"><code>attributes<-</code></a>:</td><td> </td><td valign="top"><a href="#Attributes">Attributes</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Function-and-Variable-Index_vr_letter-B">B</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-baseenv"><code>baseenv</code></a>:</td><td> </td><td valign="top"><a href="#Environment-objects">Environment objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-basename"><code>basename</code></a>:</td><td> </td><td valign="top"><a href="#Operating-system-access">Operating system access</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-body"><code>body</code></a>:</td><td> </td><td valign="top"><a href="#Function-objects">Function objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-body-1"><code>body</code></a>:</td><td> </td><td valign="top"><a href="#Manipulation-of-functions">Manipulation of functions</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-body_003c_002d"><code>body<-</code></a>:</td><td> </td><td valign="top"><a href="#Manipulation-of-functions">Manipulation of functions</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-break"><code>break</code></a>:</td><td> </td><td valign="top"><a href="#Looping">Looping</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-browser"><code>browser</code></a>:</td><td> </td><td valign="top"><a href="#browser">browser</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Function-and-Variable-Index_vr_letter-D">D</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-debug"><code>debug</code></a>:</td><td> </td><td valign="top"><a href="#debug_002fundebug">debug/undebug</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dirname"><code>dirname</code></a>:</td><td> </td><td valign="top"><a href="#Operating-system-access">Operating system access</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-do_002ecall"><code>do.call</code></a>:</td><td> </td><td valign="top"><a href="#Manipulation-of-function-calls">Manipulation of function calls</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Function-and-Variable-Index_vr_letter-E">E</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-emptyenv"><code>emptyenv</code></a>:</td><td> </td><td valign="top"><a href="#Environment-objects">Environment objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-environment-20"><code>environment</code></a>:</td><td> </td><td valign="top"><a href="#Function-objects">Function objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-environment-21"><code>environment</code></a>:</td><td> </td><td valign="top"><a href="#Manipulation-of-functions">Manipulation of functions</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-environment_003c_002d"><code>environment<-</code></a>:</td><td> </td><td valign="top"><a href="#Manipulation-of-functions">Manipulation of functions</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-eval"><code>eval</code></a>:</td><td> </td><td valign="top"><a href="#More-on-evaluation">More on evaluation</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Function-and-Variable-Index_vr_letter-F">F</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-file_002eaccess"><code>file.access</code></a>:</td><td> </td><td valign="top"><a href="#Operating-system-access">Operating system access</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-file_002eappend"><code>file.append</code></a>:</td><td> </td><td valign="top"><a href="#Operating-system-access">Operating system access</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-file_002echoose"><code>file.choose</code></a>:</td><td> </td><td valign="top"><a href="#Operating-system-access">Operating system access</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-file_002ecopy"><code>file.copy</code></a>:</td><td> </td><td valign="top"><a href="#Operating-system-access">Operating system access</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-file_002ecreate"><code>file.create</code></a>:</td><td> </td><td valign="top"><a href="#Operating-system-access">Operating system access</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-file_002eexists"><code>file.exists</code></a>:</td><td> </td><td valign="top"><a href="#Operating-system-access">Operating system access</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-file_002einfo"><code>file.info</code></a>:</td><td> </td><td valign="top"><a href="#Operating-system-access">Operating system access</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-file_002epath"><code>file.path</code></a>:</td><td> </td><td valign="top"><a href="#Operating-system-access">Operating system access</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-file_002eremove"><code>file.remove</code></a>:</td><td> </td><td valign="top"><a href="#Operating-system-access">Operating system access</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-file_002erename"><code>file.rename</code></a>:</td><td> </td><td valign="top"><a href="#Operating-system-access">Operating system access</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-file_002eshow"><code>file.show</code></a>:</td><td> </td><td valign="top"><a href="#Operating-system-access">Operating system access</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-for"><code>for</code></a>:</td><td> </td><td valign="top"><a href="#for">for</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-formals"><code>formals</code></a>:</td><td> </td><td valign="top"><a href="#Function-objects">Function objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-formals-1"><code>formals</code></a>:</td><td> </td><td valign="top"><a href="#Manipulation-of-functions">Manipulation of functions</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-formals_003c_002d"><code>formals<-</code></a>:</td><td> </td><td valign="top"><a href="#Manipulation-of-functions">Manipulation of functions</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Function-and-Variable-Index_vr_letter-G">G</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-get"><code>get</code></a>:</td><td> </td><td valign="top"><a href="#Identifiers">Identifiers</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Function-and-Variable-Index_vr_letter-I">I</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-is_002ena"><code>is.na</code></a>:</td><td> </td><td valign="top"><a href="#NA-handling">NA handling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-is_002enan"><code>is.nan</code></a>:</td><td> </td><td valign="top"><a href="#NA-handling">NA handling</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Function-and-Variable-Index_vr_letter-M">M</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-match_002earg"><code>match.arg</code></a>:</td><td> </td><td valign="top"><a href="#Argument-matching">Argument matching</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-match_002ecall"><code>match.call</code></a>:</td><td> </td><td valign="top"><a href="#Argument-matching">Argument matching</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-match_002ecall-1"><code>match.call</code></a>:</td><td> </td><td valign="top"><a href="#Manipulation-of-function-calls">Manipulation of function calls</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-match_002efun"><code>match.fun</code></a>:</td><td> </td><td valign="top"><a href="#Argument-matching">Argument matching</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-missing"><code>missing</code></a>:</td><td> </td><td valign="top"><a href="#NA-handling">NA handling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mode-3"><code>mode</code></a>:</td><td> </td><td valign="top"><a href="#Objects">Objects</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Function-and-Variable-Index_vr_letter-N">N</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-NA"><code>NA</code></a>:</td><td> </td><td valign="top"><a href="#NA-handling">NA handling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-NA-1"><code>NA</code></a>:</td><td> </td><td valign="top"><a href="#Indexing-by-vectors">Indexing by vectors</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-names"><code>names</code></a>:</td><td> </td><td valign="top"><a href="#Names">Names</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-names_003c_002d"><code>names<-</code></a>:</td><td> </td><td valign="top"><a href="#Names">Names</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-NaN"><code>NaN</code></a>:</td><td> </td><td valign="top"><a href="#NA-handling">NA handling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-new_002eenv"><code>new.env</code></a>:</td><td> </td><td valign="top"><a href="#Environment-objects">Environment objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-next"><code>next</code></a>:</td><td> </td><td valign="top"><a href="#Looping">Looping</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-NextMethod"><code>NextMethod</code></a>:</td><td> </td><td valign="top"><a href="#NextMethod">NextMethod</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-NULL"><code>NULL</code></a>:</td><td> </td><td valign="top"><a href="#NULL-object">NULL object</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Function-and-Variable-Index_vr_letter-O">O</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-on_002eexit"><code>on.exit</code></a>:</td><td> </td><td valign="top"><a href="#on_002eexit">on.exit</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Function-and-Variable-Index_vr_letter-P">P</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-pairlist"><code>pairlist</code></a>:</td><td> </td><td valign="top"><a href="#Pairlist-objects">Pairlist objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-path_002eexpand"><code>path.expand</code></a>:</td><td> </td><td valign="top"><a href="#Operating-system-access">Operating system access</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-proc_002etime"><code>proc.time</code></a>:</td><td> </td><td valign="top"><a href="#Operating-system-access">Operating system access</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Function-and-Variable-Index_vr_letter-Q">Q</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-quote"><code>quote</code></a>:</td><td> </td><td valign="top"><a href="#Language-objects">Language objects</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Function-and-Variable-Index_vr_letter-R">R</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-repeat"><code>repeat</code></a>:</td><td> </td><td valign="top"><a href="#repeat">repeat</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Function-and-Variable-Index_vr_letter-S">S</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-stop"><code>stop</code></a>:</td><td> </td><td valign="top"><a href="#stop">stop</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-storage_002emode"><code>storage.mode</code></a>:</td><td> </td><td valign="top"><a href="#Objects">Objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-substitute"><code>substitute</code></a>:</td><td> </td><td valign="top"><a href="#Substitutions">Substitutions</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-switch"><code>switch</code></a>:</td><td> </td><td valign="top"><a href="#switch">switch</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-Sys_002egetenv"><code>Sys.getenv</code></a>:</td><td> </td><td valign="top"><a href="#Operating-system-access">Operating system access</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-Sys_002egetlocale"><code>Sys.getlocale</code></a>:</td><td> </td><td valign="top"><a href="#Operating-system-access">Operating system access</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-Sys_002elocaleconv"><code>Sys.localeconv</code></a>:</td><td> </td><td valign="top"><a href="#Operating-system-access">Operating system access</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-Sys_002eputenv"><code>Sys.putenv</code></a>:</td><td> </td><td valign="top"><a href="#Operating-system-access">Operating system access</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-Sys_002eputlocale"><code>Sys.putlocale</code></a>:</td><td> </td><td valign="top"><a href="#Operating-system-access">Operating system access</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-Sys_002etime"><code>Sys.time</code></a>:</td><td> </td><td valign="top"><a href="#Operating-system-access">Operating system access</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-Sys_002etimezone"><code>Sys.timezone</code></a>:</td><td> </td><td valign="top"><a href="#Operating-system-access">Operating system access</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-system"><code>system</code></a>:</td><td> </td><td valign="top"><a href="#Operating-system-access">Operating system access</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-system_002etime"><code>system.time</code></a>:</td><td> </td><td valign="top"><a href="#Operating-system-access">Operating system access</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Function-and-Variable-Index_vr_letter-T">T</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-trace"><code>trace</code></a>:</td><td> </td><td valign="top"><a href="#trace_002funtrace">trace/untrace</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-traceback"><code>traceback</code></a>:</td><td> </td><td valign="top"><a href="#traceback">traceback</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-typeof"><code>typeof</code></a>:</td><td> </td><td valign="top"><a href="#Objects">Objects</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Function-and-Variable-Index_vr_letter-U">U</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-undebug"><code>undebug</code></a>:</td><td> </td><td valign="top"><a href="#debug_002fundebug">debug/undebug</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-unlink"><code>unlink</code></a>:</td><td> </td><td valign="top"><a href="#Operating-system-access">Operating system access</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-untrace"><code>untrace</code></a>:</td><td> </td><td valign="top"><a href="#trace_002funtrace">trace/untrace</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-UseMethod"><code>UseMethod</code></a>:</td><td> </td><td valign="top"><a href="#UseMethod">UseMethod</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Function-and-Variable-Index_vr_letter-W">W</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-warning"><code>warning</code></a>:</td><td> </td><td valign="top"><a href="#warning">warning</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-warnings"><code>warnings</code></a>:</td><td> </td><td valign="top"><a href="#warning">warning</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-while"><code>while</code></a>:</td><td> </td><td valign="top"><a href="#while">while</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
</table>
<table summary=""><tr><th valign="top">Jump to: </th><td><a class="summary-letter" href="#Function-and-Variable-Index_vr_symbol-1"><b>#</b></a>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_symbol-2"><b>$</b></a>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_symbol-3"><b>.</b></a>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_symbol-4"><b>[</b></a>
<br>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_letter-A"><b>A</b></a>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_letter-B"><b>B</b></a>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_letter-D"><b>D</b></a>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_letter-E"><b>E</b></a>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_letter-F"><b>F</b></a>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_letter-G"><b>G</b></a>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_letter-I"><b>I</b></a>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_letter-M"><b>M</b></a>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_letter-N"><b>N</b></a>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_letter-O"><b>O</b></a>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_letter-P"><b>P</b></a>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_letter-Q"><b>Q</b></a>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_letter-R"><b>R</b></a>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_letter-S"><b>S</b></a>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_letter-T"><b>T</b></a>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_letter-U"><b>U</b></a>
<a class="summary-letter" href="#Function-and-Variable-Index_vr_letter-W"><b>W</b></a>
</td></tr></table>
<hr>
<a name="Concept-Index"></a>
<div class="header">
<p>
Next: <a href="#References" accesskey="n" rel="next">References</a>, Previous: <a href="#Function-and-Variable-Index" accesskey="p" rel="prev">Function and Variable Index</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="Concept-Index-1"></a>
<h2 class="unnumbered">Concept Index</h2>
<table summary=""><tr><th valign="top">Jump to: </th><td><a class="summary-letter" href="#Concept-Index_cp_symbol-1"><b>#</b></a>
<a class="summary-letter" href="#Concept-Index_cp_symbol-2"><b>.</b></a>
<br>
<a class="summary-letter" href="#Concept-Index_cp_letter-A"><b>A</b></a>
<a class="summary-letter" href="#Concept-Index_cp_letter-B"><b>B</b></a>
<a class="summary-letter" href="#Concept-Index_cp_letter-C"><b>C</b></a>
<a class="summary-letter" href="#Concept-Index_cp_letter-E"><b>E</b></a>
<a class="summary-letter" href="#Concept-Index_cp_letter-F"><b>F</b></a>
<a class="summary-letter" href="#Concept-Index_cp_letter-I"><b>I</b></a>
<a class="summary-letter" href="#Concept-Index_cp_letter-M"><b>M</b></a>
<a class="summary-letter" href="#Concept-Index_cp_letter-N"><b>N</b></a>
<a class="summary-letter" href="#Concept-Index_cp_letter-O"><b>O</b></a>
<a class="summary-letter" href="#Concept-Index_cp_letter-P"><b>P</b></a>
<a class="summary-letter" href="#Concept-Index_cp_letter-S"><b>S</b></a>
<a class="summary-letter" href="#Concept-Index_cp_letter-T"><b>T</b></a>
<a class="summary-letter" href="#Concept-Index_cp_letter-V"><b>V</b></a>
</td></tr></table>
<table summary="" class="index-cp" border="0">
<tr><td></td><th align="left">Index Entry</th><td> </td><th align="left"> Section</th></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Concept-Index_cp_symbol-1">#</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_0023line">#line</a>:</td><td> </td><td valign="top"><a href="#Directives">Directives</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Concept-Index_cp_symbol-2">.</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_002eInternal">.Internal</a>:</td><td> </td><td valign="top"><a href="#Builtin-objects-and-special-forms">Builtin objects and special forms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_002ePrimitive">.Primitive</a>:</td><td> </td><td valign="top"><a href="#Builtin-objects-and-special-forms">Builtin objects and special forms</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Concept-Index_cp_letter-A">A</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-argument">argument</a>:</td><td> </td><td valign="top"><a href="#Function-objects">Function objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-argument-1">argument</a>:</td><td> </td><td valign="top"><a href="#Syntax-and-examples">Syntax and examples</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-argument_002c-default-values">argument, default values</a>:</td><td> </td><td valign="top"><a href="#Arguments">Arguments</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-assignment">assignment</a>:</td><td> </td><td valign="top"><a href="#Function-objects">Function objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-assignment-1">assignment</a>:</td><td> </td><td valign="top"><a href="#Function-calls">Function calls</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-assignment-2">assignment</a>:</td><td> </td><td valign="top"><a href="#Operators">Operators</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-assignment-3">assignment</a>:</td><td> </td><td valign="top"><a href="#Subset-assignment">Subset assignment</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-assignment-4">assignment</a>:</td><td> </td><td valign="top"><a href="#Global-environment">Global environment</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-assignment-5">assignment</a>:</td><td> </td><td valign="top"><a href="#Argument-evaluation">Argument evaluation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-assignment-6">assignment</a>:</td><td> </td><td valign="top"><a href="#Scope">Scope</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-assignment-7">assignment</a>:</td><td> </td><td valign="top"><a href="#UseMethod">UseMethod</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-assignment-8">assignment</a>:</td><td> </td><td valign="top"><a href="#UseMethod">UseMethod</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-assignment-9">assignment</a>:</td><td> </td><td valign="top"><a href="#More-on-evaluation">More on evaluation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-assignment-10">assignment</a>:</td><td> </td><td valign="top"><a href="#Manipulation-of-function-calls">Manipulation of function calls</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-assignment-11">assignment</a>:</td><td> </td><td valign="top"><a href="#Infix-and-prefix-operators">Infix and prefix operators</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-assignment-12">assignment</a>:</td><td> </td><td valign="top"><a href="#Infix-and-prefix-operators">Infix and prefix operators</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atomic">atomic</a>:</td><td> </td><td valign="top"><a href="#Vector-objects">Vector objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-attributes">attributes</a>:</td><td> </td><td valign="top"><a href="#Attributes">Attributes</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Concept-Index_cp_letter-B">B</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-binding">binding</a>:</td><td> </td><td valign="top"><a href="#Scope">Scope</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-binding-1">binding</a>:</td><td> </td><td valign="top"><a href="#Scope">Scope</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Concept-Index_cp_letter-C">C</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-call">call</a>:</td><td> </td><td valign="top"><a href="#Language-objects">Language objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-call-stack">call stack</a>:</td><td> </td><td valign="top"><a href="#Stacks">Stacks</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-coercion">coercion</a>:</td><td> </td><td valign="top"><a href="#Objects">Objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-coercion-1">coercion</a>:</td><td> </td><td valign="top"><a href="#Symbol-objects">Symbol objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-coercion-2">coercion</a>:</td><td> </td><td valign="top"><a href="#Any_002dtype">Any-type</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-coercion-3">coercion</a>:</td><td> </td><td valign="top"><a href="#Classes">Classes</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-coercion-4">coercion</a>:</td><td> </td><td valign="top"><a href="#NA-handling">NA handling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-comments">comments</a>:</td><td> </td><td valign="top"><a href="#Comments">Comments</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-complex-assignment">complex assignment</a>:</td><td> </td><td valign="top"><a href="#Subset-assignment">Subset assignment</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Concept-Index_cp_letter-E">E</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-environment">environment</a>:</td><td> </td><td valign="top"><a href="#Function-objects">Function objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-environment-1">environment</a>:</td><td> </td><td valign="top"><a href="#Function-objects">Function objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-environment-2">environment</a>:</td><td> </td><td valign="top"><a href="#Promise-objects">Promise objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-environment-3">environment</a>:</td><td> </td><td valign="top"><a href="#Environment-objects">Environment objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-environment-4">environment</a>:</td><td> </td><td valign="top"><a href="#Control-structures">Control structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-environment-5">environment</a>:</td><td> </td><td valign="top"><a href="#Global-environment">Global environment</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-environment-6">environment</a>:</td><td> </td><td valign="top"><a href="#Lexical-environment">Lexical environment</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-environment-7">environment</a>:</td><td> </td><td valign="top"><a href="#Stacks">Stacks</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-environment-8">environment</a>:</td><td> </td><td valign="top"><a href="#Search-path">Search path</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-environment-9">environment</a>:</td><td> </td><td valign="top"><a href="#Evaluation-environment">Evaluation environment</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-environment-10">environment</a>:</td><td> </td><td valign="top"><a href="#Argument-evaluation">Argument evaluation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-environment-11">environment</a>:</td><td> </td><td valign="top"><a href="#Argument-evaluation">Argument evaluation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-environment-12">environment</a>:</td><td> </td><td valign="top"><a href="#Scope">Scope</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-environment-13">environment</a>:</td><td> </td><td valign="top"><a href="#UseMethod">UseMethod</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-environment-14">environment</a>:</td><td> </td><td valign="top"><a href="#UseMethod">UseMethod</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-environment-15">environment</a>:</td><td> </td><td valign="top"><a href="#More-on-evaluation">More on evaluation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-environment-16">environment</a>:</td><td> </td><td valign="top"><a href="#Manipulation-of-functions">Manipulation of functions</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-environment-17">environment</a>:</td><td> </td><td valign="top"><a href="#Operating-system-access">Operating system access</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-environment-18">environment</a>:</td><td> </td><td valign="top"><a href="#Debugging">Debugging</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-environment-19">environment</a>:</td><td> </td><td valign="top"><a href="#Debugging">Debugging</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-environment_002c-evaluation">environment, evaluation</a>:</td><td> </td><td valign="top"><a href="#Lexical-environment">Lexical environment</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-environment_002c-evaluation-1">environment, evaluation</a>:</td><td> </td><td valign="top"><a href="#Lexical-environment">Lexical environment</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-environment_002c-evaluation-2">environment, evaluation</a>:</td><td> </td><td valign="top"><a href="#Argument-evaluation">Argument evaluation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-evaluation">evaluation</a>:</td><td> </td><td valign="top"><a href="#Stacks">Stacks</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-evaluation-1">evaluation</a>:</td><td> </td><td valign="top"><a href="#Evaluation-environment">Evaluation environment</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-evaluation-2">evaluation</a>:</td><td> </td><td valign="top"><a href="#Argument-evaluation">Argument evaluation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-evaluation-3">evaluation</a>:</td><td> </td><td valign="top"><a href="#Scope">Scope</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-evaluation-4">evaluation</a>:</td><td> </td><td valign="top"><a href="#Inheritance">Inheritance</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-evaluation-5">evaluation</a>:</td><td> </td><td valign="top"><a href="#UseMethod">UseMethod</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-evaluation-6">evaluation</a>:</td><td> </td><td valign="top"><a href="#More-on-evaluation">More on evaluation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-evaluation-7">evaluation</a>:</td><td> </td><td valign="top"><a href="#Manipulation-of-function-calls">Manipulation of function calls</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-evaluation_002c-argument">evaluation, argument</a>:</td><td> </td><td valign="top"><a href="#Argument-evaluation">Argument evaluation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-evaluation_002c-expression">evaluation, expression</a>:</td><td> </td><td valign="top"><a href="#Expression-objects">Expression objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-evaluation_002c-expression-1">evaluation, expression</a>:</td><td> </td><td valign="top"><a href="#Promise-objects">Promise objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-evaluation_002c-expression-2">evaluation, expression</a>:</td><td> </td><td valign="top"><a href="#Arguments">Arguments</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-evaluation_002c-lazy">evaluation, lazy</a>:</td><td> </td><td valign="top"><a href="#Objects">Objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-evaluation_002c-lazy-1">evaluation, lazy</a>:</td><td> </td><td valign="top"><a href="#Substitutions">Substitutions</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-evaluation_002c-lazy-2">evaluation, lazy</a>:</td><td> </td><td valign="top"><a href="#Substitutions">Substitutions</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-evaluation_002c-statement">evaluation, statement</a>:</td><td> </td><td valign="top"><a href="#Control-structures">Control structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-evaluation_002c-symbol">evaluation, symbol</a>:</td><td> </td><td valign="top"><a href="#Attributes">Attributes</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-evaluation_002c-symbol-1">evaluation, symbol</a>:</td><td> </td><td valign="top"><a href="#Symbol-lookup">Symbol lookup</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-evaluation_002c-symbol-2">evaluation, symbol</a>:</td><td> </td><td valign="top"><a href="#Scope">Scope</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-expression">expression</a>:</td><td> </td><td valign="top"><a href="#Introduction">Introduction</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-expression-1">expression</a>:</td><td> </td><td valign="top"><a href="#Language-objects">Language objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-expression-2">expression</a>:</td><td> </td><td valign="top"><a href="#Separators">Separators</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-expression-object">expression object</a>:</td><td> </td><td valign="top"><a href="#Expression-objects">Expression objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-expression-object-1">expression object</a>:</td><td> </td><td valign="top"><a href="#Expression-objects">Expression objects</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Concept-Index_cp_letter-F">F</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-frame">frame</a>:</td><td> </td><td valign="top"><a href="#Lexical-environment">Lexical environment</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function">function</a>:</td><td> </td><td valign="top"><a href="#Function-objects">Function objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function-1">function</a>:</td><td> </td><td valign="top"><a href="#Function-objects">Function objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function-2">function</a>:</td><td> </td><td valign="top"><a href="#Function-objects">Function objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function-3">function</a>:</td><td> </td><td valign="top"><a href="#Builtin-objects-and-special-forms">Builtin objects and special forms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function-4">function</a>:</td><td> </td><td valign="top"><a href="#Builtin-objects-and-special-forms">Builtin objects and special forms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function-5">function</a>:</td><td> </td><td valign="top"><a href="#Promise-objects">Promise objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function-6">function</a>:</td><td> </td><td valign="top"><a href="#Dot_002ddot_002ddot">Dot-dot-dot</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function-7">function</a>:</td><td> </td><td valign="top"><a href="#Function-calls">Function calls</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function-8">function</a>:</td><td> </td><td valign="top"><a href="#Lexical-environment">Lexical environment</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function-9">function</a>:</td><td> </td><td valign="top"><a href="#Lexical-environment">Lexical environment</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function-10">function</a>:</td><td> </td><td valign="top"><a href="#Stacks">Stacks</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function-11">function</a>:</td><td> </td><td valign="top"><a href="#Writing-functions">Writing functions</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function-12">function</a>:</td><td> </td><td valign="top"><a href="#Syntax-and-examples">Syntax and examples</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function-13">function</a>:</td><td> </td><td valign="top"><a href="#Syntax-and-examples">Syntax and examples</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function-14">function</a>:</td><td> </td><td valign="top"><a href="#Arguments">Arguments</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function-15">function</a>:</td><td> </td><td valign="top"><a href="#Evaluation-environment">Evaluation environment</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function-16">function</a>:</td><td> </td><td valign="top"><a href="#Argument-matching">Argument matching</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function-17">function</a>:</td><td> </td><td valign="top"><a href="#Argument-evaluation">Argument evaluation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function-18">function</a>:</td><td> </td><td valign="top"><a href="#Argument-evaluation">Argument evaluation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function-19">function</a>:</td><td> </td><td valign="top"><a href="#Argument-evaluation">Argument evaluation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function-20">function</a>:</td><td> </td><td valign="top"><a href="#Argument-evaluation">Argument evaluation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function-21">function</a>:</td><td> </td><td valign="top"><a href="#Scope">Scope</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function-22">function</a>:</td><td> </td><td valign="top"><a href="#Scope">Scope</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function-23">function</a>:</td><td> </td><td valign="top"><a href="#Scope">Scope</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function-24">function</a>:</td><td> </td><td valign="top"><a href="#Object_002doriented-programming">Object-oriented programming</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function-25">function</a>:</td><td> </td><td valign="top"><a href="#Definition">Definition</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function-26">function</a>:</td><td> </td><td valign="top"><a href="#Manipulation-of-function-calls">Manipulation of function calls</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function-27">function</a>:</td><td> </td><td valign="top"><a href="#Manipulation-of-functions">Manipulation of functions</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function-28">function</a>:</td><td> </td><td valign="top"><a href="#Manipulation-of-functions">Manipulation of functions</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function-29">function</a>:</td><td> </td><td valign="top"><a href="#Internal-representation">Internal representation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function-30">function</a>:</td><td> </td><td valign="top"><a href="#Function-calls-_0028expressions_0029">Function calls (expressions)</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function-31">function</a>:</td><td> </td><td valign="top"><a href="#Function-definitions">Function definitions</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function-argument">function argument</a>:</td><td> </td><td valign="top"><a href="#Promise-objects">Promise objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function-argument-1">function argument</a>:</td><td> </td><td valign="top"><a href="#Dot_002ddot_002ddot">Dot-dot-dot</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function-arguments">function arguments</a>:</td><td> </td><td valign="top"><a href="#Function-calls">Function calls</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function-invocation">function invocation</a>:</td><td> </td><td valign="top"><a href="#Function-calls">Function calls</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function_002c-accessor">function, accessor</a>:</td><td> </td><td valign="top"><a href="#Attributes">Attributes</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function_002c-anonymous">function, anonymous</a>:</td><td> </td><td valign="top"><a href="#Syntax-and-examples">Syntax and examples</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function_002c-assignment">function, assignment</a>:</td><td> </td><td valign="top"><a href="#Function-calls">Function calls</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function_002c-generic">function, generic</a>:</td><td> </td><td valign="top"><a href="#Object_002doriented-programming">Object-oriented programming</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function_002c-generic-1">function, generic</a>:</td><td> </td><td valign="top"><a href="#Definition">Definition</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function_002c-generic-2">function, generic</a>:</td><td> </td><td valign="top"><a href="#Definition">Definition</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function_002c-generic-3">function, generic</a>:</td><td> </td><td valign="top"><a href="#Definition">Definition</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function_002c-generic-4">function, generic</a>:</td><td> </td><td valign="top"><a href="#Inheritance">Inheritance</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function_002c-generic-5">function, generic</a>:</td><td> </td><td valign="top"><a href="#Method-dispatching">Method dispatching</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function_002c-generic-6">function, generic</a>:</td><td> </td><td valign="top"><a href="#Writing-methods">Writing methods</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function_002c-generic-7">function, generic</a>:</td><td> </td><td valign="top"><a href="#Writing-methods">Writing methods</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function_002c-internal">function, internal</a>:</td><td> </td><td valign="top"><a href="#Argument-evaluation">Argument evaluation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function_002c-internal-1">function, internal</a>:</td><td> </td><td valign="top"><a href="#Group-methods">Group methods</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-function_002c-modeling">function, modeling</a>:</td><td> </td><td valign="top"><a href="#Factors">Factors</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Concept-Index_cp_letter-I">I</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-identifier">identifier</a>:</td><td> </td><td valign="top"><a href="#Identifiers">Identifiers</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-index">index</a>:</td><td> </td><td valign="top"><a href="#Vector-objects">Vector objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-index-1">index</a>:</td><td> </td><td valign="top"><a href="#List-objects">List objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-index-2">index</a>:</td><td> </td><td valign="top"><a href="#Indexing">Indexing</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-index-3">index</a>:</td><td> </td><td valign="top"><a href="#Indexing-by-vectors">Indexing by vectors</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-index-4">index</a>:</td><td> </td><td valign="top"><a href="#Indexing-matrices-and-arrays">Indexing matrices and arrays</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-index-5">index</a>:</td><td> </td><td valign="top"><a href="#Indexing-matrices-and-arrays">Indexing matrices and arrays</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Concept-Index_cp_letter-M">M</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-mode">mode</a>:</td><td> </td><td valign="top"><a href="#Objects">Objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mode-1">mode</a>:</td><td> </td><td valign="top"><a href="#Vector-objects">Vector objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mode-2">mode</a>:</td><td> </td><td valign="top"><a href="#Symbol-objects">Symbol objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-modeling-function">modeling function</a>:</td><td> </td><td valign="top"><a href="#Factors">Factors</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Concept-Index_cp_letter-N">N</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-name">name</a>:</td><td> </td><td valign="top"><a href="#Language-objects">Language objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-name-1">name</a>:</td><td> </td><td valign="top"><a href="#Symbol-objects">Symbol objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-name-2">name</a>:</td><td> </td><td valign="top"><a href="#Symbol-lookup">Symbol lookup</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-name-3">name</a>:</td><td> </td><td valign="top"><a href="#Propagation-of-names">Propagation of names</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-name-4">name</a>:</td><td> </td><td valign="top"><a href="#Scope-of-variables">Scope of variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-name-5">name</a>:</td><td> </td><td valign="top"><a href="#Arguments">Arguments</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-name-6">name</a>:</td><td> </td><td valign="top"><a href="#Argument-matching">Argument matching</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-name-7">name</a>:</td><td> </td><td valign="top"><a href="#Argument-evaluation">Argument evaluation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-name-8">name</a>:</td><td> </td><td valign="top"><a href="#Method-dispatching">Method dispatching</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-name-9">name</a>:</td><td> </td><td valign="top"><a href="#NextMethod">NextMethod</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-name-10">name</a>:</td><td> </td><td valign="top"><a href="#Direct-manipulation-of-language-objects">Direct manipulation of language objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-name-11">name</a>:</td><td> </td><td valign="top"><a href="#Debugging">Debugging</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-namespace">namespace</a>:</td><td> </td><td valign="top"><a href="#Search-path">Search path</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Concept-Index_cp_letter-O">O</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-object">object</a>:</td><td> </td><td valign="top"><a href="#Objects">Objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-object-1">object</a>:</td><td> </td><td valign="top"><a href="#Objects">Objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-object-2">object</a>:</td><td> </td><td valign="top"><a href="#Symbol-objects">Symbol objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-object-3">object</a>:</td><td> </td><td valign="top"><a href="#Attributes">Attributes</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-object-4">object</a>:</td><td> </td><td valign="top"><a href="#Method-dispatching">Method dispatching</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-object_002doriented">object-oriented</a>:</td><td> </td><td valign="top"><a href="#Object_002doriented-programming">Object-oriented programming</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-object_002doriented-1">object-oriented</a>:</td><td> </td><td valign="top"><a href="#Definition">Definition</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Concept-Index_cp_letter-P">P</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-parsing">parsing</a>:</td><td> </td><td valign="top"><a href="#Language-objects">Language objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-parsing-1">parsing</a>:</td><td> </td><td valign="top"><a href="#Symbol-objects">Symbol objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-parsing-2">parsing</a>:</td><td> </td><td valign="top"><a href="#Evaluation-of-expressions">Evaluation of expressions</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-parsing-3">parsing</a>:</td><td> </td><td valign="top"><a href="#Computing-on-the-language">Computing on the language</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-parsing-4">parsing</a>:</td><td> </td><td valign="top"><a href="#Direct-manipulation-of-language-objects">Direct manipulation of language objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-parsing-5">parsing</a>:</td><td> </td><td valign="top"><a href="#Substitutions">Substitutions</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-parsing-6">parsing</a>:</td><td> </td><td valign="top"><a href="#Parser">Parser</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-parsing-7">parsing</a>:</td><td> </td><td valign="top"><a href="#Internal-representation">Internal representation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-partial-matching">partial matching</a>:</td><td> </td><td valign="top"><a href="#Indexing-by-vectors">Indexing by vectors</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-promise">promise</a>:</td><td> </td><td valign="top"><a href="#Promise-objects">Promise objects</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Concept-Index_cp_letter-S">S</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-scope">scope</a>:</td><td> </td><td valign="top"><a href="#Scope-of-variables">Scope of variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-scope-1">scope</a>:</td><td> </td><td valign="top"><a href="#Stacks">Stacks</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-scope-2">scope</a>:</td><td> </td><td valign="top"><a href="#Scope">Scope</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-scope-3">scope</a>:</td><td> </td><td valign="top"><a href="#Scope">Scope</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-scope-4">scope</a>:</td><td> </td><td valign="top"><a href="#Scope">Scope</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-scope-5">scope</a>:</td><td> </td><td valign="top"><a href="#More-on-evaluation">More on evaluation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-search-path">search path</a>:</td><td> </td><td valign="top"><a href="#Search-path">Search path</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-statement">statement</a>:</td><td> </td><td valign="top"><a href="#Language-objects">Language objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-symbol">symbol</a>:</td><td> </td><td valign="top"><a href="#Symbol-objects">Symbol objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-symbol-1">symbol</a>:</td><td> </td><td valign="top"><a href="#Symbol-objects">Symbol objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-symbol-2">symbol</a>:</td><td> </td><td valign="top"><a href="#Symbol-lookup">Symbol lookup</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-symbol-3">symbol</a>:</td><td> </td><td valign="top"><a href="#Scope">Scope</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-symbol-4">symbol</a>:</td><td> </td><td valign="top"><a href="#Substitutions">Substitutions</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-symbol-5">symbol</a>:</td><td> </td><td valign="top"><a href="#Manipulation-of-function-calls">Manipulation of function calls</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Concept-Index_cp_letter-T">T</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-token">token</a>:</td><td> </td><td valign="top"><a href="#Expression-objects">Expression objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-type">type</a>:</td><td> </td><td valign="top"><a href="#Objects">Objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-type-1">type</a>:</td><td> </td><td valign="top"><a href="#Objects">Objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-type-2">type</a>:</td><td> </td><td valign="top"><a href="#Basic-types">Basic types</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-type-3">type</a>:</td><td> </td><td valign="top"><a href="#Vector-objects">Vector objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-type-4">type</a>:</td><td> </td><td valign="top"><a href="#Names">Names</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-type-5">type</a>:</td><td> </td><td valign="top"><a href="#NA-handling">NA handling</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Concept-Index_cp_letter-V">V</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-value">value</a>:</td><td> </td><td valign="top"><a href="#Symbol-lookup">Symbol lookup</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-variable">variable</a>:</td><td> </td><td valign="top"><a href="#Objects">Objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-vector">vector</a>:</td><td> </td><td valign="top"><a href="#Vector-objects">Vector objects</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-vector-1">vector</a>:</td><td> </td><td valign="top"><a href="#Dimensions">Dimensions</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-vector-2">vector</a>:</td><td> </td><td valign="top"><a href="#Operators">Operators</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
</table>
<table summary=""><tr><th valign="top">Jump to: </th><td><a class="summary-letter" href="#Concept-Index_cp_symbol-1"><b>#</b></a>
<a class="summary-letter" href="#Concept-Index_cp_symbol-2"><b>.</b></a>
<br>
<a class="summary-letter" href="#Concept-Index_cp_letter-A"><b>A</b></a>
<a class="summary-letter" href="#Concept-Index_cp_letter-B"><b>B</b></a>
<a class="summary-letter" href="#Concept-Index_cp_letter-C"><b>C</b></a>
<a class="summary-letter" href="#Concept-Index_cp_letter-E"><b>E</b></a>
<a class="summary-letter" href="#Concept-Index_cp_letter-F"><b>F</b></a>
<a class="summary-letter" href="#Concept-Index_cp_letter-I"><b>I</b></a>
<a class="summary-letter" href="#Concept-Index_cp_letter-M"><b>M</b></a>
<a class="summary-letter" href="#Concept-Index_cp_letter-N"><b>N</b></a>
<a class="summary-letter" href="#Concept-Index_cp_letter-O"><b>O</b></a>
<a class="summary-letter" href="#Concept-Index_cp_letter-P"><b>P</b></a>
<a class="summary-letter" href="#Concept-Index_cp_letter-S"><b>S</b></a>
<a class="summary-letter" href="#Concept-Index_cp_letter-T"><b>T</b></a>
<a class="summary-letter" href="#Concept-Index_cp_letter-V"><b>V</b></a>
</td></tr></table>
<hr>
<a name="References"></a>
<div class="header">
<p>
Previous: <a href="#Concept-Index" accesskey="p" rel="prev">Concept Index</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="#Function-and-Variable-Index" title="Index" rel="index">Index</a>]</p>
</div>
<a name="References-1"></a>
<h2 class="appendix">Appendix A References</h2>
<p>Richard A. Becker, John M. Chambers and Allan R. Wilks (1988),
<em>The New S Language.</em> Chapman & Hall, New York.
This book is often called the “<em>Blue Book</em>”.
</p>
<div class="footnote">
<hr>
<h4 class="footnotes-heading">Footnotes</h4>
<h3><a name="FOOT1" href="#DOCF1">(1)</a></h3>
<p>actually two, but this draft
manual predates the <strong>methods</strong> package.</p>
<h3><a name="FOOT2" href="#DOCF2">(2)</a></h3>
<p>Evaluation always takes place in an
<a name="index-environment-4"></a>
environment.
See <a href="#Scope-of-variables">Scope of variables</a> for more details.</p>
<h3><a name="FOOT3" href="#DOCF3">(3)</a></h3>
<p>Looping is the repeated evaluation of a statement or
block of statements.</p>
<h3><a name="FOOT4" href="#DOCF4">(4)</a></h3>
<p>such as <code>U+A0</code>, non-breaking space,
and <code>U+3000</code>, ideographic space.</p>
</div>
<hr>
</body>
</html>
|