Lecture 8: Tidy evaluation in R#

Note from Firas

Our series of R lectures will be presented by Dr. Tiffany Timbers, the other option co-director of the Vancouver MDS program.

What Metaprogramming lets you do in R#

  • write library(purrr) instead of library("purrr")

  • enable plot(x, sin(x)) to automatically label the axes with x and sin(x)

  • create a model object via lm(y ~ x1 + x2, data = df)

  • and much much more (that you will see in Data Wrangling as we explore the tidyverse)

What is metaprogramming?#

Code that writes code/code that mutates code.

Our narrow focus on metaprogramming for this course:#

Tidy evaluation

Why focus on tidy evaluation#

In the rest of MDS you will be relying on functions from the tidyverse to do a lot of:

  • data wrangling

  • statistics

  • data visualization

The functions from the tidyverse are beautiful to use interactively:#

library(gapminder)
library(dplyr)
head(gapminder)
Error in library(gapminder): there is no package called ‘gapminder’
Traceback:

1. library(gapminder)

with base r:

gapminder[gapminder$country == "Canada" & gapminder$year == 1952, ]
A tibble: 1 × 6
countrycontinentyearlifeExppopgdpPercap
<fct><fct><int><dbl><int><dbl>
CanadaAmericas195268.751478558411367.16

In the tidyverse:

filter(gapminder, country == "Canada", year == 1952)

How does that even work?#

  • When functions like filter are called, there is a delay in evaluation and the data frame is temporarily promoted as first class objects, we say the data masks the workspace

  • This is to allow the promotion of the data frame, such that it masks the workspace (global environment)

  • When this happens, R can then find the relevant columns for the computation

This is referred to as data masking

We can capture expressions and later evaluate the code:#

We will functions from base R and rlang to demonstrate this:

library(rlang)
x <- 10
y <- expr(x)
eval(y)
10

We can also manipulate the environment code is evaluated in:#

x <- 10
y <- 2
expr(x + y)
eval(expr(x + y), env(x = 1000))
x + y
1002

You can evaluate in a data mask:#

#head(gapminder)
gapminder$gdpPercap * gapminder$pop
Error in eval(expr, envir, enclos): object 'gdpPercap' not found
Traceback:
x <- expr(gdpPercap * pop)
x
gdpPercap * pop
eval(x, gapminder)
  1. 6567086329.95223
  2. 7585448670.23365
  3. 8758855796.92893
  4. 9648014149.8489
  5. 9678553274.06687
  6. 11697659230.9699
  7. 12598563400.5169
  8. 11820990309.4608
  9. 10595901588.9034
  10. 14121995875.3377
  11. 18363410423.9786
  12. 31079291948.8899
  13. 2053669902.47879
  14. 2867792397.68722
  15. 3996988985.21125
  16. 5476396322.91986
  17. 7500110047.33615
  18. 8864476394.37768
  19. 10094200602.59
  20. 11498418357.5329
  21. 8307722182.8007
  22. 10945912518.587
  23. 16153932129.8053
  24. 21376411360.0421
  25. 22725632677.9121
  26. 30956113719.6857
  27. 28061403854.4022
  28. 41433235246.8537
  29. 61739408942.5438
  30. 84227416173.9838
  31. 115097120652.669
  32. 132119742844.669
  33. 132102425042.615
  34. 139467033682.098
  35. 165447670333.368
  36. 207444851958.217
  37. 14899557133.3119
  38. 17460618347.3729
  39. 20603593596.0431
  40. 28980597821.7449
  41. 32264255582.5783
  42. 18541315838.4746
  43. 19343845632.962
  44. 19136019188.7255
  45. 22956828370.0118
  46. 22486820880.8812
  47. 30134833900.6471
  48. 59583895818.2231
  49. 105676319104.619
  50. 134466639305.962
  51. 151820757736.505
  52. 184688236498.044
  53. 233996596623.536
  54. 271970723959.561
  55. 264010673179.124
  56. 289004799538.515
  57. 316104097626.698
  58. 397053586287.393
  59. 337223430799.523
  60. 515033625356.566
  61. 87256254101.5157
  62. 106349227168.697
  63. 131884573002.44
  64. 172457986741.708
  65. 221223770657.96
  66. 258037329175.491
  67. 295742804309.376
  68. 355853119294.078
  69. 409511234952.423
  70. 501223252920.637
  71. 599847158654.326
  72. 703658358893.63
  73. 42516266683.1358
  74. 61596299913.2558
  75. 76651179416.229
  76. 94680836235.5952
  77. 125698652513.146
  78. 149472120217.989
  79. 163589550350.139
  80. 179527736065.401
  81. 214036739549.621
  82. 234800471832.038
  83. 264148781751.719
  84. 296229400691.084
  85. 1188460758.68995
  86. 1613361772.73975
  87. 2191816125.38582
  88. 2993238335.8314
  89. 4216406356.412
  90. 5751939723.9236
  91. 7261179715.31877
  92. 8421243625.96472
  93. 10079167850.3025
  94. 12146009861.8392
  95. 15362026094.1502
  96. 21112675360.4188
  97. 32082059995.381
  98. 33985317661.0907
  99. 39011165929.1472
  100. 45306268649.6704
  101. 44594887096.4333
  102. 53072807953.8147
  103. 63009685013.4918
  104. 78028572051.8102
  105. 95262852013.6523
  106. 119957417048.458
  107. 154159077920.52
  108. 209311822133.851
  109. 72838686716.2864
  110. 87328859400.7762
  111. 101321340396.384
  112. 125658812132.235
  113. 161871509038.396
  114. 187772921747.664
  115. 206783717985.145
  116. 222331812712.216
  117. 256922515586.019
  118. 281118335091.118
  119. 314369518653.487
  120. 350141166520.108
  121. 1847398090.543
  122. 1847398090.94943
  123. 2043222288.54147
  124. 2514308802.18827
  125. 2998327102.24875
  126. 3260657629.22202
  127. 4653595792.11845
  128. 5202273024.96588
  129. 5934204759.41495
  130. 7479326759.29536
  131. 9645995478.4122
  132. 11643151767.5441
  133. 7719575216.20031
  134. 6833571025.29459
  135. 7838236490.57523
  136. 10452739933.3452
  137. 13607811411.4626
  138. 18023329326.7757
  139. 17809739028.5252
  140. 16952740924.5998
  141. 20416331717.304
  142. 25588644883.2829
  143. 28825460794.2505
  144. 34854649033.8328
  145. 2717131146.6868
  146. 4164870705.376
  147. 5725730640.971
  148. 7787883436.455
  149. 10922988275.25
  150. 14417374612.23
  151. 17219089833.9218
  152. 18718844705.9836
  153. 10839134938.0788
  154. 17192245745.728
  155. 25071535764.1344
  156. 33897026518.419
  157. 376510766.460736
  158. 435828972.132401
  159. 504382347.55477
  160. 672391397.310054
  161. 1401969807.06701
  162. 2512321368.7481
  163. 4416187131.82605
  164. 7144114193.9784
  165. 10679301652.14
  166. 13286645461.0478
  167. 17939694531.3628
  168. 20603633701.6119
  169. 119371649390.549
  170. 163049753284.523
  171. 253711949066.741
  172. 301998949547.859
  173. 502759433503.545
  174. 761344477467.542
  175. 906717258453.525
  176. 1115931255372.57
  177. 1084077163776.14
  178. 1341291557750.12
  179. 1462920751252.62
  180. 1722598680331.38
  181. 17781940935.5352
  182. 23020103934.6417
  183. 34089779369.6637
  184. 46346153670.6328
  185. 56581431456.1276
  186. 66965046602.3756
  187. 73130318095.9054
  188. 73927631407.0254
  189. 54571302853.6636
  190. 48157496050.3193
  191. 58971163876.6273
  192. 78213929148.2796
  193. 2428339520.25093
  194. 2909042417.92376
  195. 3554493256.92842
  196. 4075818934.41522
  197. 4644537855.3129
  198. 4378232963.87432
  199. 5355436506.56396
  200. 6919413539.72728
  201. 8272383440.67205
  202. 9796843171.2064
  203. 12712408470.3222
  204. 17435461729.7418
  205. 829789526.732977
  206. 1012495477.62006
  207. 1052081766.98828
  208. 1375623555.04895
  209. 1638263359.07543
  210. 2132330701.24842
  211. 2563212235.30471
  212. 3187457567.51423
  213. 3669693671.31136
  214. 2835010319.92396
  215. 3134233881.43858
  216. 3608510288.22326
  217. 1729534397.64356
  218. 2310184670.86911
  219. 3023033307.89866
  220. 3643123976.79705
  221. 3141354495.62457
  222. 3663574552.4848
  223. 4541488549.53182
  224. 5725430804.6556
  225. 6925441367.8235
  226. 8652054255.27354
  227. 11585251105.5606
  228. 24218877033.9786
  229. 5873970852.62788
  230. 7037836705.93638
  231. 8108811857.22315
  232. 9556813969.87289
  233. 11824439929.1908
  234. 14195884905.6421
  235. 21905813152.6073
  236. 28058456117.7054
  237. 22355673217.7465
  238. 24052491091.4674
  239. 30808779174.4326
  240. 36137515700.9453
  241. 168070115581.294
  242. 212455973972.909
  243. 255596717816.982
  244. 334710816939.589
  245. 422749686329.67
  246. 525683489648.984
  247. 577093069633.066
  248. 706925986091.991
  249. 751391311875.879
  250. 877503438098.975
  251. 1063269575825.78
  252. 1212704377996.04
  253. 1383806691.42853
  254. 1657993504.36515
  255. 1817613997.68293
  256. 1969510917.91537
  257. 2062193784.3765
  258. 2404605486.96815
  259. 2369849412.12717
  260. 2399456439.02315
  261. 2442004280.06313
  262. 2737291281.71136
  263. 2990229179.30429
  264. 3084613078.78141
  265. 3161726559.87227
  266. 3787904963.55633
  267. 4378505050.64671
  268. 4184010240.49135
  269. 4304976524.38412
  270. 4976220796.687
  271. 3889896143.58087
  272. 5237128465.99519
  273. 6802736597.5131
  274. 7599528805.96088
  275. 10215721151.4945
  276. 17447579585.7373
  277. 25127683584.3234
  278. 30418347406.984
  279. 35977675895.4284
  280. 45239380746.6702
  281. 53388314323.134
  282. 50420712011.4859
  283. 58534483046.9687
  284. 69135019226.6709
  285. 103102172132.616
  286. 147722858046.224
  287. 167039309147.507
  288. 214496727217.788
  289. 222754956737.111
  290. 367138722269.667
  291. 324678731163.591
  292. 462317080954.97
  293. 583508186392.963
  294. 699324197164.504
  295. 962691820907.921
  296. 1494780217152.63
  297. 1928938870545.26
  298. 2815929679840.2
  299. 3993927259238.4
  300. 6539500929092.31
  301. 26481474548.339
  302. 33662631379.7269
  303. 42394605743.7125
  304. 52942488863.7017
  305. 73594872191.6585
  306. 95755454802.6224
  307. 122097122635.2
  308. 151824477501.079
  309. 186221797590.287
  310. 230366568679.371
  311. 236013006965.707
  312. 309883885810.343
  313. 169790012.724096
  314. 207019199.012544
  315. 269639001.761542
  316. 407807571.736054
  317. 484446733.347225
  318. 357337879.939733
  319. 441765574.237369
  320. 519962442.552568
  321. 566630869.24173
  322. 619649302.95177
  323. 660959256.627156
  324. 701111696.196032
  325. 11005650695.0816
  326. 14111429069.1177
  327. 15673346681.9319
  328. 17181093743.0051
  329. 20819549223.4493
  330. 21072345136.1953
  331. 20648009138.6626
  332. 23871157044.3257
  333. 19074139151.9732
  334. 14922290060.3391
  335. 13355730548.0203
  336. 17931726045.033
  337. 1817161865.92693
  338. 2177213473.58998
  339. 2582905425.01607
  340. 3159326072.04592
  341. 4307096219.14881
  342. 5008605218.84208
  343. 8659832782.05667
  344. 8671665463.48701
  345. 9675414210.84662
  346. 9758959756.46407
  347. 11597728065.4262
  348. 13805935492.6568
  349. 2433443532.14831
  350. 3325789015.0646
  351. 4655607493.84867
  352. 6611807759.24898
  353. 9390755531.08945
  354. 12496565229.2099
  355. 12758800460.0776
  356. 15762698836.4049
  357. 19548331623.7655
  358. 23490559858.5006
  359. 29618910245.3101
  360. 39871565083.1553
  361. 4133872900.46391
  362. 4952956552.5
  363. 6625733026.82262
  364. 9736712727.82351
  365. 14439714172.8543
  366. 18781242084.851
  367. 23491934452.5957
  368. 23211215640.2038
  369. 21050180710.6314
  370. 26125858896.0236
  371. 26797508004.7935
  372. 27826215570.2518
  373. 12109590475.8031
  374. 17314932235.4983
  375. 22330930898.108
  376. 29054830740.8311
  377. 38721121654.5144
  378. 48824261688.2794
  379. 58352765410.3571
  380. 61984751387.9814
  381. 37964499980.5954
  382. 43893062449.3464
  383. 52107043452.729
  384. 65688728878.4486
  385. 33562790922.8677
  386. 40456619058.878
  387. 37583135793.0944
  388. 46314980543.066
  389. 46854233350.6851
  390. 60857084419.7684
  391. 71626950339.079
  392. 77135936772.2332
  393. 59973519954.6794
  394. 59659588751.8779
  395. 71186433969.3943
  396. 102160374746.553
  397. 62746038114.9158
  398. 78548858000.6239
  399. 97519520387.1307
  400. 112114783032.643
  401. 129277640538.869
  402. 150397974206.787
  403. 158442411319.549
  404. 168186719232.11
  405. 147483810393.196
  406. 165311042971.568
  407. 180471922898.335
  408. 233556067421.811
  409. 42006797651.83
  410. 49813395320.3699
  411. 63120285966.3055
  412. 77116977699.724
  413. 94172484444.6072
  414. 103920280027.729
  415. 110995270448.949
  416. 128771236166.089
  417. 136559629613.111
  418. 157476118455.789
  419. 172885062706.982
  420. 192906627080.569
  421. 168578116.816775
  422. 205850893.079676
  423. 271580892.765174
  424. 385409786.317521
  425. 660702490.730496
  426. 704780255.165268
  427. 881091313.289397
  428. 895783901.2122
  429. 913198814.093952
  430. 791942757.749472
  431. 853786444.069672
  432. 1033689705.33806
  433. 3482196998.3964
  434. 4514577213.34207
  435. 5740081668.24081
  436. 6696165882.70544
  437. 10229624253.5392
  438. 14222050738.92
  439. 17075997880.8907
  440. 19299310927.751
  441. 22378569689.8867
  442. 28885187703.8787
  443. 39478410078.3256
  444. 56154215096.9837
  445. 12499100973.2859
  446. 15342913820.2186
  447. 19129988881.7711
  448. 24875472663.3472
  449. 33263142611.1362
  450. 48620082640.0232
  451. 60349495671.0319
  452. 61869585518.9499
  453. 76353394349.8824
  454. 88498333675.3103
  455. 74594859031.9678
  456. 94546397112.5117
  457. 31530929611.3705
  458. 36487093093.6646
  459. 47706874227.3476
  460. 57497577541.3449
  461. 70450495584.0263
  462. 108032201471.667
  463. 160056715026.851
  464. 205148680925.854
  465. 225416799454.919
  466. 275990419358.701
  467. 348572216623.035
  468. 447970942204.754
  469. 6227271303.8085
  470. 8060441504.58049
  471. 10377474227.4607
  472. 14091020728.1053
  473. 17135814152.4652
  474. 22007877013.9792
  475. 18339569693.4148
  476. 20048823879.4408
  477. 23441762292.1733
  478. 29812618811.7607
  479. 34002160153.3595
  480. 39752986140.8636
  481. 81501034.5602684
  482. 99247227.5674682
  483. 145255876.112308
  484. 237930439.59366
  485. 186663659.807731
  486. 184691860.57917
  487. 264878362.310024
  488. 329947736.703736
  489. 439053960.276492
  490. 1238289912.25811
  491. 3818060562.4293
  492. 6699346424.28975
  493. 473266515.933196
  494. 530907910.970085
  495. 634974530.368959
  496. 853356390.813398
  497. 1162468889.15893
  498. 1270778258.88694
  499. 1384253502.73134
  500. 1519605766.20333
  501. 2138181473.15809
  502. 3707155863.00201
  503. 3378916934.3723
  504. 3146934083.95291
  505. 7554712172.1051
  506. 8644931130.56421
  507. 10547387620.6213
  508. 14379218703.5052
  509. 17423536805.7812
  510. 19275480698.0561
  511. 22023287795.4529
  512. 24670606852.1823
  513. 21947694837.1335
  514. 30881810733.9291
  515. 36015439731.1423
  516. 52854838162.2307
  517. 26279495259.9255
  518. 32626376129.064
  519. 42093096667.7055
  520. 50302260674.6774
  521. 66620259081.5663
  522. 73952569459.9327
  523. 89458310061.9101
  524. 104261743104.046
  525. 104083163954.025
  526. 121808392250.581
  527. 146467538809.042
  528. 173953983346.024
  529. 298483363097.914
  530. 383857690356.897
  531. 497652320115.72
  532. 644392918488.54
  533. 833257241541.72
  534. 972528294778.168
  535. 1104669186492.24
  536. 1227558382892.41
  537. 1417360022289.61
  538. 1517747939261.93
  539. 1733393500385.63
  540. 1861227940621.4
  541. 1806274139.98545
  542. 2164168458.0475
  543. 3021697340.55574
  544. 4087468046.69095
  545. 6133985999.76657
  546. 15360355361.0738
  547. 11393570619.1556
  548. 10445389597.3507
  549. 13329318031.6073
  550. 16580702573.9953
  551. 16269512983.1117
  552. 19213678514.1588
  553. 137960780.995312
  554. 168337466.691965
  555. 224281196.22952
  556. 323005424.810653
  557. 390973259.137566
  558. 538173615.364292
  559. 598041000.148448
  560. 518935047.710407
  561. 682520622.689438
  562. 807858171.484697
  563. 962979227.33227
  564. 1270911775.48381
  565. 493986590900.887
  566. 723529963816.389
  567. 951416222108.651
  568. 1126100616352.88
  569. 1418181247737.45
  570. 1603305779824.91
  571. 1725845977575.61
  572. 1914915573601.21
  573. 2136268169644.11
  574. 2278996207434.3
  575. 2473468447076.13
  576. 2650870893900.92
  577. 5085960279.25404
  578. 6669702328.68966
  579. 8753047553.08727
  580. 9557408661.89508
  581. 11021245951.477
  582. 10466686429.7478
  583. 9987067385.60832
  584. 12000468163.6855
  585. 15058811881.2057
  586. 18514906876.2099
  587. 22852118178.3181
  588. 30366847330.2416
  589. 27303708960.6278
  590. 39803435654.7198
  591. 50834629317.8248
  592. 74203907867.2401
  593. 113106276411.13
  594. 132138739654.37
  595. 149424095671.567
  596. 160794049220.771
  597. 181123475012.43
  598. 196895300009.988
  599. 238738073446.292
  600. 294834223726.725
  601. 7640161179.86399
  602. 9528740348.50709
  603. 11575893401.4627
  604. 15209977556.0066
  605. 20760063435.5844
  606. 27832697038.7256
  607. 30830101093.7677
  608. 31111480318.8294
  609. 37677392867.0872
  610. 45924427024.6021
  611. 54309766224.9818
  612. 65203833292.1188
  613. 1359290494.41378
  614. 1657762332.32179
  615. 2155215395.16702
  616. 2446225437.134
  617. 2826777030.02898
  618. 3697319890.22857
  619. 4038075238.19478
  620. 4551695525.65761
  621. 5552951540.41964
  622. 6998056844.31191
  623. 8328528109.01737
  624. 9377348758.33953
  625. 174108987.278307
  626. 259547084.509977
  627. 327743619.74295
  628. 430269336.403937
  629. 512936468.326124
  630. 569895199.805518
  631. 692279501.213028
  632. 683042950.14216
  633. 783516180.528623
  634. 950984748.886715
  635. 767102932.308578
  636. 852652874.197463
  637. 5891912670.80523
  638. 6057406350.57928
  639. 6970999000.73416
  640. 6270183933.68824
  641. 7773136723.84875
  642. 9200097514.95577
  643. 10454809788.3621
  644. 10493650139.467
  645. 9213607207.63259
  646. 9276089515.1804
  647. 9664493045.29473
  648. 10217297215.9514
  649. 3330697353.03841
  650. 3931129187.33598
  651. 4788888952.55727
  652. 6347422262.58766
  653. 7501351909.90737
  654. 9786553395.52551
  655. 11455138902.0217
  656. 13217592456.6579
  657. 15646832847.4582
  658. 18545413488.847
  659. 20697904973.8205
  660. 26554867097.0535
  661. 6493394048.2131
  662. 9930241909.2891
  663. 15510141068.6144
  664. 23073775963.9592
  665. 34225865466.3765
  666. 51273915647.625
  667. 76653912869.895
  668. 111905051122.032
  669. 144329299236.985
  670. 184338771740.4
  671. 204287740003.136
  672. 277296717807.812
  673. 50025955947.264
  674. 59429331128.229
  675. 75979271442.251
  676. 95350224305.4607
  677. 105693936955.046
  678. 124187241501.88
  679. 134311542120.303
  680. 137822135542.945
  681. 109029890605.328
  682. 119993697078.531
  683. 149676048403.31
  684. 179298995810.64
  685. 1075341715.18374
  686. 1526277073.13532
  687. 1884277507.35018
  688. 2646343594.11968
  689. 3306139764.0755
  690. 4359922739.98281
  691. 5445018346.1775
  692. 6587462419.76528
  693. 6512699263.29412
  694. 7609945738.99472
  695. 8975937060.5388
  696. 10924101860.9259
  697. 203322458739.6
  698. 241335356364
  699. 298889606508.6
  700. 354589929014.2
  701. 410526442809
  702. 515655862782
  703. 605852264691.6
  704. 769491988372.8
  705. 1015362737448
  706. 1399005926878
  707. 1806461015264.98
  708. 2722925438772.82
  709. 61512879123.2392
  710. 77407527996.5668
  711. 84103467353.4628
  712. 83366577256.7303
  713. 134757389176.774
  714. 189049938606.6
  715. 232601854598.884
  716. 295954872930.236
  717. 440442568204.768
  718. 621614960294.634
  719. 606568050342.2
  720. 791502035177.508
  721. 52426150706.544
  722. 65120779270.256
  723. 95780981890.948
  724. 156752848641.09
  725. 294317442834.698
  726. 421815425794.459
  727. 327711901836.63
  728. 344697094905.253
  729. 437018785886.188
  730. 523316539155.054
  731. 618279294330.716
  732. 806058303731.229
  733. 22473220511.4949
  734. 38924881556.8564
  735. 60396350632.4319
  736. 76089624801.5757
  737. 96349359728.3796
  738. 174539063525.064
  739. 205766914164.491
  740. 192621823480.477
  741. 66904278115.3287
  742. 63911044337.7009
  743. 105385189030.639
  744. 122952583890.59
  745. 15381560331.9872
  746. 16115377912.7478
  747. 18767420398.62
  748. 22201915549.5963
  749. 28824869546.6624
  750. 36484895159.247
  751. 43911758506.8
  752. 49108560194.148
  753. 62470069169.9836
  754. 89927693739.3913
  755. 132190156526.465
  756. 167141167137.836
  757. 6623900928.58499
  758. 10471140805.4029
  759. 16420430421.0182
  760. 22609255939.6933
  761. 39586973982.3314
  762. 46518849615.3848
  763. 59292468172.8932
  764. 71968316978.5993
  765. 89112243594.837
  766. 115587232694.216
  767. 132080421158.889
  768. 164029908949.751
  769. 235060310452.23
  770. 307321410802.224
  771. 419130105629.088
  772. 527850812033.901
  773. 667025988920.112
  774. 799179741816.514
  775. 934957147512.006
  776. 1089620726789.86
  777. 1251274219399.6
  778. 1418307303522.81
  779. 1620107994725.49
  780. 1661264433000.44
  781. 4133580396.7397
  782. 7301695161.15529
  783. 8735440529.22307
  784. 11398661093.8423
  785. 14850056193.9255
  786. 14343234914.5844
  787. 13946257030.1671
  788. 14776827263.292
  789. 17613484765.7673
  790. 18027806344.4069
  791. 18638689786.3374
  792. 20353013484.5546
  793. 278134909229.182
  794. 395341088001.744
  795. 630251873020.733
  796. 992906033833.796
  797. 1584112586964.36
  798. 1891464707591.05
  799. 2296143737891.3
  800. 2731908393473.1
  801. 3335119600027.97
  802. 3629636158476.35
  803. 3634666526235.29
  804. 4035134797102.17
  805. 940386912.584598
  806. 1408070439.93637
  807. 2192005081.53332
  808. 3441113320.44262
  809. 3405974308.24326
  810. 5526864720.43834
  811. 9766972259.66773
  812. 12545464196.3963
  813. 13271376154.7506
  814. 16499844607.0714
  815. 20406782659.6392
  816. 27357170724.069
  817. 5517327763.29827
  818. 7040578918.94834
  819. 7784373796.89947
  820. 10769742282.353
  821. 14723063007.1669
  822. 18380903573.7344
  823. 23811625092.9085
  824. 28870449152.3102
  825. 33575604755.2276
  826. 38452513269.6354
  827. 40411021465.9563
  828. 52106565927.1429
  829. 9648113404.2159
  830. 14786546840.5086
  831. 17704830126.0034
  832. 27045071155.6185
  833. 54714559526.6252
  834. 67036681906.3247
  835. 72469979025.6728
  836. 78300763966.8475
  837. 77171898567.2921
  838. 36495163359.6555
  839. 36583333391.1901
  840. 37121173721.953
  841. 21588403826.183
  842. 33636798616.7394
  843. 40590690362.2668
  844. 61142673146.602
  845. 101549522158.25
  846. 169690505084.72
  847. 221127835339.264
  848. 355164222241.71
  849. 530233376255.024
  850. 738482217215.895
  851. 922638064104.647
  852. 1145104609948.51
  853. 17341176464
  854. 24162944745.2334
  855. 34199395867.8082
  856. 46514800559.1498
  857. 92063687054.778
  858. 67583801714.939
  859. 46952480381.4606
  860. 53185644767.5803
  861. 49538198605.981
  862. 71144497943.2862
  863. 74137129817.5353
  864. 118530454006.187
  865. 6959840663.76444
  866. 10032388072.5148
  867. 10782507259.7441
  868. 13136635172.6515
  869. 20063644788.7981
  870. 26981770825.5499
  871. 23585336336.9064
  872. 16611733228.5201
  873. 22188356725.0389
  874. 30032922931.4738
  875. 34254617950.1974
  876. 41020719258.593
  877. 223760204.771239
  878. 273279221.601204
  879. 367796847.043404
  880. 496833953.22407
  881. 554571893.955524
  882. 932847869.180179
  883. 1125581635.86907
  884. 1237769947.98872
  885. 1762598359.14064
  886. 2351921523.90706
  887. 2610012082.9419
  888. 3158513357.40986
  889. 496896772.117099
  890. 606035661.838095
  891. 705729840.04935
  892. 912988789.25691
  893. 1190558369.5118
  894. 1090864191.36933
  895. 1119723032.36962
  896. 1148581873.35062
  897. 1217843092.0424
  898. 1340624342.87433
  899. 1495937378.2921
  900. 1323912407.32519
  901. 2434651995.67574
  902. 4143382666.77531
  903. 9742712723.45021
  904. 33025475319.0886
  905. 45886525492.4832
  906. 59746434997.7681
  907. 58067421827.0981
  908. 44726416798.581
  909. 42074394127.753
  910. 45061918969.3615
  911. 51187726429.1742
  912. 72790086208.4219
  913. 6872937813.51408
  914. 8234738516.41725
  915. 9372769145.75364
  916. 10350964014.4768
  917. 12384074920.6063
  918. 12364894630.0473
  919. 11949321645.6379
  920. 12211452300.1946
  921. 12707067346.995
  922. 13970993798.9061
  923. 14737783396.9688
  924. 20025792284.7044
  925. 1077150609.33772
  926. 1341226242.42832
  927. 1552685302.41684
  928. 2055024664.87291
  929. 2765844790.46199
  930. 3738755018.01864
  931. 4115013156.92654
  932. 4972762582.71206
  933. 5640025182.00661
  934. 7213507712.84371
  935. 7868292338.77011
  936. 10119916240.5456
  937. 12357176936.9459
  938. 14008533816.8311
  939. 18141281511.9674
  940. 23130196146.8077
  941. 32597809659.7684
  942. 49171111017.6135
  943. 71059367334.4421
  944. 85738648221.2256
  945. 133327738132.065
  946. 207482379883.417
  947. 231314259623.228
  948. 309066109785.359
  949. 1736145324.53936
  950. 2080144351.64774
  951. 2327242244.58752
  952. 2840818256.72072
  953. 3388309666.19322
  954. 4455837163.55608
  955. 4325020632.17221
  956. 5222971144.09086
  957. 6219703868.09062
  958. 7416558541.34325
  959. 10066082622.1603
  960. 12544127564.6048
  961. 759877632.159193
  962. 911146295.621428
  963. 1210856170.55525
  964. 1748778848.08461
  965. 2114933837.79187
  966. 2181378951.33742
  967. 2402627042.9837
  968. 2617513368.27424
  969. 2885375609.24556
  970. 3625883720.26078
  971. 4466822066.37189
  972. 5896422596.76724
  973. 1016559328.18509
  974. 1240388905.4215
  975. 1772916773.46679
  976. 1953845681.17466
  977. 2192597230.16677
  978. 3388220219.79308
  979. 3658680958.59756
  980. 4987669071.04269
  981. 6641069982.49289
  982. 8538209610.88631
  983. 10828037566.8742
  984. 13705902966.1678
  985. 104845718511.969
  986. 144668369722.174
  987. 188402581601.137
  988. 276201669610.826
  989. 381219826098.527
  990. 489353295727.781
  991. 688551298314.617
  992. 696116709845.12
  993. 834621536788.274
  994. 936636422664.789
  995. 1100884521316.24
  996. 1301973070171.29
  997. 629774979.826522
  998. 805090717.486539
  999. 1067213276.68824
  1000. 1409334278.935
  1001. 1877410277.9875
  1002. 2517397824.12
  1003. 3513123131.38445
  1004. 4711397687.66443
  1005. 4129281353.40883
  1006. 4745744245.8363
  1007. 5724837882.70358
  1008. 8897642669.93242
  1009. 1095660939.60423
  1010. 1630611470.58559
  1011. 2206362439.60848
  1012. 2960040094.2198
  1013. 4104497951.66253
  1014. 5374421249.68307
  1015. 6313244220.45576
  1016. 6681347764.04041
  1017. 4353422615.51898
  1018. 4478413551.7982
  1019. 4722688037.72486
  1020. 6336475807.4617
  1021. 16779421622.4047
  1022. 18729253094.2939
  1023. 20451257282.1178
  1024. 25272637722.1519
  1025. 32158341514.1333
  1026. 43612155831.8934
  1027. 54589498863.3479
  1028. 63331358935.7724
  1029. 76054427590.3892
  1030. 85077877939.9129
  1031. 101560083268.57
  1032. 128958323769.775
  1033. 3020266895.82064
  1034. 3487957478.30457
  1035. 4335998836.09128
  1036. 4919203358.1129
  1037. 7111150787.50431
  1038. 5589747687.07039
  1039. 5817958152.49182
  1040. 5026265057.80634
  1041. 5407702568.10227
  1042. 7842519681.68105
  1043. 11705318549.5401
  1044. 16433892152.3625
  1045. 6650781676
  1046. 7606145400
  1047. 9170161168
  1048. 9028724579
  1049. 10162501230
  1050. 11696920277
  1051. 14704507408
  1052. 14641002530
  1053. 14069648686
  1054. 17947864805
  1055. 27860427491
  1056. 45087309120
  1057. 1177547676.40313
  1058. 1436763251.62864
  1059. 1971810785.00824
  1060. 2680776460.25992
  1061. 3078461893.60934
  1062. 3787427569.60091
  1063. 4606061372.59411
  1064. 4721268295.25201
  1065. 5913214598.55975
  1066. 6920743072.82316
  1067. 8031247474.6589
  1068. 9887114066.42932
  1069. 5012431651.69527
  1070. 5789421899.34386
  1071. 6740601536.90858
  1072. 7617882645.36493
  1073. 8375870413.95605
  1074. 9671206057.99648
  1075. 11347646973.0329
  1076. 13897146222.2827
  1077. 18247658193.2257
  1078. 23251644296.9496
  1079. 27354068342.6902
  1080. 31542251118.2026
  1081. 92831291730.8937
  1082. 124335627651.528
  1083. 151004791951.147
  1084. 193528142723.178
  1085. 250531591643.146
  1086. 293808863797.949
  1087. 306234860366.244
  1088. 346853235808.614
  1089. 406532406373.845
  1090. 471974656555.132
  1091. 543738536478.117
  1092. 609764312245.525
  1093. 21058193787.114
  1094. 27304428858.1752
  1095. 32788333486.9
  1096. 39459740428.8795
  1097. 47000447796.848
  1098. 51378093148.73
  1099. 56611498450.76
  1100. 63050008702.6841
  1101. 63127124699.7896
  1102. 77385257445.895
  1103. 90626601698.45
  1104. 103655730129.674
  1105. 3628362766.93892
  1106. 4698033596.43012
  1107. 5780809121.09038
  1108. 8662204203.74166
  1109. 10234767751.2804
  1110. 14015472611.2172
  1111. 10339605319.764
  1112. 9885855212.48438
  1113. 8719537247.77683
  1114. 10385471754.5943
  1115. 12736126639.9725
  1116. 15603375234.6385
  1117. 2574746971.05197
  1118. 3084906138.33606
  1119. 4066902657.4941
  1120. 4780646467.65724
  1121. 4828548738.49791
  1122. 4596222732.79786
  1123. 5856052413.33125
  1124. 4900402142.58415
  1125. 4877760835.66905
  1126. 5609376389.03992
  1127. 6696363647.16629
  1128. 7990649871.11753
  1129. 35678601207.9222
  1130. 40912701545.8704
  1131. 48190888406.8828
  1132. 47974091350.4542
  1133. 91271560517.1712
  1134. 123295582777.116
  1135. 115181178668.38
  1136. 112951266107.586
  1137. 151235904174.953
  1138. 172581501319.655
  1139. 193674896635.367
  1140. 271949699763.733
  1141. 33594817529.4522
  1142. 40694951309.3515
  1143. 48944921612.3677
  1144. 61946375191.0729
  1145. 74589639181.052
  1146. 94252564410.3949
  1147. 108213282691.329
  1148. 132035157036.096
  1149. 145588949429.931
  1150. 181880081160.08
  1151. 202668235988.123
  1152. 228421423674.687
  1153. 928435681.494731
  1154. 1260371978.49133
  1155. 1837152375.61453
  1156. 3374411809.10042
  1157. 8802884859.8775
  1158. 11902052462.9894
  1159. 16854804933.9785
  1160. 28873528072.8907
  1161. 35654866007.6873
  1162. 44992304219.6694
  1163. 53658268402.9439
  1164. 71521099580.4844
  1165. 28305736881.9553
  1166. 34873817306.3784
  1167. 42658038632.5597
  1168. 57149426446.9155
  1169. 72787986851.6265
  1170. 91901399757.2744
  1171. 132019106316.209
  1172. 179310664748.318
  1173. 236747712482.478
  1174. 277819863187.178
  1175. 321029463168.042
  1176. 441110354736.257
  1177. 2331755944.38672
  1178. 3149893033.27293
  1179. 4299460457.43322
  1180. 6213666373.43482
  1181. 8670687327.27859
  1182. 9846351628.11261
  1183. 14273686782.0154
  1184. 15853852673.6169
  1185. 16447556623.0208
  1186. 19452611987.5538
  1187. 22000972010.6022
  1188. 31803076821.027
  1189. 3037550252.47708
  1190. 3623539461.16481
  1191. 4317132882.3837
  1192. 5260938508.92334
  1193. 6596267899.02761
  1194. 9694750656.43963
  1195. 14335992614.1462
  1196. 15541678375.1258
  1197. 18816476471.1427
  1198. 21891623375.4261
  1199. 22264997029.8653
  1200. 27820927446.7422
  1201. 30164781548.3309
  1202. 38827542285.5778
  1203. 52130689937.703
  1204. 70222305898.226
  1205. 82860598386.0801
  1206. 100438462619.245
  1207. 116626175121.357
  1208. 128465130363.322
  1209. 99734320550.3549
  1210. 144488140093.85
  1211. 158181134666.889
  1212. 212448566597.624
  1213. 28561783326.5775
  1214. 40358318274.0677
  1215. 50023104521.4934
  1216. 64141377891.538
  1217. 81266211261.2439
  1218. 111186903868.474
  1219. 139162617315.734
  1220. 131417048927.291
  1221. 153138130044.342
  1222. 190273063890.606
  1223. 220013427319.714
  1224. 290580355162.284
  1225. 103676873315.934
  1226. 133673272043.01
  1227. 161922307755.119
  1228. 208421579588.909
  1229. 264531348088.038
  1230. 329183780346.863
  1231. 306176833715.221
  1232. 342774381700.612
  1233. 296946267447.619
  1234. 392718270288.302
  1235. 463598198650.342
  1236. 592792827796.088
  1237. 26160648602.0354
  1238. 33282852529.6639
  1239. 42645207507.8022
  1240. 57908898290.279
  1241. 80933619341.8277
  1242. 98292660518.072
  1243. 115888777247.581
  1244. 129288514715.632
  1245. 160900556777.318
  1246. 179169637551.457
  1247. 208373796584.833
  1248. 218280817633.876
  1249. 6863524441.195
  1250. 8830172987.14
  1251. 12505462638.093
  1252. 18355386422.5552
  1253. 25974504080.9839
  1254. 30101306751.3146
  1255. 33875323753.8391
  1256. 42302689206.0539
  1257. 52492666708.6814
  1258. 63908179531.019
  1259. 72775210745.9651
  1260. 76203261313.5439
  1261. 700656740.5215
  1262. 854929784.2428
  1263. 1139049306.726
  1264. 1664863264.16374
  1265. 2330165765.41338
  1266. 2125753982.35036
  1267. 2727418853.17693
  1268. 2980683766.46808
  1269. 3796146461.76819
  1270. 4158126197.66691
  1271. 4699106901.6612
  1272. 6121478792.80445
  1273. 52294917283.18
  1274. 70307637223.5886
  1275. 88453168839.7395
  1276. 124789457739.148
  1277. 165537035770.656
  1278. 202646437193.072
  1279. 214743374426.87
  1280. 219973253287.762
  1281. 150424128715.758
  1282. 165756170699.815
  1283. 176666264621.071
  1284. 240770207962.994
  1285. 1250540010.98911
  1286. 1524740985.73326
  1287. 1823034933.29129
  1288. 1763376143.83762
  1289. 2357669470.14992
  1290. 3120613605.12598
  1291. 4855307638.79229
  1292. 5384205753.52721
  1293. 5373379681.74576
  1294. 4255023708.42767
  1295. 6169268408.36928
  1296. 7647471286.17077
  1297. 52784690.5494405
  1298. 52784690.551945
  1299. 70020507.871055
  1300. 98028711.056691
  1301. 117419005.53013
  1302. 150813401.580972
  1303. 186362274.809381
  1304. 168049218.941084
  1305. 179898843.338554
  1306. 194980183.449888
  1307. 230529056.66908
  1308. 319014076.627531
  1309. 25874890184.7302
  1310. 36053698159.2232
  1311. 57469729990.4227
  1312. 94964675299.1543
  1313. 160766615318.859
  1314. 277732829132.913
  1315. 379205636077.268
  1316. 309913175526.553
  1317. 420962502379.079
  1318. 437050471341.364
  1319. 465885351158.005
  1320. 597695839259.554
  1321. 3996587748.42799
  1322. 4788469786.51828
  1323. 5677013482.14969
  1324. 6394540398.17551
  1325. 7331414920.51898
  1326. 8216240862.75418
  1327. 9335285431.47547
  1328. 10339079560.2098
  1329. 11364398525.7025
  1330. 13276669392.306
  1331. 16518491524.4447
  1332. 21007739941.0751
  1333. 24569338287.8189
  1334. 36218184315.7313
  1335. 47902193037.4614
  1336. 63703671182.0546
  1337. 87472977399.8071
  1338. 112754859703.889
  1339. 137128138486.785
  1340. 146500635545.173
  1341. 91631822558.6785
  1342. 81807115768.4046
  1343. 73168001828.9263
  1344. 99335920778.7992
  1345. 1885604184.96561
  1346. 2305972823.36329
  1347. 2755749969.24892
  1348. 3210716852.08835
  1349. 3897491953.67491
  1350. 4234824811.04762
  1351. 5075562091.40525
  1352. 5008095519.23214
  1353. 4553590871.78975
  1354. 2630861090.90221
  1355. 3748629725.0206
  1356. 5299935153.38333
  1357. 2609160781.829
  1358. 4110927115.00096
  1359. 6431522198.1144
  1360. 9843342904.704
  1361. 18505810449.1848
  1362. 26066821067.844
  1363. 40226628130.1333
  1364. 52709528648.1471
  1365. 80152023987.888
  1366. 127451407551.469
  1367. 151216927293.59
  1368. 214643321189.537
  1369. 18056332320.3293
  1370. 23424190728.9655
  1371. 31700325638.0436
  1372. 37372114718.2445
  1373. 44437640820.8001
  1374. 52732470220.3041
  1375. 57287947438.2716
  1376. 62585581999.5104
  1377. 50369310506.684
  1378. 65275620851.2565
  1379. 73786500198.1752
  1380. 101750154778.254
  1381. 6278380543.97084
  1382. 8987280431.62103
  1383. 11717564986.756
  1384. 15490013353.7921
  1385. 20983941200.762
  1386. 26687734267.5462
  1387. 33254471590.631
  1388. 36346000744.7804
  1389. 28418203993.7201
  1390. 34521489478.5482
  1391. 41557566962.5819
  1392. 51774742721.4196
  1393. 2870033036.23495
  1394. 3498171939.31639
  1395. 4218233606.59541
  1396. 4405143232.17802
  1397. 4817774314.43645
  1398. 6317136770.10266
  1399. 6859481088.53965
  1400. 7567286393.10125
  1401. 5654271489.02042
  1402. 6173124436.1414
  1403. 6839053809.78016
  1404. 8445270167.8052
  1405. 67406033605.5055
  1406. 88625232661.2852
  1407. 105894592740.676
  1408. 149384977704.516
  1409. 185884606122.395
  1410. 217816767591.772
  1411. 266816058819.641
  1412. 281208278147.402
  1413. 288743816612.724
  1414. 320371065827.681
  1415. 342625279554.94
  1416. 407844809855.241
  1417. 109461193459.584
  1418. 136221071505.49
  1419. 177409134906.359
  1420. 262589077073.781
  1421. 367176936800.991
  1422. 482340170513.63
  1423. 528962031083.201
  1424. 612953611112.557
  1425. 735740746843.74
  1426. 814856426872.94
  1427. 997206698031.168
  1428. 1165759889360.77
  1429. 8649123231.41426
  1430. 9790790993.50069
  1431. 11198078000.9146
  1432. 13327981307.9351
  1433. 15794445637.4035
  1434. 19040444665.9602
  1435. 25397158408.5381
  1436. 30957839348.4804
  1437. 37877940921.6673
  1438. 49822140983.9893
  1439. 59031417076.4342
  1440. 80903553056.6483
  1441. 13743466427.099
  1442. 17266791454.855
  1443. 21914581924.1461
  1444. 21464795754.6517
  1445. 24225983090.0777
  1446. 37682086133.5771
  1447. 38606646598.6269
  1448. 37282276212.6676
  1449. 42121123344.6223
  1450. 52493088051.887
  1451. 73935737498.9576
  1452. 110062906753.49
  1453. 333308277.060118
  1454. 406697255.561724
  1455. 686798523.34275
  1456. 1099305739.44885
  1457. 1615474887.84562
  1458. 2085164350.03065
  1459. 2531613968.68222
  1460. 3105576937.80258
  1461. 3419229788.5056
  1462. 4087998066.31156
  1463. 4665882609.04767
  1464. 5114071458.24144
  1465. 60758104611.5455
  1466. 72989108704.3753
  1467. 93230160068.9689
  1468. 120051227737.469
  1469. 144836928909.3
  1470. 155590807217.646
  1471. 172061322425.375
  1472. 198635036915.166
  1473. 208206690698.532
  1474. 224812535648.329
  1475. 262730098132.633
  1476. 305790367006.705
  1477. 70945330691.25
  1478. 91804044355.98
  1479. 115762571238.2
  1480. 139243733012.16
  1481. 174086796614.256
  1482. 170431587415.5
  1483. 183679999508.265
  1484. 201371579184.634
  1485. 222955601022.544
  1486. 231173833391.741
  1487. 253840431788.296
  1488. 283348281397.785
  1489. 6017702154.45335
  1490. 8786330020.33984
  1491. 10602503376.9816
  1492. 10690854351.7492
  1493. 17231547901.5724
  1494. 25348191033.1687
  1495. 35400751245.9812
  1496. 35041416419.7894
  1497. 44158841963.8436
  1498. 60538802164.5556
  1499. 70183154066.5244
  1500. 80823487648.3685
  1501. 10319841571.2945
  1502. 15326226341.7374
  1503. 21726782116.2323
  1504. 36085212828.4953
  1505. 61856147294.154
  1506. 93938682197.2959
  1507. 137397885952.136
  1508. 218413809089.588
  1509. 314765067293.352
  1510. 437045349282.133
  1511. 521733747819.826
  1512. 665525790663.551
  1513. 5964624801.33289
  1514. 6603135550.61123
  1515. 7843819038.34729
  1516. 10693757259.3236
  1517. 13471019459.7353
  1518. 16487074298.3685
  1519. 17348804251.9994
  1520. 19165704757.286
  1521. 21967672236.4707
  1522. 24217670028.5989
  1523. 31102374563.3927
  1524. 42238971727.8945
  1525. 16133053859.9772
  1526. 19872699754.4962
  1527. 29327752243.3073
  1528. 44077076065.5443
  1529. 59870954797.2532
  1530. 86584704135.001
  1531. 116854125162.052
  1532. 157813231197.02
  1533. 261626115120.687
  1534. 352425659154.813
  1535. 371388079010.646
  1536. 485304043506.289
  1537. 1048203910.89551
  1538. 1256869619.71389
  1539. 1631297808.09138
  1540. 2564443056.818
  1541. 3392280377.25399
  1542. 3538541387.59684
  1543. 3556092709.86604
  1544. 3792060473.7533
  1545. 3876089960.58191
  1546. 4244353748.33863
  1547. 4411054800.61842
  1548. 5034322889.20126
  1549. 2003975797.4748
  1550. 3136390911.66
  1551. 4435292529.21456
  1552. 5397385045.23316
  1553. 6455379924.25738
  1554. 8207707919.13888
  1555. 10181762179.6148
  1556. 8802302576.06153
  1557. 8724813465.48951
  1558. 10006836267.2737
  1559. 12627656072.6214
  1560. 19027934931.0579
  1561. 5356609955.84579
  1562. 5512352800.96533
  1563. 7116976045.43192
  1564. 9250181066.38666
  1565. 14602071542.181
  1566. 18741055623.5405
  1567. 23974959096.5671
  1568. 29435397611.5369
  1569. 36928107577.2246
  1570. 45020990584.1068
  1571. 55915981214.3516
  1572. 72887997686.7379
  1573. 43784293371.6635
  1574. 56957505187.4373
  1575. 69195263214.0901
  1576. 94432289201.0317
  1577. 129376797192.61
  1578. 181028003992.741
  1579. 200738267961.7
  1580. 269115388365.695
  1581. 330361441740.66
  1582. 416204622976.16
  1583. 438052273010.69
  1584. 601879503437.493
  1585. 4279789889.34275
  1586. 5169314846.81567
  1587. 5899396651.15902
  1588. 8089642065.17538
  1589. 9688269464.83266
  1590. 9667290102.6184
  1591. 8828115615.05592
  1592. 9440712990.75982
  1593. 11757527777.4702
  1594. 17319425514.0166
  1595. 22951696053.0808
  1596. 30815028568.8582
  1597. 503266612999.41
  1598. 580293841968.5
  1599. 664933720414.44
  1600. 777276942063.51
  1601. 891382233156.39
  1602. 979129659734.34
  1603. 1027209400659.14
  1604. 1234494698392.63
  1605. 1313860808996.94
  1606. 1533397976044.22
  1607. 1766158504919.93
  1608. 2017969309929.46
  1609. 2204242423150.24
  1610. 2553468310606.08
  1611. 3016906282432.68
  1612. 3880918003145.84
  1613. 4576999719662.24
  1614. 5301732427679.07
  1615. 5806915391021.06
  1616. 7256025860958
  1617. 8221624217605.75
  1618. 9761353098899.43
  1619. 11247278678120.6
  1620. 12934458535085
  1621. 12879675387.396
  1622. 14915372268.1333
  1623. 14560134513.4621
  1624. 14964967150.52
  1625. 16137943765.5223
  1626. 18690350108.4238
  1627. 20442318131.9848
  1628. 22693695077.6473
  1629. 25625559931.7261
  1630. 30116780131.2093
  1631. 25986564534.6223
  1632. 36582976212.173
  1633. 41829188706.3432
  1634. 65702678704.8914
  1635. 68591437240.9069
  1636. 92643439785.0438
  1637. 120974882898.419
  1638. 177490169722.235
  1639. 174209188664.344
  1640. 177016799858.086
  1641. 217529059872.663
  1642. 227446835024.402
  1643. 208996562053.544
  1644. 297777432881.327
  1645. 15881082791.9447
  1646. 19611292638.3026
  1647. 26092281505.0016
  1648. 25143376124.1608
  1649. 31236255710.3085
  1650. 36057532314.5293
  1651. 39705759524.1319
  1652. 51567948937.8148
  1653. 69172999028.9303
  1654. 105396057842.094
  1655. 142758920197.848
  1656. 208174556559.048
  1657. 1561946720.38247
  1658. 1955764566.67874
  1659. 2491712161.64181
  1660. 3027659756.73845
  1661. 3414075012.75944
  1662. 4644385651.59995
  1663. 6182644080.95383
  1664. 8637343287.79464
  1665. 12665833359.6789
  1666. 20095073782.0045
  1667. 15305597343.4934
  1668. 12156859904.4969
  1669. 3880312374.05489
  1670. 4425030274.68152
  1671. 5052880863.15125
  1672. 5813537083.14685
  1673. 9370298237.14433
  1674. 15377328249.8562
  1675. 19098490175.8022
  1676. 22121638706.9449
  1677. 25125105886.174
  1678. 33512362498.2854
  1679. 41793958634.6795
  1680. 50659874994.2062
  1681. 3065822956.432
  1682. 3956861606.256
  1683. 4969774845.486
  1684. 6930601540.2
  1685. 7992264610.72771
  1686. 8287471946.14845
  1687. 8593512578.67595
  1688. 8823720129.4891
  1689. 10148621483.3682
  1690. 10089784202.2684
  1691. 11354618752.0137
  1692. 14931695863.7838
  1693. 1253572117.47612
  1694. 1891590901.34375
  1695. 2255531193.8844
  1696. 2846372532.11476
  1697. 4685169626.25753
  1698. 4553746742.39019
  1699. 6024110453.88114
  1700. 6508240904.92827
  1701. 7422611852.1295
  1702. 9037850589.82356
  1703. 8015110972.06478
  1704. 5782658337.33873

The data mask allows you to mingle variables from an environment and a data frame in a single expression.

y <- 1000
new_exp <- expr(pop / y)

eval(new_exp, gapminder)
  1. 8425.333
  2. 9240.934
  3. 10267.083
  4. 11537.966
  5. 13079.46
  6. 14880.372
  7. 12881.816
  8. 13867.957
  9. 16317.921
  10. 22227.415
  11. 25268.405
  12. 31889.923
  13. 1282.697
  14. 1476.505
  15. 1728.137
  16. 1984.06
  17. 2263.554
  18. 2509.048
  19. 2780.097
  20. 3075.321
  21. 3326.498
  22. 3428.038
  23. 3508.512
  24. 3600.523
  25. 9279.525
  26. 10270.856
  27. 11000.948
  28. 12760.499
  29. 14760.787
  30. 17152.804
  31. 20033.753
  32. 23254.956
  33. 26298.373
  34. 29072.015
  35. 31287.142
  36. 33333.216
  37. 4232.095
  38. 4561.361
  39. 4826.015
  40. 5247.469
  41. 5894.858
  42. 6162.675
  43. 7016.384
  44. 7874.23
  45. 8735.988
  46. 9875.024
  47. 10866.106
  48. 12420.476
  49. 17876.956
  50. 19610.538
  51. 21283.783
  52. 22934.225
  53. 24779.799
  54. 26983.828
  55. 29341.374
  56. 31620.918
  57. 33958.947
  58. 36203.463
  59. 38331.121
  60. 40301.927
  61. 8691.212
  62. 9712.569
  63. 10794.968
  64. 11872.264
  65. 13177
  66. 14074.1
  67. 15184.2
  68. 16257.249
  69. 17481.977
  70. 18565.243
  71. 19546.792
  72. 20434.176
  73. 6927.772
  74. 6965.86
  75. 7129.864
  76. 7376.998
  77. 7544.201
  78. 7568.43
  79. 7574.613
  80. 7578.903
  81. 7914.969
  82. 8069.876
  83. 8148.312
  84. 8199.783
  85. 120.447
  86. 138.655
  87. 171.863
  88. 202.182
  89. 230.8
  90. 297.41
  91. 377.967
  92. 454.612
  93. 529.491
  94. 598.561
  95. 656.397
  96. 708.573
  97. 46886.859
  98. 51365.468
  99. 56839.289
  100. 62821.884
  101. 70759.295
  102. 80428.306
  103. 93074.406
  104. 103764.241
  105. 113704.579
  106. 123315.288
  107. 135656.79
  108. 150448.339
  109. 8730.405
  110. 8989.111
  111. 9218.4
  112. 9556.5
  113. 9709.1
  114. 9821.8
  115. 9856.303
  116. 9870.2
  117. 10045.622
  118. 10199.787
  119. 10311.97
  120. 10392.226
  121. 1738.315
  122. 1925.173
  123. 2151.895
  124. 2427.334
  125. 2761.407
  126. 3168.267
  127. 3641.603
  128. 4243.788
  129. 4981.671
  130. 6066.08
  131. 7026.113
  132. 8078.314
  133. 2883.315
  134. 3211.738
  135. 3593.918
  136. 4040.665
  137. 4565.872
  138. 5079.716
  139. 5642.224
  140. 6156.369
  141. 6893.451
  142. 7693.188
  143. 8445.134
  144. 9119.152
  145. 2791
  146. 3076
  147. 3349
  148. 3585
  149. 3819
  150. 4086
  151. 4172.693
  152. 4338.977
  153. 4256.013
  154. 3607
  155. 4165.416
  156. 4552.198
  157. 442.308
  158. 474.639
  159. 512.764
  160. 553.541
  161. 619.351
  162. 781.472
  163. 970.347
  164. 1151.184
  165. 1342.614
  166. 1536.536
  167. 1630.347
  168. 1639.131
  169. 56602.56
  170. 65551.171
  171. 76039.39
  172. 88049.823
  173. 100840.058
  174. 114313.951
  175. 128962.939
  176. 142938.076
  177. 155975.974
  178. 168546.719
  179. 179914.212
  180. 190010.647
  181. 7274.9
  182. 7651.254
  183. 8012.946
  184. 8310.226
  185. 8576.2
  186. 8797.022
  187. 8892.098
  188. 8971.958
  189. 8658.506
  190. 8066.057
  191. 7661.799
  192. 7322.858
  193. 4469.979
  194. 4713.416
  195. 4919.632
  196. 5127.935
  197. 5433.886
  198. 5889.574
  199. 6634.596
  200. 7586.551
  201. 8878.303
  202. 10352.843
  203. 12251.209
  204. 14326.203
  205. 2445.618
  206. 2667.518
  207. 2961.915
  208. 3330.989
  209. 3529.983
  210. 3834.415
  211. 4580.41
  212. 5126.023
  213. 5809.236
  214. 6121.61
  215. 7021.078
  216. 8390.505
  217. 4693.836
  218. 5322.536
  219. 6083.619
  220. 6960.067
  221. 7450.606
  222. 6978.607
  223. 7272.485
  224. 8371.791
  225. 10150.094
  226. 11782.962
  227. 12926.707
  228. 14131.858
  229. 5009.067
  230. 5359.923
  231. 5793.633
  232. 6335.506
  233. 7021.028
  234. 7959.865
  235. 9250.831
  236. 10780.667
  237. 12467.171
  238. 14195.809
  239. 15929.988
  240. 17696.293
  241. 14785.584
  242. 17010.154
  243. 18985.849
  244. 20819.767
  245. 22284.5
  246. 23796.4
  247. 25201.9
  248. 26549.7
  249. 28523.502
  250. 30305.843
  251. 31902.268
  252. 33390.141
  253. 1291.695
  254. 1392.284
  255. 1523.478
  256. 1733.638
  257. 1927.26
  258. 2167.533
  259. 2476.971
  260. 2840.009
  261. 3265.124
  262. 3696.513
  263. 4048.013
  264. 4369.038
  265. 2682.462
  266. 2894.855
  267. 3150.417
  268. 3495.967
  269. 3899.068
  270. 4388.26
  271. 4875.118
  272. 5498.955
  273. 6429.417
  274. 7562.011
  275. 8835.739
  276. 10238.807
  277. 6377.619
  278. 7048.426
  279. 7961.258
  280. 8858.908
  281. 9717.524
  282. 10599.793
  283. 11487.112
  284. 12463.354
  285. 13572.994
  286. 14599.929
  287. 15497.046
  288. 16284.741
  289. 556263.527
  290. 637408
  291. 665770
  292. 754550
  293. 862030
  294. 943455
  295. 1000281
  296. 1084035
  297. 1164970
  298. 1230075
  299. 1280400
  300. 1318683.096
  301. 12350.771
  302. 14485.993
  303. 17009.885
  304. 19764.027
  305. 22542.89
  306. 25094.412
  307. 27764.644
  308. 30964.245
  309. 34202.721
  310. 37657.83
  311. 41008.227
  312. 44227.55
  313. 153.936
  314. 170.928
  315. 191.689
  316. 217.378
  317. 250.027
  318. 304.739
  319. 348.643
  320. 395.114
  321. 454.429
  322. 527.982
  323. 614.382
  324. 710.96
  325. 14100.005
  326. 15577.932
  327. 17486.434
  328. 19941.073
  329. 23007.669
  330. 26480.87
  331. 30646.495
  332. 35481.645
  333. 41672.143
  334. 47798.986
  335. 55379.852
  336. 64606.759
  337. 854.885
  338. 940.458
  339. 1047.924
  340. 1179.76
  341. 1340.458
  342. 1536.769
  343. 1774.735
  344. 2064.095
  345. 2409.073
  346. 2800.947
  347. 3328.795
  348. 3800.61
  349. 926.317
  350. 1112.3
  351. 1345.187
  352. 1588.717
  353. 1834.796
  354. 2108.457
  355. 2424.367
  356. 2799.811
  357. 3173.216
  358. 3518.107
  359. 3834.934
  360. 4133.884
  361. 2977.019
  362. 3300
  363. 3832.408
  364. 4744.87
  365. 6071.696
  366. 7459.574
  367. 9025.951
  368. 10761.098
  369. 12772.596
  370. 14625.967
  371. 16252.726
  372. 18013.409
  373. 3882.229
  374. 3991.242
  375. 4076.557
  376. 4174.366
  377. 4225.31
  378. 4318.673
  379. 4413.368
  380. 4484.31
  381. 4494.013
  382. 4444.595
  383. 4481.02
  384. 4493.312
  385. 6007.797
  386. 6640.752
  387. 7254.373
  388. 8139.332
  389. 8831.348
  390. 9537.988
  391. 9789.224
  392. 10239.839
  393. 10723.26
  394. 10983.007
  395. 11226.999
  396. 11416.987
  397. 9125.183
  398. 9513.758
  399. 9620.282
  400. 9835.109
  401. 9862.158
  402. 10161.915
  403. 10303.704
  404. 10311.597
  405. 10315.702
  406. 10300.707
  407. 10256.295
  408. 10228.744
  409. 4334
  410. 4487.831
  411. 4646.899
  412. 4838.8
  413. 4991.596
  414. 5088.419
  415. 5117.81
  416. 5127.024
  417. 5171.393
  418. 5283.663
  419. 5374.693
  420. 5468.12
  421. 63.149
  422. 71.851
  423. 89.898
  424. 127.617
  425. 178.848
  426. 228.694
  427. 305.991
  428. 311.025
  429. 384.156
  430. 417.908
  431. 447.416
  432. 496.374
  433. 2491.346
  434. 2923.186
  435. 3453.434
  436. 4049.146
  437. 4671.329
  438. 5302.8
  439. 5968.349
  440. 6655.297
  441. 7351.181
  442. 7992.357
  443. 8650.322
  444. 9319.622
  445. 3548.753
  446. 4058.385
  447. 4681.707
  448. 5432.424
  449. 6298.651
  450. 7278.866
  451. 8365.85
  452. 9545.158
  453. 10748.394
  454. 11911.819
  455. 12921.234
  456. 13755.68
  457. 22223.309
  458. 25009.741
  459. 28173.309
  460. 31681.188
  461. 34807.417
  462. 38783.863
  463. 45681.811
  464. 52799.062
  465. 59402.198
  466. 66134.291
  467. 73312.559
  468. 80264.543
  469. 2042.865
  470. 2355.805
  471. 2747.687
  472. 3232.927
  473. 3790.903
  474. 4282.586
  475. 4474.873
  476. 4842.194
  477. 5274.649
  478. 5783.439
  479. 6353.681
  480. 6939.688
  481. 216.964
  482. 232.922
  483. 249.22
  484. 259.864
  485. 277.603
  486. 192.675
  487. 285.483
  488. 341.244
  489. 387.838
  490. 439.971
  491. 495.627
  492. 551.201
  493. 1438.76
  494. 1542.611
  495. 1666.618
  496. 1820.319
  497. 2260.187
  498. 2512.642
  499. 2637.297
  500. 2915.959
  501. 3668.44
  502. 4058.319
  503. 4414.865
  504. 4906.585
  505. 20860.941
  506. 22815.614
  507. 25145.372
  508. 27860.297
  509. 30770.372
  510. 34617.799
  511. 38111.756
  512. 42999.53
  513. 52088.559
  514. 59861.301
  515. 67946.797
  516. 76511.887
  517. 4090.5
  518. 4324
  519. 4491.443
  520. 4605.744
  521. 4639.657
  522. 4738.902
  523. 4826.933
  524. 4931.729
  525. 5041.039
  526. 5134.406
  527. 5193.039
  528. 5238.46
  529. 42459.667
  530. 44310.863
  531. 47124
  532. 49569
  533. 51732
  534. 53165.019
  535. 54433.565
  536. 55630.1
  537. 57374.179
  538. 58623.428
  539. 59925.035
  540. 61083.916
  541. 420.702
  542. 434.904
  543. 455.661
  544. 489.004
  545. 537.977
  546. 706.367
  547. 753.874
  548. 880.397
  549. 985.739
  550. 1126.189
  551. 1299.304
  552. 1454.867
  553. 284.32
  554. 323.15
  555. 374.02
  556. 439.593
  557. 517.101
  558. 608.274
  559. 715.523
  560. 848.406
  561. 1025.384
  562. 1235.767
  563. 1457.766
  564. 1688.359
  565. 69145.952
  566. 71019.069
  567. 73739.117
  568. 76368.453
  569. 78717.088
  570. 78160.773
  571. 78335.266
  572. 77718.298
  573. 80597.764
  574. 82011.073
  575. 82350.671
  576. 82400.996
  577. 5581.001
  578. 6391.288
  579. 7355.248
  580. 8490.213
  581. 9354.12
  582. 10538.093
  583. 11400.338
  584. 14168.101
  585. 16278.738
  586. 18418.288
  587. 20550.751
  588. 22873.338
  589. 7733.25
  590. 8096.218
  591. 8448.233
  592. 8716.441
  593. 8888.628
  594. 9308.479
  595. 9786.48
  596. 9974.49
  597. 10325.429
  598. 10502.372
  599. 10603.863
  600. 10706.29
  601. 3146.381
  602. 3640.876
  603. 4208.858
  604. 4690.773
  605. 5149.581
  606. 5703.43
  607. 6395.63
  608. 7326.406
  609. 8486.949
  610. 9803.875
  611. 11178.65
  612. 12572.928
  613. 2664.249
  614. 2876.726
  615. 3140.003
  616. 3451.418
  617. 3811.387
  618. 4227.026
  619. 4710.497
  620. 5650.262
  621. 6990.574
  622. 8048.834
  623. 8807.818
  624. 9947.814
  625. 580.653
  626. 601.095
  627. 627.82
  628. 601.287
  629. 625.361
  630. 745.228
  631. 825.987
  632. 927.524
  633. 1050.938
  634. 1193.708
  635. 1332.459
  636. 1472.041
  637. 3201.488
  638. 3507.701
  639. 3880.13
  640. 4318.137
  641. 4698.301
  642. 4908.554
  643. 5198.399
  644. 5756.203
  645. 6326.682
  646. 6913.545
  647. 7607.651
  648. 8502.814
  649. 1517.453
  650. 1770.39
  651. 2090.162
  652. 2500.689
  653. 2965.146
  654. 3055.235
  655. 3669.448
  656. 4372.203
  657. 5077.347
  658. 5867.957
  659. 6677.328
  660. 7483.763
  661. 2125.9
  662. 2736.3
  663. 3305.2
  664. 3722.8
  665. 4115.7
  666. 4583.7
  667. 5264.5
  668. 5584.51
  669. 5829.696
  670. 6495.918
  671. 6762.476
  672. 6980.412
  673. 9504
  674. 9839
  675. 10063
  676. 10223.422
  677. 10394.091
  678. 10637.171
  679. 10705.535
  680. 10612.74
  681. 10348.684
  682. 10244.684
  683. 10083.313
  684. 9956.108
  685. 147.962
  686. 165.11
  687. 182.053
  688. 198.676
  689. 209.275
  690. 221.823
  691. 233.997
  692. 244.676
  693. 259.012
  694. 271.192
  695. 288.03
  696. 301.931
  697. 372000
  698. 409000
  699. 454000
  700. 506000
  701. 567000
  702. 634000
  703. 708000
  704. 788000
  705. 872000
  706. 959000
  707. 1034172.547
  708. 1110396.331
  709. 82052
  710. 90124
  711. 99028
  712. 109343
  713. 121282
  714. 136725
  715. 153343
  716. 169276
  717. 184816
  718. 199278
  719. 211060
  720. 223547
  721. 17272
  722. 19792
  723. 22874
  724. 26538
  725. 30614
  726. 35480.679
  727. 43072.751
  728. 51889.696
  729. 60397.973
  730. 63327.987
  731. 66907.826
  732. 69453.57
  733. 5441.766
  734. 6248.643
  735. 7240.26
  736. 8519.282
  737. 10061.506
  738. 11882.916
  739. 14173.318
  740. 16543.189
  741. 17861.905
  742. 20775.703
  743. 24001.816
  744. 27499.638
  745. 2952.156
  746. 2878.22
  747. 2830
  748. 2900.1
  749. 3024.4
  750. 3271.9
  751. 3480
  752. 3539.9
  753. 3557.761
  754. 3667.233
  755. 3879.155
  756. 4109.086
  757. 1620.914
  758. 1944.401
  759. 2310.904
  760. 2693.585
  761. 3095.893
  762. 3495.918
  763. 3858.421
  764. 4203.148
  765. 4936.55
  766. 5531.387
  767. 6029.529
  768. 6426.679
  769. 47666
  770. 49182
  771. 50843.2
  772. 52667.1
  773. 54365.564
  774. 56059.245
  775. 56535.636
  776. 56729.703
  777. 56840.847
  778. 57479.469
  779. 57926.999
  780. 58147.733
  781. 1426.095
  782. 1535.09
  783. 1665.128
  784. 1861.096
  785. 1997.616
  786. 2156.814
  787. 2298.309
  788. 2326.606
  789. 2378.618
  790. 2531.311
  791. 2664.659
  792. 2780.132
  793. 86459.025
  794. 91563.009
  795. 95831.757
  796. 100825.279
  797. 107188.273
  798. 113872.473
  799. 118454.974
  800. 122091.325
  801. 124329.269
  802. 125956.499
  803. 127065.841
  804. 127467.972
  805. 607.914
  806. 746.559
  807. 933.559
  808. 1255.058
  809. 1613.551
  810. 1937.652
  811. 2347.031
  812. 2820.042
  813. 3867.409
  814. 4526.235
  815. 5307.47
  816. 6053.193
  817. 6464.046
  818. 7454.779
  819. 8678.557
  820. 10191.512
  821. 12044.785
  822. 14500.404
  823. 17661.452
  824. 21198.082
  825. 25020.539
  826. 28263.827
  827. 31386.842
  828. 35610.177
  829. 8865.488
  830. 9411.381
  831. 10917.494
  832. 12617.009
  833. 14781.241
  834. 16325.32
  835. 17647.518
  836. 19067.554
  837. 20711.375
  838. 21585.105
  839. 22215.365
  840. 23301.725
  841. 20947.571
  842. 22611.552
  843. 26420.307
  844. 30131
  845. 33505
  846. 36436
  847. 39326
  848. 41622
  849. 43805.45
  850. 46173.816
  851. 47969.15
  852. 49044.79
  853. 160
  854. 212.846
  855. 358.266
  856. 575.003
  857. 841.934
  858. 1140.357
  859. 1497.494
  860. 1891.487
  861. 1418.095
  862. 1765.345
  863. 2111.561
  864. 2505.559
  865. 1439.529
  866. 1647.412
  867. 1886.848
  868. 2186.894
  869. 2680.018
  870. 3115.787
  871. 3086.876
  872. 3089.353
  873. 3219.994
  874. 3430.388
  875. 3677.78
  876. 3921.278
  877. 748.747
  878. 813.338
  879. 893.143
  880. 996.38
  881. 1116.779
  882. 1251.524
  883. 1411.807
  884. 1599.2
  885. 1803.195
  886. 1982.823
  887. 2046.772
  888. 2012.649
  889. 863.308
  890. 975.95
  891. 1112.796
  892. 1279.406
  893. 1482.628
  894. 1703.617
  895. 1956.875
  896. 2269.414
  897. 1912.974
  898. 2200.725
  899. 2814.651
  900. 3193.942
  901. 1019.729
  902. 1201.578
  903. 1441.863
  904. 1759.224
  905. 2183.877
  906. 2721.783
  907. 3344.074
  908. 3799.845
  909. 4364.501
  910. 4759.67
  911. 5368.585
  912. 6036.914
  913. 4762.912
  914. 5181.679
  915. 5703.324
  916. 6334.556
  917. 7082.43
  918. 8007.166
  919. 9171.477
  920. 10568.642
  921. 12210.395
  922. 14165.114
  923. 16473.477
  924. 19167.654
  925. 2917.802
  926. 3221.238
  927. 3628.608
  928. 4147.252
  929. 4730.997
  930. 5637.246
  931. 6502.825
  932. 7824.747
  933. 10014.249
  934. 10419.991
  935. 11824.495
  936. 13327.079
  937. 6748.378
  938. 7739.235
  939. 8906.385
  940. 10154.878
  941. 11441.462
  942. 12845.381
  943. 14441.916
  944. 16331.785
  945. 18319.502
  946. 20476.091
  947. 22662.365
  948. 24821.286
  949. 3838.168
  950. 4241.884
  951. 4690.372
  952. 5212.416
  953. 5828.158
  954. 6491.649
  955. 6998.256
  956. 7634.008
  957. 8416.215
  958. 9384.984
  959. 10580.176
  960. 12031.795
  961. 1022.556
  962. 1076.852
  963. 1146.757
  964. 1230.542
  965. 1332.786
  966. 1456.688
  967. 1622.136
  968. 1841.24
  969. 2119.465
  970. 2444.741
  971. 2828.858
  972. 3270.065
  973. 516.556
  974. 609.816
  975. 701.016
  976. 789.309
  977. 851.334
  978. 913.025
  979. 992.04
  980. 1042.663
  981. 1096.202
  982. 1149.818
  983. 1200.206
  984. 1250.882
  985. 30144.317
  986. 35015.548
  987. 41121.485
  988. 47995.559
  989. 55984.294
  990. 63759.976
  991. 71640.904
  992. 80122.492
  993. 88111.03
  994. 95895.146
  995. 102479.927
  996. 108700.891
  997. 800.663
  998. 882.134
  999. 1010.28
  1000. 1149.5
  1001. 1320.5
  1002. 1528
  1003. 1756.032
  1004. 2015.133
  1005. 2312.802
  1006. 2494.803
  1007. 2674.234
  1008. 2874.127
  1009. 413.834
  1010. 442.829
  1011. 474.528
  1012. 501.035
  1013. 527.678
  1014. 560.073
  1015. 562.548
  1016. 569.473
  1017. 621.621
  1018. 692.651
  1019. 720.23
  1020. 684.736
  1021. 9939.217
  1022. 11406.35
  1023. 13056.604
  1024. 14770.296
  1025. 16660.67
  1026. 18396.941
  1027. 20198.73
  1028. 22987.397
  1029. 25798.239
  1030. 28529.501
  1031. 31167.783
  1032. 33757.175
  1033. 6446.316
  1034. 7038.035
  1035. 7788.944
  1036. 8680.909
  1037. 9809.596
  1038. 11127.868
  1039. 12587.223
  1040. 12891.952
  1041. 13160.731
  1042. 16603.334
  1043. 18473.78
  1044. 19951.656
  1045. 20092.996
  1046. 21731.844
  1047. 23634.436
  1048. 25870.271
  1049. 28466.39
  1050. 31528.087
  1051. 34680.442
  1052. 38028.578
  1053. 40546.538
  1054. 43247.867
  1055. 45598.081
  1056. 47761.98
  1057. 485.831
  1058. 548.08
  1059. 621.392
  1060. 706.64
  1061. 821.782
  1062. 977.026
  1063. 1099.01
  1064. 1278.184
  1065. 1554.253
  1066. 1774.766
  1067. 1972.153
  1068. 2055.08
  1069. 9182.536
  1070. 9682.338
  1071. 10332.057
  1072. 11261.69
  1073. 12412.593
  1074. 13933.198
  1075. 15796.314
  1076. 17917.18
  1077. 20326.209
  1078. 23001.113
  1079. 25873.917
  1080. 28901.79
  1081. 10381.988
  1082. 11026.383
  1083. 11805.689
  1084. 12596.822
  1085. 13329.874
  1086. 13852.989
  1087. 14310.401
  1088. 14665.278
  1089. 15174.244
  1090. 15604.464
  1091. 16122.83
  1092. 16570.613
  1093. 1994.794
  1094. 2229.407
  1095. 2488.55
  1096. 2728.15
  1097. 2929.1
  1098. 3164.9
  1099. 3210.65
  1100. 3317.166
  1101. 3437.674
  1102. 3676.187
  1103. 3908.037
  1104. 4115.771
  1105. 1165.79
  1106. 1358.828
  1107. 1590.597
  1108. 1865.49
  1109. 2182.908
  1110. 2554.598
  1111. 2979.423
  1112. 3344.353
  1113. 4017.939
  1114. 4609.572
  1115. 5146.848
  1116. 5675.356
  1117. 3379.468
  1118. 3692.184
  1119. 4076.008
  1120. 4534.062
  1121. 5060.262
  1122. 5682.086
  1123. 6437.188
  1124. 7332.638
  1125. 8392.818
  1126. 9666.252
  1127. 11140.655
  1128. 12894.865
  1129. 33119.096
  1130. 37173.34
  1131. 41871.351
  1132. 47287.752
  1133. 53740.085
  1134. 62209.173
  1135. 73039.376
  1136. 81551.52
  1137. 93364.244
  1138. 106207.839
  1139. 119901.274
  1140. 135031.164
  1141. 3327.728
  1142. 3491.938
  1143. 3638.919
  1144. 3786.019
  1145. 3933.004
  1146. 4043.205
  1147. 4114.787
  1148. 4186.147
  1149. 4286.357
  1150. 4405.672
  1151. 4535.591
  1152. 4627.926
  1153. 507.833
  1154. 561.977
  1155. 628.164
  1156. 714.775
  1157. 829.05
  1158. 1004.533
  1159. 1301.048
  1160. 1593.882
  1161. 1915.208
  1162. 2283.635
  1163. 2713.462
  1164. 3204.897
  1165. 41346.56
  1166. 46679.944
  1167. 53100.671
  1168. 60641.899
  1169. 69325.921
  1170. 78152.686
  1171. 91462.088
  1172. 105186.881
  1173. 120065.004
  1174. 135564.834
  1175. 153403.524
  1176. 169270.617
  1177. 940.08
  1178. 1063.506
  1179. 1215.725
  1180. 1405.486
  1181. 1616.384
  1182. 1839.782
  1183. 2036.305
  1184. 2253.639
  1185. 2484.997
  1186. 2734.531
  1187. 2990.875
  1188. 3242.173
  1189. 1555.876
  1190. 1770.902
  1191. 2009.813
  1192. 2287.985
  1193. 2614.104
  1194. 2984.494
  1195. 3366.439
  1196. 3886.512
  1197. 4483.945
  1198. 5154.123
  1199. 5884.491
  1200. 6667.147
  1201. 8025.7
  1202. 9146.1
  1203. 10516.5
  1204. 12132.2
  1205. 13954.7
  1206. 15990.099
  1207. 18125.129
  1208. 20195.924
  1209. 22430.449
  1210. 24748.122
  1211. 26769.436
  1212. 28674.757
  1213. 22438.691
  1214. 26072.194
  1215. 30325.264
  1216. 35356.6
  1217. 40850.141
  1218. 46850.962
  1219. 53456.774
  1220. 60017.788
  1221. 67185.766
  1222. 75012.988
  1223. 82995.088
  1224. 91077.287
  1225. 25730.551
  1226. 28235.346
  1227. 30329.617
  1228. 31785.378
  1229. 33039.545
  1230. 34621.254
  1231. 36227.381
  1232. 37740.71
  1233. 38370.697
  1234. 38654.957
  1235. 38625.976
  1236. 38518.241
  1237. 8526.05
  1238. 8817.65
  1239. 9019.8
  1240. 9103
  1241. 8970.45
  1242. 9662.6
  1243. 9859.65
  1244. 9915.289
  1245. 9927.68
  1246. 10156.415
  1247. 10433.867
  1248. 10642.836
  1249. 2227
  1250. 2260
  1251. 2448.046
  1252. 2648.961
  1253. 2847.132
  1254. 3080.828
  1255. 3279.001
  1256. 3444.468
  1257. 3585.176
  1258. 3759.43
  1259. 3859.606
  1260. 3942.491
  1261. 257.7
  1262. 308.7
  1263. 358.9
  1264. 414.024
  1265. 461.633
  1266. 492.095
  1267. 517.81
  1268. 562.035
  1269. 622.191
  1270. 684.81
  1271. 743.981
  1272. 798.094
  1273. 16630
  1274. 17829.327
  1275. 18680.721
  1276. 19284.814
  1277. 20662.648
  1278. 21658.597
  1279. 22356.726
  1280. 22686.371
  1281. 22797.027
  1282. 22562.458
  1283. 22404.337
  1284. 22276.056
  1285. 2534.927
  1286. 2822.082
  1287. 3051.242
  1288. 3451.079
  1289. 3992.121
  1290. 4657.072
  1291. 5507.565
  1292. 6349.365
  1293. 7290.203
  1294. 7212.583
  1295. 7852.401
  1296. 8860.588
  1297. 60.011
  1298. 61.325
  1299. 65.345
  1300. 70.787
  1301. 76.595
  1302. 86.796
  1303. 98.593
  1304. 110.812
  1305. 125.911
  1306. 145.608
  1307. 170.372
  1308. 199.579
  1309. 4005.677
  1310. 4419.65
  1311. 4943.029
  1312. 5618.198
  1313. 6472.756
  1314. 8128.505
  1315. 11254.672
  1316. 14619.745
  1317. 16945.857
  1318. 21229.759
  1319. 24501.53
  1320. 27601.038
  1321. 2755.589
  1322. 3054.547
  1323. 3430.243
  1324. 3965.841
  1325. 4588.696
  1326. 5260.855
  1327. 6147.783
  1328. 7171.347
  1329. 8307.92
  1330. 9535.314
  1331. 10870.037
  1332. 12267.493
  1333. 6860.147
  1334. 7271.135
  1335. 7616.06
  1336. 7971.222
  1337. 8313.288
  1338. 8686.367
  1339. 9032.824
  1340. 9230.783
  1341. 9826.397
  1342. 10336.594
  1343. 10111.559
  1344. 10150.265
  1345. 2143.249
  1346. 2295.678
  1347. 2467.895
  1348. 2662.19
  1349. 2879.013
  1350. 3140.897
  1351. 3464.522
  1352. 3868.905
  1353. 4260.884
  1354. 4578.212
  1355. 5359.092
  1356. 6144.562
  1357. 1127
  1358. 1445.929
  1359. 1750.2
  1360. 1977.6
  1361. 2152.4
  1362. 2325.3
  1363. 2651.869
  1364. 2794.552
  1365. 3235.865
  1366. 3802.309
  1367. 4197.776
  1368. 4553.009
  1369. 3558.137
  1370. 3844.277
  1371. 4237.384
  1372. 4442.238
  1373. 4593.433
  1374. 4827.803
  1375. 5048.043
  1376. 5199.318
  1377. 5302.888
  1378. 5383.01
  1379. 5410.052
  1380. 5447.502
  1381. 1489.518
  1382. 1533.07
  1383. 1582.962
  1384. 1646.912
  1385. 1694.51
  1386. 1746.919
  1387. 1861.252
  1388. 1945.87
  1389. 1999.21
  1390. 2011.612
  1391. 2011.497
  1392. 2009.245
  1393. 2526.994
  1394. 2780.415
  1395. 3080.153
  1396. 3428.839
  1397. 3840.161
  1398. 4353.666
  1399. 5828.892
  1400. 6921.858
  1401. 6099.799
  1402. 6633.514
  1403. 7753.31
  1404. 9118.773
  1405. 14264.935
  1406. 16151.549
  1407. 18356.657
  1408. 20997.321
  1409. 23935.81
  1410. 27129.932
  1411. 31140.029
  1412. 35933.379
  1413. 39964.159
  1414. 42835.005
  1415. 44433.622
  1416. 43997.828
  1417. 28549.87
  1418. 29841.614
  1419. 31158.061
  1420. 32850.275
  1421. 34513.161
  1422. 36439
  1423. 37983.31
  1424. 38880.702
  1425. 39549.438
  1426. 39855.442
  1427. 40152.517
  1428. 40448.191
  1429. 7982.342
  1430. 9128.546
  1431. 10421.936
  1432. 11737.396
  1433. 13016.733
  1434. 14116.836
  1435. 15410.151
  1436. 16495.304
  1437. 17587.06
  1438. 18698.655
  1439. 19576.783
  1440. 20378.239
  1441. 8504.667
  1442. 9753.392
  1443. 11183.227
  1444. 12716.129
  1445. 14597.019
  1446. 17104.986
  1447. 20367.053
  1448. 24725.96
  1449. 28227.588
  1450. 32160.729
  1451. 37090.298
  1452. 42292.929
  1453. 290.243
  1454. 326.741
  1455. 370.006
  1456. 420.69
  1457. 480.105
  1458. 551.425
  1459. 649.901
  1460. 779.348
  1461. 962.344
  1462. 1054.486
  1463. 1130.269
  1464. 1133.066
  1465. 7124.673
  1466. 7363.802
  1467. 7561.588
  1468. 7867.931
  1469. 8122.293
  1470. 8251.648
  1471. 8325.26
  1472. 8421.403
  1473. 8718.867
  1474. 8897.619
  1475. 8954.175
  1476. 9031.088
  1477. 4815
  1478. 5126
  1479. 5666
  1480. 6063
  1481. 6401.4
  1482. 6316.424
  1483. 6468.126
  1484. 6649.942
  1485. 6995.447
  1486. 7193.761
  1487. 7361.757
  1488. 7554.661
  1489. 3661.549
  1490. 4149.908
  1491. 4834.621
  1492. 5680.812
  1493. 6701.172
  1494. 7932.503
  1495. 9410.494
  1496. 11242.847
  1497. 13219.062
  1498. 15081.016
  1499. 17155.814
  1500. 19314.747
  1501. 8550.362
  1502. 10164.215
  1503. 11918.938
  1504. 13648.692
  1505. 15226.039
  1506. 16785.196
  1507. 18501.39
  1508. 19757.799
  1509. 20686.918
  1510. 21628.605
  1511. 22454.239
  1512. 23174.294
  1513. 8322.925
  1514. 9452.826
  1515. 10863.958
  1516. 12607.312
  1517. 14706.593
  1518. 17129.565
  1519. 19844.382
  1520. 23040.63
  1521. 26605.473
  1522. 30686.889
  1523. 34593.779
  1524. 38139.64
  1525. 21289.402
  1526. 25041.917
  1527. 29263.397
  1528. 34024.249
  1529. 39276.153
  1530. 44148.285
  1531. 48827.16
  1532. 52910.342
  1533. 56667.095
  1534. 60216.677
  1535. 62806.748
  1536. 65068.149
  1537. 1219.113
  1538. 1357.445
  1539. 1528.098
  1540. 1735.55
  1541. 2056.351
  1542. 2308.582
  1543. 2644.765
  1544. 3154.264
  1545. 3747.553
  1546. 4320.89
  1547. 4977.378
  1548. 5701.579
  1549. 662.85
  1550. 764.9
  1551. 887.498
  1552. 960.155
  1553. 975.199
  1554. 1039.009
  1555. 1116.479
  1556. 1191.336
  1557. 1183.669
  1558. 1138.101
  1559. 1101.832
  1560. 1056.608
  1561. 3647.735
  1562. 3950.849
  1563. 4286.552
  1564. 4786.986
  1565. 5303.507
  1566. 6005.061
  1567. 6734.098
  1568. 7724.976
  1569. 8523.077
  1570. 9231.669
  1571. 9770.575
  1572. 10276.158
  1573. 22235.677
  1574. 25670.939
  1575. 29788.695
  1576. 33411.317
  1577. 37492.953
  1578. 42404.033
  1579. 47328.791
  1580. 52881.328
  1581. 58179.144
  1582. 63047.647
  1583. 67308.928
  1584. 71158.647
  1585. 5824.797
  1586. 6675.501
  1587. 7688.797
  1588. 8900.294
  1589. 10190.285
  1590. 11457.758
  1591. 12939.4
  1592. 15283.05
  1593. 18252.19
  1594. 21210.254
  1595. 24739.869
  1596. 29170.398
  1597. 50430
  1598. 51430
  1599. 53292
  1600. 54959
  1601. 56079
  1602. 56179
  1603. 56339.704
  1604. 56981.62
  1605. 57866.349
  1606. 58808.266
  1607. 59912.431
  1608. 60776.238
  1609. 157553
  1610. 171984
  1611. 186538
  1612. 198712
  1613. 209896
  1614. 220239
  1615. 232187.835
  1616. 242803.533
  1617. 256894.189
  1618. 272911.76
  1619. 287675.526
  1620. 301139.947
  1621. 2252.965
  1622. 2424.959
  1623. 2598.466
  1624. 2748.579
  1625. 2829.526
  1626. 2873.52
  1627. 2953.997
  1628. 3045.153
  1629. 3149.262
  1630. 3262.838
  1631. 3363.085
  1632. 3447.496
  1633. 5439.568
  1634. 6702.668
  1635. 8143.375
  1636. 9709.552
  1637. 11515.649
  1638. 13503.563
  1639. 15620.766
  1640. 17910.182
  1641. 20265.563
  1642. 22374.398
  1643. 24287.67
  1644. 26084.662
  1645. 26246.839
  1646. 28998.543
  1647. 33796.14
  1648. 39463.91
  1649. 44655.014
  1650. 50533.506
  1651. 56142.181
  1652. 62826.491
  1653. 69940.728
  1654. 76048.996
  1655. 80908.147
  1656. 85262.356
  1657. 1030.585
  1658. 1070.439
  1659. 1133.134
  1660. 1142.636
  1661. 1089.572
  1662. 1261.091
  1663. 1425.876
  1664. 1691.21
  1665. 2104.779
  1666. 2826.046
  1667. 3389.578
  1668. 4018.332
  1669. 4963.829
  1670. 5498.09
  1671. 6120.081
  1672. 6740.785
  1673. 7407.075
  1674. 8403.99
  1675. 9657.618
  1676. 11219.34
  1677. 13367.997
  1678. 15826.497
  1679. 18701.257
  1680. 22211.743
  1681. 2672
  1682. 3016
  1683. 3421
  1684. 3900
  1685. 4506.497
  1686. 5216.55
  1687. 6100.407
  1688. 7272.406
  1689. 8381.163
  1690. 9417.789
  1691. 10595.811
  1692. 11746.035
  1693. 3080.907
  1694. 3646.34
  1695. 4277.736
  1696. 4995.432
  1697. 5861.135
  1698. 6642.107
  1699. 7636.524
  1700. 9216.418
  1701. 10704.34
  1702. 11404.948
  1703. 11926.563
  1704. 12311.143

Back to our example:#

What is going on here?

  • code evaluation is delayed

  • the filter function quotes columns country and year

  • the filter function then creates a data mask (to mingle variables from the environment and the data frame)

  • the columns country and year and unquoted and evaluated within the data mask

filter(gapminder, country == "Canada", year == 1952)

Trade off of lovely interactivity of tidyverse functions…#

programming with them can be more challenging.#

Let’s try writing a function which wraps filter for gapminder:

#filter(gapminder, country == "Canada")

filter_gap <- function(col, val) {
    filter(gapminder, col == val)
}

filter_gap(country, "Canada")
Error: object 'country' not found
Traceback:

1. filter_gap(country, "Canada")
2. filter(gapminder, col == val)   # at line 4 of file <text>
3. filter.tbl_df(gapminder, col == val)
4. filter_impl(.data, quo)

Why does filter work with non-quoted variable names, but our function filter_gap fail?

Proper way of defining this function:#

Use enquo to quote the column names, and then !! to unquote them in context.

filter_gap <- function(col, val) {
    col <- enquo(col)
    filter(gapminder, !!col == val)
}

filter_gap(country, "Canada")
A tibble: 12 × 6
countrycontinentyearlifeExppopgdpPercap
<fct><fct><int><dbl><int><dbl>
CanadaAmericas195268.7501478558411367.16
CanadaAmericas195769.9601701015412489.95
CanadaAmericas196271.3001898584913462.49
CanadaAmericas196772.1302081976716076.59
CanadaAmericas197272.8802228450018970.57
CanadaAmericas197774.2102379640022090.88
CanadaAmericas198275.7602520190022898.79
CanadaAmericas198776.8602654970026626.52
CanadaAmericas199277.9502852350226342.88
CanadaAmericas199778.6103030584328954.93
CanadaAmericas200279.7703190226833328.97
CanadaAmericas200780.6533339014136319.24

Evaluating functions and quoting functions in R#

  • differ in the way they get their arguments

  • evaluating functions take arguments as values

  • a quoting function is not passed the value of an expression, it is passed the expression itself

Evaluating functions#

  • take arguments as values:

identity(6)
6
identity(2 * 3)
6
a <- 2
b <- 3
identity(a * b)
6

Quoting functions#

  • take the expression itself, not the value

typeof(quote(6))
'double'
typeof(quote(2 * 3))
'language'
typeof(quote(a * b))
identity(quote(a * b))
'language'
a * b

You get the code! Not the value!

Not always one or the other:#

In practice some functions take both arguments that are evaluated and quoted, for example:

select(iris, Species)

Here iris is an evaluated argument, and Species is a quoted argument.

How can you tell if an argument is quoted?#

The argument will not work correctly outside of its original context and ordinary indirect references do not work, some examples:

library(dplyr)

temp <- dplyr
Error in eval(expr, envir, enclos): object 'dplyr' not found
Traceback:
temp <- "dplyr"
library(temp)
Error in library(temp): there is no package called ‘temp’
Traceback:

1. library(temp)

We get these errors because there is no dplyr object for R to find, and temp is interpreted by library directly as a package name rather than as an indirect reference.

filter(mtcars, cyl == 4)

temp <- cyl == 4
Error in eval(expr, envir, enclos): object 'cyl' not found
Traceback:
temp <- "cyl" == 4
filter(mtcars, temp)
A data.frame: 0 × 11
mpgcyldisphpdratwtqsecvsamgearcarb
<dbl><dbl><dbl><dbl><dbl><dbl><dbl><dbl><dbl><dbl><dbl>

sum(mtcars2$am)

temp <- mtcars$am
sum(temp)
13

It worked! sum() is an evaluating function and the indirect reference was resolved in the ordinary way.

R cannot find cyl because we haven’t specified where to find it. This object exists only inside the mtcars data frame. And then when we put temp in the subset function it tries to use temp as a column name but it doesn’t exist and so we get nothing returned.

Challenge 1#

Which of the function arguments in the function call below are quoted? Which are evaluated?

arrange(mtcars, cyl)

Let’s try some quoting and unquoting so we can use indirect references in a dplyr function:#

Unquoting is accomplished using the !! (pronounced “bang bang”) operator.

col1 <- quote(country)
val1 <- "Canada"
col2 <- quote(year)
val2 <- 2007

typeof(col1)
col2
'symbol'
'name'
year
filter(gapminder, !!col1 == val1, !!col2 == val2)
A tibble: 1 × 6
countrycontinentyearlifeExppopgdpPercap
<fct><fct><int><dbl><int><dbl>
CanadaAmericas200780.6533339014136319.24

Viewing the unquoted expression:#

The qq_show function from the rlang package performs unquoting and prints the result to the screen:

qq_show(filter(gapminder, !!col1 == val1, !!col2 == val2))
filter(gapminder, country == val1, year == val2)

Challenge 2#

Re-write the code below using quoting and unquoting so that you can create two variables, var_1 and var_2, to indirectly reference the column names in this function call. Also use rlang::qq_show to check your expresion.

arrange(mtcars, hp, mpg)

var_1 <- quote(hp)
var_2 <- quote(mpg)

qq_show(arrange(mtcars, !!var_1, !!var_2))
arrange(mtcars, hp, mpg)

enquo vs quote when writing a function#

  • quote quotes what you typed

  • enquo quotes what your user typed (i.e., it makes a function argument automatically quote its input)

filter_gap <- function(col, val) {
    col <- enquo(col)
    filter(gapminder, !!col == val)
}

filter_gap(country, "Canada")
A tibble: 12 × 6
countrycontinentyearlifeExppopgdpPercap
<fct><fct><int><dbl><int><dbl>
CanadaAmericas195268.7501478558411367.16
CanadaAmericas195769.9601701015412489.95
CanadaAmericas196271.3001898584913462.49
CanadaAmericas196772.1302081976716076.59
CanadaAmericas197272.8802228450018970.57
CanadaAmericas197774.2102379640022090.88
CanadaAmericas198275.7602520190022898.79
CanadaAmericas198776.8602654970026626.52
CanadaAmericas199277.9502852350226342.88
CanadaAmericas199778.6103030584328954.93
CanadaAmericas200279.7703190226833328.97
CanadaAmericas200780.6533339014136319.24

Quote - unquote pattern all in one step: interpolation#

  • In the newest release of rlang, there has been the introduction of the {{ (pronounced “curly curly”) operator.

  • Does the same thing as enguo and !! but (hopefully) easier to use.

filter_gap <- function(col, val) {
    filter(gapminder, {{col}} == val)
}

filter_gap(country, "Canada")
A tibble: 12 × 6
countrycontinentyearlifeExppopgdpPercap
<fct><fct><int><dbl><int><dbl>
CanadaAmericas195268.7501478558411367.16
CanadaAmericas195769.9601701015412489.95
CanadaAmericas196271.3001898584913462.49
CanadaAmericas196772.1302081976716076.59
CanadaAmericas197272.8802228450018970.57
CanadaAmericas197774.2102379640022090.88
CanadaAmericas198275.7602520190022898.79
CanadaAmericas198776.8602654970026626.52
CanadaAmericas199277.9502852350226342.88
CanadaAmericas199778.6103030584328954.93
CanadaAmericas200279.7703190226833328.97
CanadaAmericas200780.6533339014136319.24

Creating functions that handle unquoted column names:#

Or do it all in one step with the brand new curly curly {{ operator:

filter_gap <- function(col, val) {
    filter(gapminder, {{col}} == val)
}

filter_gap(country, "Canada")

Creating functions that handle column names as strings:#

Sometimes you want to pass a column name into a function as a string (often useful when you are programming and have the column names as a character vector).

You can do this by using symbols + unquoting with sym + !! :

# example of what we want to wrap: filter(gapminder, country == "Canada")
filter_gap <- function(col, val) {
    col <- sym(col)
    filter(gapminder, !!col == val)
}

filter_gap("country", "Canada")

Another operator is needed when assigning values…#

  • : is needed before the = when quoting and unquoting:

library(rlang)
r <- quote(c(1, 2, 3))
eval(r)
{{c(1, 2, 3)}}

?eval_tidy
  1. 1
  2. 2
  3. 3
  1. 1
  2. 2
  3. 3
x <- quote(mpg)
typeof(x)
select(mtcars, !!x)
'symbol'
A data.frame: 32 × 1
mpg
<dbl>
Mazda RX421.0
Mazda RX4 Wag21.0
Datsun 71022.8
Hornet 4 Drive21.4
Hornet Sportabout18.7
Valiant18.1
Duster 36014.3
Merc 240D24.4
Merc 23022.8
Merc 28019.2
Merc 280C17.8
Merc 450SE16.4
Merc 450SL17.3
Merc 450SLC15.2
Cadillac Fleetwood10.4
Lincoln Continental10.4
Chrysler Imperial14.7
Fiat 12832.4
Honda Civic30.4
Toyota Corolla33.9
Toyota Corona21.5
Dodge Challenger15.5
AMC Javelin15.2
Camaro Z2813.3
Pontiac Firebird19.2
Fiat X1-927.3
Porsche 914-226.0
Lotus Europa30.4
Ford Pantera L15.8
Ferrari Dino19.7
Maserati Bora15.0
Volvo 142E21.4
old_col <- quote(mpg)
new_col <- quote(kml)

mutate(mtcars, !!new_col := !!old_col * 0.425144)

#mutate(mtcars, mpg = mpg * 0.425144)
A data.frame: 32 × 12
mpgcyldisphpdratwtqsecvsamgearcarbkml
<dbl><dbl><dbl><dbl><dbl><dbl><dbl><dbl><dbl><dbl><dbl><dbl>
21.06160.01103.902.62016.460144 8.928024
21.06160.01103.902.87517.020144 8.928024
22.84108.0 933.852.32018.611141 9.693283
21.46258.01103.083.21519.441031 9.098082
18.78360.01753.153.44017.020032 7.950193
18.16225.01052.763.46020.221031 7.695106
14.38360.02453.213.57015.840034 6.079559
24.44146.7 623.693.19020.00104210.373514
22.84140.8 953.923.15022.901042 9.693283
19.26167.61233.923.44018.301044 8.162765
17.86167.61233.923.44018.901044 7.567563
16.48275.81803.074.07017.400033 6.972362
17.38275.81803.073.73017.600033 7.354991
15.28275.81803.073.78018.000033 6.462189
10.48472.02052.935.25017.980034 4.421498
10.48460.02153.005.42417.820034 4.421498
14.78440.02303.235.34517.420034 6.249617
32.44 78.7 664.082.20019.47114113.774666
30.44 75.7 524.931.61518.52114212.924378
33.94 71.1 654.221.83519.90114114.412382
21.54120.1 973.702.46520.011031 9.140596
15.58318.01502.763.52016.870032 6.589732
15.28304.01503.153.43517.300032 6.462189
13.38350.02453.733.84015.410034 5.654415
19.28400.01753.083.84517.050032 8.162765
27.34 79.0 664.081.93518.90114111.606431
26.04120.3 914.432.14016.70015211.053744
30.44 95.11133.771.51316.90115212.924378
15.88351.02644.223.17014.500154 6.717275
19.76145.01753.622.77015.500156 8.375337
15.08301.03353.543.57014.600158 6.377160
21.44121.01094.112.78018.601142 9.098082
old_col <- quote(mpg)
new_col <- quote(kml)

mutate(mtcars, !!new_col := !!old_col * 0.425144)

Pass the dots when you can#

If you are only passing on variable to a tidyverse function, and that variable is not used in logical comparisons, or in variable assignment, you can get away with passing the dots:

sort_gap <- function(...) {
    arrange(gapminder, ...)
}

sort_gap(year)
A tibble: 1704 × 6
countrycontinentyearlifeExppopgdpPercap
<fct><fct><int><dbl><int><dbl>
Afghanistan Asia 195228.801 8425333 779.4453
Albania Europe 195255.230 1282697 1601.0561
Algeria Africa 195243.077 9279525 2449.0082
Angola Africa 195230.015 4232095 3520.6103
Argentina Americas195262.485 17876956 5911.3151
Australia Oceania 195269.120 869121210039.5956
Austria Europe 195266.800 6927772 6137.0765
Bahrain Asia 195250.939 120447 9867.0848
Bangladesh Asia 195237.484 46886859 684.2442
Belgium Europe 195268.000 8730405 8343.1051
Benin Africa 195238.223 1738315 1062.7522
Bolivia Americas195240.414 2883315 2677.3263
Bosnia and Herzegovina Europe 195253.820 2791000 973.5332
Botswana Africa 195247.622 442308 851.2411
Brazil Americas195250.917 56602560 2108.9444
Bulgaria Europe 195259.600 7274900 2444.2866
Burkina Faso Africa 195231.975 4469979 543.2552
Burundi Africa 195239.031 2445618 339.2965
Cambodia Asia 195239.417 4693836 368.4693
Cameroon Africa 195238.523 5009067 1172.6677
Canada Americas195268.750 1478558411367.1611
Central African RepublicAfrica 195235.463 1291695 1071.3107
Chad Africa 195238.092 2682462 1178.6659
Chile Americas195254.745 6377619 3939.9788
China Asia 195244.000556263527 400.4486
Colombia Americas195250.643 12350771 2144.1151
Comoros Africa 195240.715 153936 1102.9909
Congo, Dem. Rep. Africa 195239.143 14100005 780.5423
Congo, Rep. Africa 195242.111 854885 2125.6214
Costa Rica Americas195257.206 926317 2627.0095
⋮⋮⋮⋮⋮⋮
Sierra Leone Africa 200742.568 6144562 862.5408
Singapore Asia 200779.972 455300947143.1796
Slovak Republic Europe 200774.663 544750218678.3144
Slovenia Europe 200777.926 200924525768.2576
Somalia Africa 200748.159 9118773 926.1411
South Africa Africa 200749.339 43997828 9269.6578
Spain Europe 200780.941 4044819128821.0637
Sri Lanka Asia 200772.396 20378239 3970.0954
Sudan Africa 200758.556 42292929 2602.3950
Swaziland Africa 200739.613 1133066 4513.4806
Sweden Europe 200780.884 903108833859.7484
Switzerland Europe 200781.701 755466137506.4191
Syria Asia 200774.143 19314747 4184.5481
Taiwan Asia 200778.400 2317429428718.2768
Tanzania Africa 200752.517 38139640 1107.4822
Thailand Asia 200770.616 65068149 7458.3963
Togo Africa 200758.420 5701579 882.9699
Trinidad and TobagoAmericas200769.819 105660818008.5092
Tunisia Africa 200773.923 10276158 7092.9230
Turkey Europe 200771.777 71158647 8458.2764
Uganda Africa 200751.542 29170398 1056.3801
United Kingdom Europe 200779.425 6077623833203.2613
United States Americas200778.24230113994742951.6531
Uruguay Americas200776.384 344749610611.4630
Venezuela Americas200773.747 2608466211415.8057
Vietnam Asia 200774.249 85262356 2441.5764
West Bank and Gaza Asia 200773.422 4018332 3025.3498
Yemen, Rep. Asia 200762.698 22211743 2280.7699
Zambia Africa 200742.384 11746035 1271.2116
Zimbabwe Africa 200743.487 12311143 469.7093

Notes on passing the dots#

  • the dots must be the last function argument

  • they are useful because you can add multiple arguments

For example:

sort_gap <- function(..., x) {
    print(x + 1)
    arrange(gapminder, ...)
}

sort_gap(year, continent, country, 2)
sort_gap <- function(x, ...) {
    print(x + 1)
    arrange(gapminder, ...)
}

sort_gap(1, year, continent, country)

Pass the dots is not always the solution…#

library(dplyr)
select_n_change <- function(data, ...) {
    out <- select(data, ...)
    mutate(out, ... := ... / mean(...))
}

select_n_change(mtcars, mpg, cyl, disp, hp)
Error: object 'mpg' not found
Traceback:

1. select_n_change(mtcars, mpg, cyl, disp, hp)
2. mutate(out, `:=`(..., .../mean(...)))   # at line 4 of file <text>
3. mutate.data.frame(out, `:=`(..., .../mean(...)))
4. as.data.frame(mutate(tbl_df(.data), ...))
5. mutate(tbl_df(.data), ...)
6. mutate.tbl_df(tbl_df(.data), ...)
7. mutate_impl(.data, dots, caller_env())

When passing in different column names to different functions, use quote & unquote:#

select_n_change <- function(data, col_range, col_to_change) {
    out <- select(data, {{col_range}})
    mutate(out, {{col_to_change}} := {{col_to_change}} / mean({{col_to_change}}))
}

select_n_change(mtcars, mpg:hp, mpg)
A data.frame: 32 × 4
mpgcyldisphp
<dbl><dbl><dbl><dbl>
1.04526366160.0110
1.04526366160.0110
1.13485774108.0 93
1.06517346258.0110
0.93078248360.0175
0.90091776225.0105
0.71177488360.0245
1.21449684146.7 62
1.13485774140.8 95
0.95566966167.6123
0.88598546167.6123
0.81630118275.8180
0.86109818275.8180
0.75657188275.8180
0.51765448472.0205
0.51765448460.0215
0.73168468440.0230
1.61269254 78.7 66
1.51314364 75.7 52
1.68735424 71.1 65
1.07015094120.1 97
0.77150418318.0150
0.75657188304.0150
0.66200038350.0245
0.95566968400.0175
1.35884274 79.0 66
1.29413594120.3 91
1.51314364 95.1113
0.78643658351.0264
0.98055696145.0175
0.74661698301.0335
1.06517344121.0109

Combine quoting & unquoting with pass the dots:#

select_n_change <- function(data, col_to_change, ...) {
    out <- select(data, ...)
    mutate(out, {{col_to_change}} := {{col_to_change}} / mean({{col_to_change}}))
}

select_n_change(mtcars, mpg, mpg, drat, carb)
A data.frame: 32 × 3
mpgdratcarb
<dbl><dbl><dbl>
1.04526363.904
1.04526363.904
1.13485773.851
1.06517343.081
0.93078243.152
0.90091772.761
0.71177483.214
1.21449683.692
1.13485773.922
0.95566963.924
0.88598543.924
0.81630113.073
0.86109813.073
0.75657183.073
0.51765442.934
0.51765443.004
0.73168463.234
1.61269254.081
1.51314364.932
1.68735424.221
1.07015093.701
0.77150412.762
0.75657183.152
0.66200033.734
0.95566963.082
1.35884274.081
1.29413594.432
1.51314363.772
0.78643654.224
0.98055693.626
0.74661693.548
1.06517344.112
head(mtcars)

Another operator is needed when assigning values…#

mutate(mtcars, kml = mpg * 0.425144)

What did we learn?#

  • quoting and unquoting

  • data masking

  • without and quoting and unquoting function arguments for quoted functions, R will attempt to evaluate the arguments - potentially out of context.

  • introduction to the tidyverse

Attribution:#

iris[c(2, 4)]
A data.frame: 150 × 2
Sepal.WidthPetal.Width
<dbl><dbl>
3.50.2
3.00.2
3.20.2
3.10.2
3.60.2
3.90.4
3.40.3
3.40.2
2.90.2
3.10.1
3.70.2
3.40.2
3.00.1
3.00.1
4.00.2
4.40.4
3.90.4
3.50.3
3.80.3
3.80.3
3.40.2
3.70.4
3.60.2
3.30.5
3.40.2
3.00.2
3.40.4
3.50.2
3.40.2
3.20.2
⋮⋮
3.22.3
2.82.0
2.82.0
2.71.8
3.32.1
3.21.8
2.81.8
3.01.8
2.82.1
3.01.6
2.81.9
3.82.0
2.82.2
2.81.5
2.61.4
3.02.3
3.42.4
3.11.8
3.01.8
3.12.1
3.12.4
3.12.3
2.71.9
3.22.3
3.32.5
3.02.3
2.51.9
3.02.0
3.42.3
3.01.8