Lecture 8: Tidy evaluation in R
Contents
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 oflibrary("purrr")
enable
plot(x, sin(x))
to automatically label the axes withx
andsin(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, ]
country | continent | year | lifeExp | pop | gdpPercap |
---|---|---|---|---|---|
<fct> | <fct> | <int> | <dbl> | <int> | <dbl> |
Canada | Americas | 1952 | 68.75 | 14785584 | 11367.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)
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
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)
- 6567086329.95223
- 7585448670.23365
- 8758855796.92893
- 9648014149.8489
- 9678553274.06687
- 11697659230.9699
- 12598563400.5169
- 11820990309.4608
- 10595901588.9034
- 14121995875.3377
- 18363410423.9786
- 31079291948.8899
- 2053669902.47879
- 2867792397.68722
- 3996988985.21125
- 5476396322.91986
- 7500110047.33615
- 8864476394.37768
- 10094200602.59
- 11498418357.5329
- 8307722182.8007
- 10945912518.587
- 16153932129.8053
- 21376411360.0421
- 22725632677.9121
- 30956113719.6857
- 28061403854.4022
- 41433235246.8537
- 61739408942.5438
- 84227416173.9838
- 115097120652.669
- 132119742844.669
- 132102425042.615
- 139467033682.098
- 165447670333.368
- 207444851958.217
- 14899557133.3119
- 17460618347.3729
- 20603593596.0431
- 28980597821.7449
- 32264255582.5783
- 18541315838.4746
- 19343845632.962
- 19136019188.7255
- 22956828370.0118
- 22486820880.8812
- 30134833900.6471
- 59583895818.2231
- 105676319104.619
- 134466639305.962
- 151820757736.505
- 184688236498.044
- 233996596623.536
- 271970723959.561
- 264010673179.124
- 289004799538.515
- 316104097626.698
- 397053586287.393
- 337223430799.523
- 515033625356.566
- 87256254101.5157
- 106349227168.697
- 131884573002.44
- 172457986741.708
- 221223770657.96
- 258037329175.491
- 295742804309.376
- 355853119294.078
- 409511234952.423
- 501223252920.637
- 599847158654.326
- 703658358893.63
- 42516266683.1358
- 61596299913.2558
- 76651179416.229
- 94680836235.5952
- 125698652513.146
- 149472120217.989
- 163589550350.139
- 179527736065.401
- 214036739549.621
- 234800471832.038
- 264148781751.719
- 296229400691.084
- 1188460758.68995
- 1613361772.73975
- 2191816125.38582
- 2993238335.8314
- 4216406356.412
- 5751939723.9236
- 7261179715.31877
- 8421243625.96472
- 10079167850.3025
- 12146009861.8392
- 15362026094.1502
- 21112675360.4188
- 32082059995.381
- 33985317661.0907
- 39011165929.1472
- 45306268649.6704
- 44594887096.4333
- 53072807953.8147
- 63009685013.4918
- 78028572051.8102
- 95262852013.6523
- 119957417048.458
- 154159077920.52
- 209311822133.851
- 72838686716.2864
- 87328859400.7762
- 101321340396.384
- 125658812132.235
- 161871509038.396
- 187772921747.664
- 206783717985.145
- 222331812712.216
- 256922515586.019
- 281118335091.118
- 314369518653.487
- 350141166520.108
- 1847398090.543
- 1847398090.94943
- 2043222288.54147
- 2514308802.18827
- 2998327102.24875
- 3260657629.22202
- 4653595792.11845
- 5202273024.96588
- 5934204759.41495
- 7479326759.29536
- 9645995478.4122
- 11643151767.5441
- 7719575216.20031
- 6833571025.29459
- 7838236490.57523
- 10452739933.3452
- 13607811411.4626
- 18023329326.7757
- 17809739028.5252
- 16952740924.5998
- 20416331717.304
- 25588644883.2829
- 28825460794.2505
- 34854649033.8328
- 2717131146.6868
- 4164870705.376
- 5725730640.971
- 7787883436.455
- 10922988275.25
- 14417374612.23
- 17219089833.9218
- 18718844705.9836
- 10839134938.0788
- 17192245745.728
- 25071535764.1344
- 33897026518.419
- 376510766.460736
- 435828972.132401
- 504382347.55477
- 672391397.310054
- 1401969807.06701
- 2512321368.7481
- 4416187131.82605
- 7144114193.9784
- 10679301652.14
- 13286645461.0478
- 17939694531.3628
- 20603633701.6119
- 119371649390.549
- 163049753284.523
- 253711949066.741
- 301998949547.859
- 502759433503.545
- 761344477467.542
- 906717258453.525
- 1115931255372.57
- 1084077163776.14
- 1341291557750.12
- 1462920751252.62
- 1722598680331.38
- 17781940935.5352
- 23020103934.6417
- 34089779369.6637
- 46346153670.6328
- 56581431456.1276
- 66965046602.3756
- 73130318095.9054
- 73927631407.0254
- 54571302853.6636
- 48157496050.3193
- 58971163876.6273
- 78213929148.2796
- 2428339520.25093
- 2909042417.92376
- 3554493256.92842
- 4075818934.41522
- 4644537855.3129
- 4378232963.87432
- 5355436506.56396
- 6919413539.72728
- 8272383440.67205
- 9796843171.2064
- 12712408470.3222
- 17435461729.7418
- 829789526.732977
- 1012495477.62006
- 1052081766.98828
- 1375623555.04895
- 1638263359.07543
- 2132330701.24842
- 2563212235.30471
- 3187457567.51423
- 3669693671.31136
- 2835010319.92396
- 3134233881.43858
- 3608510288.22326
- 1729534397.64356
- 2310184670.86911
- 3023033307.89866
- 3643123976.79705
- 3141354495.62457
- 3663574552.4848
- 4541488549.53182
- 5725430804.6556
- 6925441367.8235
- 8652054255.27354
- 11585251105.5606
- 24218877033.9786
- 5873970852.62788
- 7037836705.93638
- 8108811857.22315
- 9556813969.87289
- 11824439929.1908
- 14195884905.6421
- 21905813152.6073
- 28058456117.7054
- 22355673217.7465
- 24052491091.4674
- 30808779174.4326
- 36137515700.9453
- 168070115581.294
- 212455973972.909
- 255596717816.982
- 334710816939.589
- 422749686329.67
- 525683489648.984
- 577093069633.066
- 706925986091.991
- 751391311875.879
- 877503438098.975
- 1063269575825.78
- 1212704377996.04
- 1383806691.42853
- 1657993504.36515
- 1817613997.68293
- 1969510917.91537
- 2062193784.3765
- 2404605486.96815
- 2369849412.12717
- 2399456439.02315
- 2442004280.06313
- 2737291281.71136
- 2990229179.30429
- 3084613078.78141
- 3161726559.87227
- 3787904963.55633
- 4378505050.64671
- 4184010240.49135
- 4304976524.38412
- 4976220796.687
- 3889896143.58087
- 5237128465.99519
- 6802736597.5131
- 7599528805.96088
- 10215721151.4945
- 17447579585.7373
- 25127683584.3234
- 30418347406.984
- 35977675895.4284
- 45239380746.6702
- 53388314323.134
- 50420712011.4859
- 58534483046.9687
- 69135019226.6709
- 103102172132.616
- 147722858046.224
- 167039309147.507
- 214496727217.788
- 222754956737.111
- 367138722269.667
- 324678731163.591
- 462317080954.97
- 583508186392.963
- 699324197164.504
- 962691820907.921
- 1494780217152.63
- 1928938870545.26
- 2815929679840.2
- 3993927259238.4
- 6539500929092.31
- 26481474548.339
- 33662631379.7269
- 42394605743.7125
- 52942488863.7017
- 73594872191.6585
- 95755454802.6224
- 122097122635.2
- 151824477501.079
- 186221797590.287
- 230366568679.371
- 236013006965.707
- 309883885810.343
- 169790012.724096
- 207019199.012544
- 269639001.761542
- 407807571.736054
- 484446733.347225
- 357337879.939733
- 441765574.237369
- 519962442.552568
- 566630869.24173
- 619649302.95177
- 660959256.627156
- 701111696.196032
- 11005650695.0816
- 14111429069.1177
- 15673346681.9319
- 17181093743.0051
- 20819549223.4493
- 21072345136.1953
- 20648009138.6626
- 23871157044.3257
- 19074139151.9732
- 14922290060.3391
- 13355730548.0203
- 17931726045.033
- 1817161865.92693
- 2177213473.58998
- 2582905425.01607
- 3159326072.04592
- 4307096219.14881
- 5008605218.84208
- 8659832782.05667
- 8671665463.48701
- 9675414210.84662
- 9758959756.46407
- 11597728065.4262
- 13805935492.6568
- 2433443532.14831
- 3325789015.0646
- 4655607493.84867
- 6611807759.24898
- 9390755531.08945
- 12496565229.2099
- 12758800460.0776
- 15762698836.4049
- 19548331623.7655
- 23490559858.5006
- 29618910245.3101
- 39871565083.1553
- 4133872900.46391
- 4952956552.5
- 6625733026.82262
- 9736712727.82351
- 14439714172.8543
- 18781242084.851
- 23491934452.5957
- 23211215640.2038
- 21050180710.6314
- 26125858896.0236
- 26797508004.7935
- 27826215570.2518
- 12109590475.8031
- 17314932235.4983
- 22330930898.108
- 29054830740.8311
- 38721121654.5144
- 48824261688.2794
- 58352765410.3571
- 61984751387.9814
- 37964499980.5954
- 43893062449.3464
- 52107043452.729
- 65688728878.4486
- 33562790922.8677
- 40456619058.878
- 37583135793.0944
- 46314980543.066
- 46854233350.6851
- 60857084419.7684
- 71626950339.079
- 77135936772.2332
- 59973519954.6794
- 59659588751.8779
- 71186433969.3943
- 102160374746.553
- 62746038114.9158
- 78548858000.6239
- 97519520387.1307
- 112114783032.643
- 129277640538.869
- 150397974206.787
- 158442411319.549
- 168186719232.11
- 147483810393.196
- 165311042971.568
- 180471922898.335
- 233556067421.811
- 42006797651.83
- 49813395320.3699
- 63120285966.3055
- 77116977699.724
- 94172484444.6072
- 103920280027.729
- 110995270448.949
- 128771236166.089
- 136559629613.111
- 157476118455.789
- 172885062706.982
- 192906627080.569
- 168578116.816775
- 205850893.079676
- 271580892.765174
- 385409786.317521
- 660702490.730496
- 704780255.165268
- 881091313.289397
- 895783901.2122
- 913198814.093952
- 791942757.749472
- 853786444.069672
- 1033689705.33806
- 3482196998.3964
- 4514577213.34207
- 5740081668.24081
- 6696165882.70544
- 10229624253.5392
- 14222050738.92
- 17075997880.8907
- 19299310927.751
- 22378569689.8867
- 28885187703.8787
- 39478410078.3256
- 56154215096.9837
- 12499100973.2859
- 15342913820.2186
- 19129988881.7711
- 24875472663.3472
- 33263142611.1362
- 48620082640.0232
- 60349495671.0319
- 61869585518.9499
- 76353394349.8824
- 88498333675.3103
- 74594859031.9678
- 94546397112.5117
- 31530929611.3705
- 36487093093.6646
- 47706874227.3476
- 57497577541.3449
- 70450495584.0263
- 108032201471.667
- 160056715026.851
- 205148680925.854
- 225416799454.919
- 275990419358.701
- 348572216623.035
- 447970942204.754
- 6227271303.8085
- 8060441504.58049
- 10377474227.4607
- 14091020728.1053
- 17135814152.4652
- 22007877013.9792
- 18339569693.4148
- 20048823879.4408
- 23441762292.1733
- 29812618811.7607
- 34002160153.3595
- 39752986140.8636
- 81501034.5602684
- 99247227.5674682
- 145255876.112308
- 237930439.59366
- 186663659.807731
- 184691860.57917
- 264878362.310024
- 329947736.703736
- 439053960.276492
- 1238289912.25811
- 3818060562.4293
- 6699346424.28975
- 473266515.933196
- 530907910.970085
- 634974530.368959
- 853356390.813398
- 1162468889.15893
- 1270778258.88694
- 1384253502.73134
- 1519605766.20333
- 2138181473.15809
- 3707155863.00201
- 3378916934.3723
- 3146934083.95291
- 7554712172.1051
- 8644931130.56421
- 10547387620.6213
- 14379218703.5052
- 17423536805.7812
- 19275480698.0561
- 22023287795.4529
- 24670606852.1823
- 21947694837.1335
- 30881810733.9291
- 36015439731.1423
- 52854838162.2307
- 26279495259.9255
- 32626376129.064
- 42093096667.7055
- 50302260674.6774
- 66620259081.5663
- 73952569459.9327
- 89458310061.9101
- 104261743104.046
- 104083163954.025
- 121808392250.581
- 146467538809.042
- 173953983346.024
- 298483363097.914
- 383857690356.897
- 497652320115.72
- 644392918488.54
- 833257241541.72
- 972528294778.168
- 1104669186492.24
- 1227558382892.41
- 1417360022289.61
- 1517747939261.93
- 1733393500385.63
- 1861227940621.4
- 1806274139.98545
- 2164168458.0475
- 3021697340.55574
- 4087468046.69095
- 6133985999.76657
- 15360355361.0738
- 11393570619.1556
- 10445389597.3507
- 13329318031.6073
- 16580702573.9953
- 16269512983.1117
- 19213678514.1588
- 137960780.995312
- 168337466.691965
- 224281196.22952
- 323005424.810653
- 390973259.137566
- 538173615.364292
- 598041000.148448
- 518935047.710407
- 682520622.689438
- 807858171.484697
- 962979227.33227
- 1270911775.48381
- 493986590900.887
- 723529963816.389
- 951416222108.651
- 1126100616352.88
- 1418181247737.45
- 1603305779824.91
- 1725845977575.61
- 1914915573601.21
- 2136268169644.11
- 2278996207434.3
- 2473468447076.13
- 2650870893900.92
- 5085960279.25404
- 6669702328.68966
- 8753047553.08727
- 9557408661.89508
- 11021245951.477
- 10466686429.7478
- 9987067385.60832
- 12000468163.6855
- 15058811881.2057
- 18514906876.2099
- 22852118178.3181
- 30366847330.2416
- 27303708960.6278
- 39803435654.7198
- 50834629317.8248
- 74203907867.2401
- 113106276411.13
- 132138739654.37
- 149424095671.567
- 160794049220.771
- 181123475012.43
- 196895300009.988
- 238738073446.292
- 294834223726.725
- 7640161179.86399
- 9528740348.50709
- 11575893401.4627
- 15209977556.0066
- 20760063435.5844
- 27832697038.7256
- 30830101093.7677
- 31111480318.8294
- 37677392867.0872
- 45924427024.6021
- 54309766224.9818
- 65203833292.1188
- 1359290494.41378
- 1657762332.32179
- 2155215395.16702
- 2446225437.134
- 2826777030.02898
- 3697319890.22857
- 4038075238.19478
- 4551695525.65761
- 5552951540.41964
- 6998056844.31191
- 8328528109.01737
- 9377348758.33953
- 174108987.278307
- 259547084.509977
- 327743619.74295
- 430269336.403937
- 512936468.326124
- 569895199.805518
- 692279501.213028
- 683042950.14216
- 783516180.528623
- 950984748.886715
- 767102932.308578
- 852652874.197463
- 5891912670.80523
- 6057406350.57928
- 6970999000.73416
- 6270183933.68824
- 7773136723.84875
- 9200097514.95577
- 10454809788.3621
- 10493650139.467
- 9213607207.63259
- 9276089515.1804
- 9664493045.29473
- 10217297215.9514
- 3330697353.03841
- 3931129187.33598
- 4788888952.55727
- 6347422262.58766
- 7501351909.90737
- 9786553395.52551
- 11455138902.0217
- 13217592456.6579
- 15646832847.4582
- 18545413488.847
- 20697904973.8205
- 26554867097.0535
- 6493394048.2131
- 9930241909.2891
- 15510141068.6144
- 23073775963.9592
- 34225865466.3765
- 51273915647.625
- 76653912869.895
- 111905051122.032
- 144329299236.985
- 184338771740.4
- 204287740003.136
- 277296717807.812
- 50025955947.264
- 59429331128.229
- 75979271442.251
- 95350224305.4607
- 105693936955.046
- 124187241501.88
- 134311542120.303
- 137822135542.945
- 109029890605.328
- 119993697078.531
- 149676048403.31
- 179298995810.64
- 1075341715.18374
- 1526277073.13532
- 1884277507.35018
- 2646343594.11968
- 3306139764.0755
- 4359922739.98281
- 5445018346.1775
- 6587462419.76528
- 6512699263.29412
- 7609945738.99472
- 8975937060.5388
- 10924101860.9259
- 203322458739.6
- 241335356364
- 298889606508.6
- 354589929014.2
- 410526442809
- 515655862782
- 605852264691.6
- 769491988372.8
- 1015362737448
- 1399005926878
- 1806461015264.98
- 2722925438772.82
- 61512879123.2392
- 77407527996.5668
- 84103467353.4628
- 83366577256.7303
- 134757389176.774
- 189049938606.6
- 232601854598.884
- 295954872930.236
- 440442568204.768
- 621614960294.634
- 606568050342.2
- 791502035177.508
- 52426150706.544
- 65120779270.256
- 95780981890.948
- 156752848641.09
- 294317442834.698
- 421815425794.459
- 327711901836.63
- 344697094905.253
- 437018785886.188
- 523316539155.054
- 618279294330.716
- 806058303731.229
- 22473220511.4949
- 38924881556.8564
- 60396350632.4319
- 76089624801.5757
- 96349359728.3796
- 174539063525.064
- 205766914164.491
- 192621823480.477
- 66904278115.3287
- 63911044337.7009
- 105385189030.639
- 122952583890.59
- 15381560331.9872
- 16115377912.7478
- 18767420398.62
- 22201915549.5963
- 28824869546.6624
- 36484895159.247
- 43911758506.8
- 49108560194.148
- 62470069169.9836
- 89927693739.3913
- 132190156526.465
- 167141167137.836
- 6623900928.58499
- 10471140805.4029
- 16420430421.0182
- 22609255939.6933
- 39586973982.3314
- 46518849615.3848
- 59292468172.8932
- 71968316978.5993
- 89112243594.837
- 115587232694.216
- 132080421158.889
- 164029908949.751
- 235060310452.23
- 307321410802.224
- 419130105629.088
- 527850812033.901
- 667025988920.112
- 799179741816.514
- 934957147512.006
- 1089620726789.86
- 1251274219399.6
- 1418307303522.81
- 1620107994725.49
- 1661264433000.44
- 4133580396.7397
- 7301695161.15529
- 8735440529.22307
- 11398661093.8423
- 14850056193.9255
- 14343234914.5844
- 13946257030.1671
- 14776827263.292
- 17613484765.7673
- 18027806344.4069
- 18638689786.3374
- 20353013484.5546
- 278134909229.182
- 395341088001.744
- 630251873020.733
- 992906033833.796
- 1584112586964.36
- 1891464707591.05
- 2296143737891.3
- 2731908393473.1
- 3335119600027.97
- 3629636158476.35
- 3634666526235.29
- 4035134797102.17
- 940386912.584598
- 1408070439.93637
- 2192005081.53332
- 3441113320.44262
- 3405974308.24326
- 5526864720.43834
- 9766972259.66773
- 12545464196.3963
- 13271376154.7506
- 16499844607.0714
- 20406782659.6392
- 27357170724.069
- 5517327763.29827
- 7040578918.94834
- 7784373796.89947
- 10769742282.353
- 14723063007.1669
- 18380903573.7344
- 23811625092.9085
- 28870449152.3102
- 33575604755.2276
- 38452513269.6354
- 40411021465.9563
- 52106565927.1429
- 9648113404.2159
- 14786546840.5086
- 17704830126.0034
- 27045071155.6185
- 54714559526.6252
- 67036681906.3247
- 72469979025.6728
- 78300763966.8475
- 77171898567.2921
- 36495163359.6555
- 36583333391.1901
- 37121173721.953
- 21588403826.183
- 33636798616.7394
- 40590690362.2668
- 61142673146.602
- 101549522158.25
- 169690505084.72
- 221127835339.264
- 355164222241.71
- 530233376255.024
- 738482217215.895
- 922638064104.647
- 1145104609948.51
- 17341176464
- 24162944745.2334
- 34199395867.8082
- 46514800559.1498
- 92063687054.778
- 67583801714.939
- 46952480381.4606
- 53185644767.5803
- 49538198605.981
- 71144497943.2862
- 74137129817.5353
- 118530454006.187
- 6959840663.76444
- 10032388072.5148
- 10782507259.7441
- 13136635172.6515
- 20063644788.7981
- 26981770825.5499
- 23585336336.9064
- 16611733228.5201
- 22188356725.0389
- 30032922931.4738
- 34254617950.1974
- 41020719258.593
- 223760204.771239
- 273279221.601204
- 367796847.043404
- 496833953.22407
- 554571893.955524
- 932847869.180179
- 1125581635.86907
- 1237769947.98872
- 1762598359.14064
- 2351921523.90706
- 2610012082.9419
- 3158513357.40986
- 496896772.117099
- 606035661.838095
- 705729840.04935
- 912988789.25691
- 1190558369.5118
- 1090864191.36933
- 1119723032.36962
- 1148581873.35062
- 1217843092.0424
- 1340624342.87433
- 1495937378.2921
- 1323912407.32519
- 2434651995.67574
- 4143382666.77531
- 9742712723.45021
- 33025475319.0886
- 45886525492.4832
- 59746434997.7681
- 58067421827.0981
- 44726416798.581
- 42074394127.753
- 45061918969.3615
- 51187726429.1742
- 72790086208.4219
- 6872937813.51408
- 8234738516.41725
- 9372769145.75364
- 10350964014.4768
- 12384074920.6063
- 12364894630.0473
- 11949321645.6379
- 12211452300.1946
- 12707067346.995
- 13970993798.9061
- 14737783396.9688
- 20025792284.7044
- 1077150609.33772
- 1341226242.42832
- 1552685302.41684
- 2055024664.87291
- 2765844790.46199
- 3738755018.01864
- 4115013156.92654
- 4972762582.71206
- 5640025182.00661
- 7213507712.84371
- 7868292338.77011
- 10119916240.5456
- 12357176936.9459
- 14008533816.8311
- 18141281511.9674
- 23130196146.8077
- 32597809659.7684
- 49171111017.6135
- 71059367334.4421
- 85738648221.2256
- 133327738132.065
- 207482379883.417
- 231314259623.228
- 309066109785.359
- 1736145324.53936
- 2080144351.64774
- 2327242244.58752
- 2840818256.72072
- 3388309666.19322
- 4455837163.55608
- 4325020632.17221
- 5222971144.09086
- 6219703868.09062
- 7416558541.34325
- 10066082622.1603
- 12544127564.6048
- 759877632.159193
- 911146295.621428
- 1210856170.55525
- 1748778848.08461
- 2114933837.79187
- 2181378951.33742
- 2402627042.9837
- 2617513368.27424
- 2885375609.24556
- 3625883720.26078
- 4466822066.37189
- 5896422596.76724
- 1016559328.18509
- 1240388905.4215
- 1772916773.46679
- 1953845681.17466
- 2192597230.16677
- 3388220219.79308
- 3658680958.59756
- 4987669071.04269
- 6641069982.49289
- 8538209610.88631
- 10828037566.8742
- 13705902966.1678
- 104845718511.969
- 144668369722.174
- 188402581601.137
- 276201669610.826
- 381219826098.527
- 489353295727.781
- 688551298314.617
- 696116709845.12
- 834621536788.274
- 936636422664.789
- 1100884521316.24
- 1301973070171.29
- 629774979.826522
- 805090717.486539
- 1067213276.68824
- 1409334278.935
- 1877410277.9875
- 2517397824.12
- 3513123131.38445
- 4711397687.66443
- 4129281353.40883
- 4745744245.8363
- 5724837882.70358
- 8897642669.93242
- 1095660939.60423
- 1630611470.58559
- 2206362439.60848
- 2960040094.2198
- 4104497951.66253
- 5374421249.68307
- 6313244220.45576
- 6681347764.04041
- 4353422615.51898
- 4478413551.7982
- 4722688037.72486
- 6336475807.4617
- 16779421622.4047
- 18729253094.2939
- 20451257282.1178
- 25272637722.1519
- 32158341514.1333
- 43612155831.8934
- 54589498863.3479
- 63331358935.7724
- 76054427590.3892
- 85077877939.9129
- 101560083268.57
- 128958323769.775
- 3020266895.82064
- 3487957478.30457
- 4335998836.09128
- 4919203358.1129
- 7111150787.50431
- 5589747687.07039
- 5817958152.49182
- 5026265057.80634
- 5407702568.10227
- 7842519681.68105
- 11705318549.5401
- 16433892152.3625
- 6650781676
- 7606145400
- 9170161168
- 9028724579
- 10162501230
- 11696920277
- 14704507408
- 14641002530
- 14069648686
- 17947864805
- 27860427491
- 45087309120
- 1177547676.40313
- 1436763251.62864
- 1971810785.00824
- 2680776460.25992
- 3078461893.60934
- 3787427569.60091
- 4606061372.59411
- 4721268295.25201
- 5913214598.55975
- 6920743072.82316
- 8031247474.6589
- 9887114066.42932
- 5012431651.69527
- 5789421899.34386
- 6740601536.90858
- 7617882645.36493
- 8375870413.95605
- 9671206057.99648
- 11347646973.0329
- 13897146222.2827
- 18247658193.2257
- 23251644296.9496
- 27354068342.6902
- 31542251118.2026
- 92831291730.8937
- 124335627651.528
- 151004791951.147
- 193528142723.178
- 250531591643.146
- 293808863797.949
- 306234860366.244
- 346853235808.614
- 406532406373.845
- 471974656555.132
- 543738536478.117
- 609764312245.525
- 21058193787.114
- 27304428858.1752
- 32788333486.9
- 39459740428.8795
- 47000447796.848
- 51378093148.73
- 56611498450.76
- 63050008702.6841
- 63127124699.7896
- 77385257445.895
- 90626601698.45
- 103655730129.674
- 3628362766.93892
- 4698033596.43012
- 5780809121.09038
- 8662204203.74166
- 10234767751.2804
- 14015472611.2172
- 10339605319.764
- 9885855212.48438
- 8719537247.77683
- 10385471754.5943
- 12736126639.9725
- 15603375234.6385
- 2574746971.05197
- 3084906138.33606
- 4066902657.4941
- 4780646467.65724
- 4828548738.49791
- 4596222732.79786
- 5856052413.33125
- 4900402142.58415
- 4877760835.66905
- 5609376389.03992
- 6696363647.16629
- 7990649871.11753
- 35678601207.9222
- 40912701545.8704
- 48190888406.8828
- 47974091350.4542
- 91271560517.1712
- 123295582777.116
- 115181178668.38
- 112951266107.586
- 151235904174.953
- 172581501319.655
- 193674896635.367
- 271949699763.733
- 33594817529.4522
- 40694951309.3515
- 48944921612.3677
- 61946375191.0729
- 74589639181.052
- 94252564410.3949
- 108213282691.329
- 132035157036.096
- 145588949429.931
- 181880081160.08
- 202668235988.123
- 228421423674.687
- 928435681.494731
- 1260371978.49133
- 1837152375.61453
- 3374411809.10042
- 8802884859.8775
- 11902052462.9894
- 16854804933.9785
- 28873528072.8907
- 35654866007.6873
- 44992304219.6694
- 53658268402.9439
- 71521099580.4844
- 28305736881.9553
- 34873817306.3784
- 42658038632.5597
- 57149426446.9155
- 72787986851.6265
- 91901399757.2744
- 132019106316.209
- 179310664748.318
- 236747712482.478
- 277819863187.178
- 321029463168.042
- 441110354736.257
- 2331755944.38672
- 3149893033.27293
- 4299460457.43322
- 6213666373.43482
- 8670687327.27859
- 9846351628.11261
- 14273686782.0154
- 15853852673.6169
- 16447556623.0208
- 19452611987.5538
- 22000972010.6022
- 31803076821.027
- 3037550252.47708
- 3623539461.16481
- 4317132882.3837
- 5260938508.92334
- 6596267899.02761
- 9694750656.43963
- 14335992614.1462
- 15541678375.1258
- 18816476471.1427
- 21891623375.4261
- 22264997029.8653
- 27820927446.7422
- 30164781548.3309
- 38827542285.5778
- 52130689937.703
- 70222305898.226
- 82860598386.0801
- 100438462619.245
- 116626175121.357
- 128465130363.322
- 99734320550.3549
- 144488140093.85
- 158181134666.889
- 212448566597.624
- 28561783326.5775
- 40358318274.0677
- 50023104521.4934
- 64141377891.538
- 81266211261.2439
- 111186903868.474
- 139162617315.734
- 131417048927.291
- 153138130044.342
- 190273063890.606
- 220013427319.714
- 290580355162.284
- 103676873315.934
- 133673272043.01
- 161922307755.119
- 208421579588.909
- 264531348088.038
- 329183780346.863
- 306176833715.221
- 342774381700.612
- 296946267447.619
- 392718270288.302
- 463598198650.342
- 592792827796.088
- 26160648602.0354
- 33282852529.6639
- 42645207507.8022
- 57908898290.279
- 80933619341.8277
- 98292660518.072
- 115888777247.581
- 129288514715.632
- 160900556777.318
- 179169637551.457
- 208373796584.833
- 218280817633.876
- 6863524441.195
- 8830172987.14
- 12505462638.093
- 18355386422.5552
- 25974504080.9839
- 30101306751.3146
- 33875323753.8391
- 42302689206.0539
- 52492666708.6814
- 63908179531.019
- 72775210745.9651
- 76203261313.5439
- 700656740.5215
- 854929784.2428
- 1139049306.726
- 1664863264.16374
- 2330165765.41338
- 2125753982.35036
- 2727418853.17693
- 2980683766.46808
- 3796146461.76819
- 4158126197.66691
- 4699106901.6612
- 6121478792.80445
- 52294917283.18
- 70307637223.5886
- 88453168839.7395
- 124789457739.148
- 165537035770.656
- 202646437193.072
- 214743374426.87
- 219973253287.762
- 150424128715.758
- 165756170699.815
- 176666264621.071
- 240770207962.994
- 1250540010.98911
- 1524740985.73326
- 1823034933.29129
- 1763376143.83762
- 2357669470.14992
- 3120613605.12598
- 4855307638.79229
- 5384205753.52721
- 5373379681.74576
- 4255023708.42767
- 6169268408.36928
- 7647471286.17077
- 52784690.5494405
- 52784690.551945
- 70020507.871055
- 98028711.056691
- 117419005.53013
- 150813401.580972
- 186362274.809381
- 168049218.941084
- 179898843.338554
- 194980183.449888
- 230529056.66908
- 319014076.627531
- 25874890184.7302
- 36053698159.2232
- 57469729990.4227
- 94964675299.1543
- 160766615318.859
- 277732829132.913
- 379205636077.268
- 309913175526.553
- 420962502379.079
- 437050471341.364
- 465885351158.005
- 597695839259.554
- 3996587748.42799
- 4788469786.51828
- 5677013482.14969
- 6394540398.17551
- 7331414920.51898
- 8216240862.75418
- 9335285431.47547
- 10339079560.2098
- 11364398525.7025
- 13276669392.306
- 16518491524.4447
- 21007739941.0751
- 24569338287.8189
- 36218184315.7313
- 47902193037.4614
- 63703671182.0546
- 87472977399.8071
- 112754859703.889
- 137128138486.785
- 146500635545.173
- 91631822558.6785
- 81807115768.4046
- 73168001828.9263
- 99335920778.7992
- 1885604184.96561
- 2305972823.36329
- 2755749969.24892
- 3210716852.08835
- 3897491953.67491
- 4234824811.04762
- 5075562091.40525
- 5008095519.23214
- 4553590871.78975
- 2630861090.90221
- 3748629725.0206
- 5299935153.38333
- 2609160781.829
- 4110927115.00096
- 6431522198.1144
- 9843342904.704
- 18505810449.1848
- 26066821067.844
- 40226628130.1333
- 52709528648.1471
- 80152023987.888
- 127451407551.469
- 151216927293.59
- 214643321189.537
- 18056332320.3293
- 23424190728.9655
- 31700325638.0436
- 37372114718.2445
- 44437640820.8001
- 52732470220.3041
- 57287947438.2716
- 62585581999.5104
- 50369310506.684
- 65275620851.2565
- 73786500198.1752
- 101750154778.254
- 6278380543.97084
- 8987280431.62103
- 11717564986.756
- 15490013353.7921
- 20983941200.762
- 26687734267.5462
- 33254471590.631
- 36346000744.7804
- 28418203993.7201
- 34521489478.5482
- 41557566962.5819
- 51774742721.4196
- 2870033036.23495
- 3498171939.31639
- 4218233606.59541
- 4405143232.17802
- 4817774314.43645
- 6317136770.10266
- 6859481088.53965
- 7567286393.10125
- 5654271489.02042
- 6173124436.1414
- 6839053809.78016
- 8445270167.8052
- 67406033605.5055
- 88625232661.2852
- 105894592740.676
- 149384977704.516
- 185884606122.395
- 217816767591.772
- 266816058819.641
- 281208278147.402
- 288743816612.724
- 320371065827.681
- 342625279554.94
- 407844809855.241
- 109461193459.584
- 136221071505.49
- 177409134906.359
- 262589077073.781
- 367176936800.991
- 482340170513.63
- 528962031083.201
- 612953611112.557
- 735740746843.74
- 814856426872.94
- 997206698031.168
- 1165759889360.77
- 8649123231.41426
- 9790790993.50069
- 11198078000.9146
- 13327981307.9351
- 15794445637.4035
- 19040444665.9602
- 25397158408.5381
- 30957839348.4804
- 37877940921.6673
- 49822140983.9893
- 59031417076.4342
- 80903553056.6483
- 13743466427.099
- 17266791454.855
- 21914581924.1461
- 21464795754.6517
- 24225983090.0777
- 37682086133.5771
- 38606646598.6269
- 37282276212.6676
- 42121123344.6223
- 52493088051.887
- 73935737498.9576
- 110062906753.49
- 333308277.060118
- 406697255.561724
- 686798523.34275
- 1099305739.44885
- 1615474887.84562
- 2085164350.03065
- 2531613968.68222
- 3105576937.80258
- 3419229788.5056
- 4087998066.31156
- 4665882609.04767
- 5114071458.24144
- 60758104611.5455
- 72989108704.3753
- 93230160068.9689
- 120051227737.469
- 144836928909.3
- 155590807217.646
- 172061322425.375
- 198635036915.166
- 208206690698.532
- 224812535648.329
- 262730098132.633
- 305790367006.705
- 70945330691.25
- 91804044355.98
- 115762571238.2
- 139243733012.16
- 174086796614.256
- 170431587415.5
- 183679999508.265
- 201371579184.634
- 222955601022.544
- 231173833391.741
- 253840431788.296
- 283348281397.785
- 6017702154.45335
- 8786330020.33984
- 10602503376.9816
- 10690854351.7492
- 17231547901.5724
- 25348191033.1687
- 35400751245.9812
- 35041416419.7894
- 44158841963.8436
- 60538802164.5556
- 70183154066.5244
- 80823487648.3685
- 10319841571.2945
- 15326226341.7374
- 21726782116.2323
- 36085212828.4953
- 61856147294.154
- 93938682197.2959
- 137397885952.136
- 218413809089.588
- 314765067293.352
- 437045349282.133
- 521733747819.826
- 665525790663.551
- 5964624801.33289
- 6603135550.61123
- 7843819038.34729
- 10693757259.3236
- 13471019459.7353
- 16487074298.3685
- 17348804251.9994
- 19165704757.286
- 21967672236.4707
- 24217670028.5989
- 31102374563.3927
- 42238971727.8945
- 16133053859.9772
- 19872699754.4962
- 29327752243.3073
- 44077076065.5443
- 59870954797.2532
- 86584704135.001
- 116854125162.052
- 157813231197.02
- 261626115120.687
- 352425659154.813
- 371388079010.646
- 485304043506.289
- 1048203910.89551
- 1256869619.71389
- 1631297808.09138
- 2564443056.818
- 3392280377.25399
- 3538541387.59684
- 3556092709.86604
- 3792060473.7533
- 3876089960.58191
- 4244353748.33863
- 4411054800.61842
- 5034322889.20126
- 2003975797.4748
- 3136390911.66
- 4435292529.21456
- 5397385045.23316
- 6455379924.25738
- 8207707919.13888
- 10181762179.6148
- 8802302576.06153
- 8724813465.48951
- 10006836267.2737
- 12627656072.6214
- 19027934931.0579
- 5356609955.84579
- 5512352800.96533
- 7116976045.43192
- 9250181066.38666
- 14602071542.181
- 18741055623.5405
- 23974959096.5671
- 29435397611.5369
- 36928107577.2246
- 45020990584.1068
- 55915981214.3516
- 72887997686.7379
- 43784293371.6635
- 56957505187.4373
- 69195263214.0901
- 94432289201.0317
- 129376797192.61
- 181028003992.741
- 200738267961.7
- 269115388365.695
- 330361441740.66
- 416204622976.16
- 438052273010.69
- 601879503437.493
- 4279789889.34275
- 5169314846.81567
- 5899396651.15902
- 8089642065.17538
- 9688269464.83266
- 9667290102.6184
- 8828115615.05592
- 9440712990.75982
- 11757527777.4702
- 17319425514.0166
- 22951696053.0808
- 30815028568.8582
- 503266612999.41
- 580293841968.5
- 664933720414.44
- 777276942063.51
- 891382233156.39
- 979129659734.34
- 1027209400659.14
- 1234494698392.63
- 1313860808996.94
- 1533397976044.22
- 1766158504919.93
- 2017969309929.46
- 2204242423150.24
- 2553468310606.08
- 3016906282432.68
- 3880918003145.84
- 4576999719662.24
- 5301732427679.07
- 5806915391021.06
- 7256025860958
- 8221624217605.75
- 9761353098899.43
- 11247278678120.6
- 12934458535085
- 12879675387.396
- 14915372268.1333
- 14560134513.4621
- 14964967150.52
- 16137943765.5223
- 18690350108.4238
- 20442318131.9848
- 22693695077.6473
- 25625559931.7261
- 30116780131.2093
- 25986564534.6223
- 36582976212.173
- 41829188706.3432
- 65702678704.8914
- 68591437240.9069
- 92643439785.0438
- 120974882898.419
- 177490169722.235
- 174209188664.344
- 177016799858.086
- 217529059872.663
- 227446835024.402
- 208996562053.544
- 297777432881.327
- 15881082791.9447
- 19611292638.3026
- 26092281505.0016
- 25143376124.1608
- 31236255710.3085
- 36057532314.5293
- 39705759524.1319
- 51567948937.8148
- 69172999028.9303
- 105396057842.094
- 142758920197.848
- 208174556559.048
- 1561946720.38247
- 1955764566.67874
- 2491712161.64181
- 3027659756.73845
- 3414075012.75944
- 4644385651.59995
- 6182644080.95383
- 8637343287.79464
- 12665833359.6789
- 20095073782.0045
- 15305597343.4934
- 12156859904.4969
- 3880312374.05489
- 4425030274.68152
- 5052880863.15125
- 5813537083.14685
- 9370298237.14433
- 15377328249.8562
- 19098490175.8022
- 22121638706.9449
- 25125105886.174
- 33512362498.2854
- 41793958634.6795
- 50659874994.2062
- 3065822956.432
- 3956861606.256
- 4969774845.486
- 6930601540.2
- 7992264610.72771
- 8287471946.14845
- 8593512578.67595
- 8823720129.4891
- 10148621483.3682
- 10089784202.2684
- 11354618752.0137
- 14931695863.7838
- 1253572117.47612
- 1891590901.34375
- 2255531193.8844
- 2846372532.11476
- 4685169626.25753
- 4553746742.39019
- 6024110453.88114
- 6508240904.92827
- 7422611852.1295
- 9037850589.82356
- 8015110972.06478
- 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)
- 8425.333
- 9240.934
- 10267.083
- 11537.966
- 13079.46
- 14880.372
- 12881.816
- 13867.957
- 16317.921
- 22227.415
- 25268.405
- 31889.923
- 1282.697
- 1476.505
- 1728.137
- 1984.06
- 2263.554
- 2509.048
- 2780.097
- 3075.321
- 3326.498
- 3428.038
- 3508.512
- 3600.523
- 9279.525
- 10270.856
- 11000.948
- 12760.499
- 14760.787
- 17152.804
- 20033.753
- 23254.956
- 26298.373
- 29072.015
- 31287.142
- 33333.216
- 4232.095
- 4561.361
- 4826.015
- 5247.469
- 5894.858
- 6162.675
- 7016.384
- 7874.23
- 8735.988
- 9875.024
- 10866.106
- 12420.476
- 17876.956
- 19610.538
- 21283.783
- 22934.225
- 24779.799
- 26983.828
- 29341.374
- 31620.918
- 33958.947
- 36203.463
- 38331.121
- 40301.927
- 8691.212
- 9712.569
- 10794.968
- 11872.264
- 13177
- 14074.1
- 15184.2
- 16257.249
- 17481.977
- 18565.243
- 19546.792
- 20434.176
- 6927.772
- 6965.86
- 7129.864
- 7376.998
- 7544.201
- 7568.43
- 7574.613
- 7578.903
- 7914.969
- 8069.876
- 8148.312
- 8199.783
- 120.447
- 138.655
- 171.863
- 202.182
- 230.8
- 297.41
- 377.967
- 454.612
- 529.491
- 598.561
- 656.397
- 708.573
- 46886.859
- 51365.468
- 56839.289
- 62821.884
- 70759.295
- 80428.306
- 93074.406
- 103764.241
- 113704.579
- 123315.288
- 135656.79
- 150448.339
- 8730.405
- 8989.111
- 9218.4
- 9556.5
- 9709.1
- 9821.8
- 9856.303
- 9870.2
- 10045.622
- 10199.787
- 10311.97
- 10392.226
- 1738.315
- 1925.173
- 2151.895
- 2427.334
- 2761.407
- 3168.267
- 3641.603
- 4243.788
- 4981.671
- 6066.08
- 7026.113
- 8078.314
- 2883.315
- 3211.738
- 3593.918
- 4040.665
- 4565.872
- 5079.716
- 5642.224
- 6156.369
- 6893.451
- 7693.188
- 8445.134
- 9119.152
- 2791
- 3076
- 3349
- 3585
- 3819
- 4086
- 4172.693
- 4338.977
- 4256.013
- 3607
- 4165.416
- 4552.198
- 442.308
- 474.639
- 512.764
- 553.541
- 619.351
- 781.472
- 970.347
- 1151.184
- 1342.614
- 1536.536
- 1630.347
- 1639.131
- 56602.56
- 65551.171
- 76039.39
- 88049.823
- 100840.058
- 114313.951
- 128962.939
- 142938.076
- 155975.974
- 168546.719
- 179914.212
- 190010.647
- 7274.9
- 7651.254
- 8012.946
- 8310.226
- 8576.2
- 8797.022
- 8892.098
- 8971.958
- 8658.506
- 8066.057
- 7661.799
- 7322.858
- 4469.979
- 4713.416
- 4919.632
- 5127.935
- 5433.886
- 5889.574
- 6634.596
- 7586.551
- 8878.303
- 10352.843
- 12251.209
- 14326.203
- 2445.618
- 2667.518
- 2961.915
- 3330.989
- 3529.983
- 3834.415
- 4580.41
- 5126.023
- 5809.236
- 6121.61
- 7021.078
- 8390.505
- 4693.836
- 5322.536
- 6083.619
- 6960.067
- 7450.606
- 6978.607
- 7272.485
- 8371.791
- 10150.094
- 11782.962
- 12926.707
- 14131.858
- 5009.067
- 5359.923
- 5793.633
- 6335.506
- 7021.028
- 7959.865
- 9250.831
- 10780.667
- 12467.171
- 14195.809
- 15929.988
- 17696.293
- 14785.584
- 17010.154
- 18985.849
- 20819.767
- 22284.5
- 23796.4
- 25201.9
- 26549.7
- 28523.502
- 30305.843
- 31902.268
- 33390.141
- 1291.695
- 1392.284
- 1523.478
- 1733.638
- 1927.26
- 2167.533
- 2476.971
- 2840.009
- 3265.124
- 3696.513
- 4048.013
- 4369.038
- 2682.462
- 2894.855
- 3150.417
- 3495.967
- 3899.068
- 4388.26
- 4875.118
- 5498.955
- 6429.417
- 7562.011
- 8835.739
- 10238.807
- 6377.619
- 7048.426
- 7961.258
- 8858.908
- 9717.524
- 10599.793
- 11487.112
- 12463.354
- 13572.994
- 14599.929
- 15497.046
- 16284.741
- 556263.527
- 637408
- 665770
- 754550
- 862030
- 943455
- 1000281
- 1084035
- 1164970
- 1230075
- 1280400
- 1318683.096
- 12350.771
- 14485.993
- 17009.885
- 19764.027
- 22542.89
- 25094.412
- 27764.644
- 30964.245
- 34202.721
- 37657.83
- 41008.227
- 44227.55
- 153.936
- 170.928
- 191.689
- 217.378
- 250.027
- 304.739
- 348.643
- 395.114
- 454.429
- 527.982
- 614.382
- 710.96
- 14100.005
- 15577.932
- 17486.434
- 19941.073
- 23007.669
- 26480.87
- 30646.495
- 35481.645
- 41672.143
- 47798.986
- 55379.852
- 64606.759
- 854.885
- 940.458
- 1047.924
- 1179.76
- 1340.458
- 1536.769
- 1774.735
- 2064.095
- 2409.073
- 2800.947
- 3328.795
- 3800.61
- 926.317
- 1112.3
- 1345.187
- 1588.717
- 1834.796
- 2108.457
- 2424.367
- 2799.811
- 3173.216
- 3518.107
- 3834.934
- 4133.884
- 2977.019
- 3300
- 3832.408
- 4744.87
- 6071.696
- 7459.574
- 9025.951
- 10761.098
- 12772.596
- 14625.967
- 16252.726
- 18013.409
- 3882.229
- 3991.242
- 4076.557
- 4174.366
- 4225.31
- 4318.673
- 4413.368
- 4484.31
- 4494.013
- 4444.595
- 4481.02
- 4493.312
- 6007.797
- 6640.752
- 7254.373
- 8139.332
- 8831.348
- 9537.988
- 9789.224
- 10239.839
- 10723.26
- 10983.007
- 11226.999
- 11416.987
- 9125.183
- 9513.758
- 9620.282
- 9835.109
- 9862.158
- 10161.915
- 10303.704
- 10311.597
- 10315.702
- 10300.707
- 10256.295
- 10228.744
- 4334
- 4487.831
- 4646.899
- 4838.8
- 4991.596
- 5088.419
- 5117.81
- 5127.024
- 5171.393
- 5283.663
- 5374.693
- 5468.12
- 63.149
- 71.851
- 89.898
- 127.617
- 178.848
- 228.694
- 305.991
- 311.025
- 384.156
- 417.908
- 447.416
- 496.374
- 2491.346
- 2923.186
- 3453.434
- 4049.146
- 4671.329
- 5302.8
- 5968.349
- 6655.297
- 7351.181
- 7992.357
- 8650.322
- 9319.622
- 3548.753
- 4058.385
- 4681.707
- 5432.424
- 6298.651
- 7278.866
- 8365.85
- 9545.158
- 10748.394
- 11911.819
- 12921.234
- 13755.68
- 22223.309
- 25009.741
- 28173.309
- 31681.188
- 34807.417
- 38783.863
- 45681.811
- 52799.062
- 59402.198
- 66134.291
- 73312.559
- 80264.543
- 2042.865
- 2355.805
- 2747.687
- 3232.927
- 3790.903
- 4282.586
- 4474.873
- 4842.194
- 5274.649
- 5783.439
- 6353.681
- 6939.688
- 216.964
- 232.922
- 249.22
- 259.864
- 277.603
- 192.675
- 285.483
- 341.244
- 387.838
- 439.971
- 495.627
- 551.201
- 1438.76
- 1542.611
- 1666.618
- 1820.319
- 2260.187
- 2512.642
- 2637.297
- 2915.959
- 3668.44
- 4058.319
- 4414.865
- 4906.585
- 20860.941
- 22815.614
- 25145.372
- 27860.297
- 30770.372
- 34617.799
- 38111.756
- 42999.53
- 52088.559
- 59861.301
- 67946.797
- 76511.887
- 4090.5
- 4324
- 4491.443
- 4605.744
- 4639.657
- 4738.902
- 4826.933
- 4931.729
- 5041.039
- 5134.406
- 5193.039
- 5238.46
- 42459.667
- 44310.863
- 47124
- 49569
- 51732
- 53165.019
- 54433.565
- 55630.1
- 57374.179
- 58623.428
- 59925.035
- 61083.916
- 420.702
- 434.904
- 455.661
- 489.004
- 537.977
- 706.367
- 753.874
- 880.397
- 985.739
- 1126.189
- 1299.304
- 1454.867
- 284.32
- 323.15
- 374.02
- 439.593
- 517.101
- 608.274
- 715.523
- 848.406
- 1025.384
- 1235.767
- 1457.766
- 1688.359
- 69145.952
- 71019.069
- 73739.117
- 76368.453
- 78717.088
- 78160.773
- 78335.266
- 77718.298
- 80597.764
- 82011.073
- 82350.671
- 82400.996
- 5581.001
- 6391.288
- 7355.248
- 8490.213
- 9354.12
- 10538.093
- 11400.338
- 14168.101
- 16278.738
- 18418.288
- 20550.751
- 22873.338
- 7733.25
- 8096.218
- 8448.233
- 8716.441
- 8888.628
- 9308.479
- 9786.48
- 9974.49
- 10325.429
- 10502.372
- 10603.863
- 10706.29
- 3146.381
- 3640.876
- 4208.858
- 4690.773
- 5149.581
- 5703.43
- 6395.63
- 7326.406
- 8486.949
- 9803.875
- 11178.65
- 12572.928
- 2664.249
- 2876.726
- 3140.003
- 3451.418
- 3811.387
- 4227.026
- 4710.497
- 5650.262
- 6990.574
- 8048.834
- 8807.818
- 9947.814
- 580.653
- 601.095
- 627.82
- 601.287
- 625.361
- 745.228
- 825.987
- 927.524
- 1050.938
- 1193.708
- 1332.459
- 1472.041
- 3201.488
- 3507.701
- 3880.13
- 4318.137
- 4698.301
- 4908.554
- 5198.399
- 5756.203
- 6326.682
- 6913.545
- 7607.651
- 8502.814
- 1517.453
- 1770.39
- 2090.162
- 2500.689
- 2965.146
- 3055.235
- 3669.448
- 4372.203
- 5077.347
- 5867.957
- 6677.328
- 7483.763
- 2125.9
- 2736.3
- 3305.2
- 3722.8
- 4115.7
- 4583.7
- 5264.5
- 5584.51
- 5829.696
- 6495.918
- 6762.476
- 6980.412
- 9504
- 9839
- 10063
- 10223.422
- 10394.091
- 10637.171
- 10705.535
- 10612.74
- 10348.684
- 10244.684
- 10083.313
- 9956.108
- 147.962
- 165.11
- 182.053
- 198.676
- 209.275
- 221.823
- 233.997
- 244.676
- 259.012
- 271.192
- 288.03
- 301.931
- 372000
- 409000
- 454000
- 506000
- 567000
- 634000
- 708000
- 788000
- 872000
- 959000
- 1034172.547
- 1110396.331
- 82052
- 90124
- 99028
- 109343
- 121282
- 136725
- 153343
- 169276
- 184816
- 199278
- 211060
- 223547
- 17272
- 19792
- 22874
- 26538
- 30614
- 35480.679
- 43072.751
- 51889.696
- 60397.973
- 63327.987
- 66907.826
- 69453.57
- 5441.766
- 6248.643
- 7240.26
- 8519.282
- 10061.506
- 11882.916
- 14173.318
- 16543.189
- 17861.905
- 20775.703
- 24001.816
- 27499.638
- 2952.156
- 2878.22
- 2830
- 2900.1
- 3024.4
- 3271.9
- 3480
- 3539.9
- 3557.761
- 3667.233
- 3879.155
- 4109.086
- 1620.914
- 1944.401
- 2310.904
- 2693.585
- 3095.893
- 3495.918
- 3858.421
- 4203.148
- 4936.55
- 5531.387
- 6029.529
- 6426.679
- 47666
- 49182
- 50843.2
- 52667.1
- 54365.564
- 56059.245
- 56535.636
- 56729.703
- 56840.847
- 57479.469
- 57926.999
- 58147.733
- 1426.095
- 1535.09
- 1665.128
- 1861.096
- 1997.616
- 2156.814
- 2298.309
- 2326.606
- 2378.618
- 2531.311
- 2664.659
- 2780.132
- 86459.025
- 91563.009
- 95831.757
- 100825.279
- 107188.273
- 113872.473
- 118454.974
- 122091.325
- 124329.269
- 125956.499
- 127065.841
- 127467.972
- 607.914
- 746.559
- 933.559
- 1255.058
- 1613.551
- 1937.652
- 2347.031
- 2820.042
- 3867.409
- 4526.235
- 5307.47
- 6053.193
- 6464.046
- 7454.779
- 8678.557
- 10191.512
- 12044.785
- 14500.404
- 17661.452
- 21198.082
- 25020.539
- 28263.827
- 31386.842
- 35610.177
- 8865.488
- 9411.381
- 10917.494
- 12617.009
- 14781.241
- 16325.32
- 17647.518
- 19067.554
- 20711.375
- 21585.105
- 22215.365
- 23301.725
- 20947.571
- 22611.552
- 26420.307
- 30131
- 33505
- 36436
- 39326
- 41622
- 43805.45
- 46173.816
- 47969.15
- 49044.79
- 160
- 212.846
- 358.266
- 575.003
- 841.934
- 1140.357
- 1497.494
- 1891.487
- 1418.095
- 1765.345
- 2111.561
- 2505.559
- 1439.529
- 1647.412
- 1886.848
- 2186.894
- 2680.018
- 3115.787
- 3086.876
- 3089.353
- 3219.994
- 3430.388
- 3677.78
- 3921.278
- 748.747
- 813.338
- 893.143
- 996.38
- 1116.779
- 1251.524
- 1411.807
- 1599.2
- 1803.195
- 1982.823
- 2046.772
- 2012.649
- 863.308
- 975.95
- 1112.796
- 1279.406
- 1482.628
- 1703.617
- 1956.875
- 2269.414
- 1912.974
- 2200.725
- 2814.651
- 3193.942
- 1019.729
- 1201.578
- 1441.863
- 1759.224
- 2183.877
- 2721.783
- 3344.074
- 3799.845
- 4364.501
- 4759.67
- 5368.585
- 6036.914
- 4762.912
- 5181.679
- 5703.324
- 6334.556
- 7082.43
- 8007.166
- 9171.477
- 10568.642
- 12210.395
- 14165.114
- 16473.477
- 19167.654
- 2917.802
- 3221.238
- 3628.608
- 4147.252
- 4730.997
- 5637.246
- 6502.825
- 7824.747
- 10014.249
- 10419.991
- 11824.495
- 13327.079
- 6748.378
- 7739.235
- 8906.385
- 10154.878
- 11441.462
- 12845.381
- 14441.916
- 16331.785
- 18319.502
- 20476.091
- 22662.365
- 24821.286
- 3838.168
- 4241.884
- 4690.372
- 5212.416
- 5828.158
- 6491.649
- 6998.256
- 7634.008
- 8416.215
- 9384.984
- 10580.176
- 12031.795
- 1022.556
- 1076.852
- 1146.757
- 1230.542
- 1332.786
- 1456.688
- 1622.136
- 1841.24
- 2119.465
- 2444.741
- 2828.858
- 3270.065
- 516.556
- 609.816
- 701.016
- 789.309
- 851.334
- 913.025
- 992.04
- 1042.663
- 1096.202
- 1149.818
- 1200.206
- 1250.882
- 30144.317
- 35015.548
- 41121.485
- 47995.559
- 55984.294
- 63759.976
- 71640.904
- 80122.492
- 88111.03
- 95895.146
- 102479.927
- 108700.891
- 800.663
- 882.134
- 1010.28
- 1149.5
- 1320.5
- 1528
- 1756.032
- 2015.133
- 2312.802
- 2494.803
- 2674.234
- 2874.127
- 413.834
- 442.829
- 474.528
- 501.035
- 527.678
- 560.073
- 562.548
- 569.473
- 621.621
- 692.651
- 720.23
- 684.736
- 9939.217
- 11406.35
- 13056.604
- 14770.296
- 16660.67
- 18396.941
- 20198.73
- 22987.397
- 25798.239
- 28529.501
- 31167.783
- 33757.175
- 6446.316
- 7038.035
- 7788.944
- 8680.909
- 9809.596
- 11127.868
- 12587.223
- 12891.952
- 13160.731
- 16603.334
- 18473.78
- 19951.656
- 20092.996
- 21731.844
- 23634.436
- 25870.271
- 28466.39
- 31528.087
- 34680.442
- 38028.578
- 40546.538
- 43247.867
- 45598.081
- 47761.98
- 485.831
- 548.08
- 621.392
- 706.64
- 821.782
- 977.026
- 1099.01
- 1278.184
- 1554.253
- 1774.766
- 1972.153
- 2055.08
- 9182.536
- 9682.338
- 10332.057
- 11261.69
- 12412.593
- 13933.198
- 15796.314
- 17917.18
- 20326.209
- 23001.113
- 25873.917
- 28901.79
- 10381.988
- 11026.383
- 11805.689
- 12596.822
- 13329.874
- 13852.989
- 14310.401
- 14665.278
- 15174.244
- 15604.464
- 16122.83
- 16570.613
- 1994.794
- 2229.407
- 2488.55
- 2728.15
- 2929.1
- 3164.9
- 3210.65
- 3317.166
- 3437.674
- 3676.187
- 3908.037
- 4115.771
- 1165.79
- 1358.828
- 1590.597
- 1865.49
- 2182.908
- 2554.598
- 2979.423
- 3344.353
- 4017.939
- 4609.572
- 5146.848
- 5675.356
- 3379.468
- 3692.184
- 4076.008
- 4534.062
- 5060.262
- 5682.086
- 6437.188
- 7332.638
- 8392.818
- 9666.252
- 11140.655
- 12894.865
- 33119.096
- 37173.34
- 41871.351
- 47287.752
- 53740.085
- 62209.173
- 73039.376
- 81551.52
- 93364.244
- 106207.839
- 119901.274
- 135031.164
- 3327.728
- 3491.938
- 3638.919
- 3786.019
- 3933.004
- 4043.205
- 4114.787
- 4186.147
- 4286.357
- 4405.672
- 4535.591
- 4627.926
- 507.833
- 561.977
- 628.164
- 714.775
- 829.05
- 1004.533
- 1301.048
- 1593.882
- 1915.208
- 2283.635
- 2713.462
- 3204.897
- 41346.56
- 46679.944
- 53100.671
- 60641.899
- 69325.921
- 78152.686
- 91462.088
- 105186.881
- 120065.004
- 135564.834
- 153403.524
- 169270.617
- 940.08
- 1063.506
- 1215.725
- 1405.486
- 1616.384
- 1839.782
- 2036.305
- 2253.639
- 2484.997
- 2734.531
- 2990.875
- 3242.173
- 1555.876
- 1770.902
- 2009.813
- 2287.985
- 2614.104
- 2984.494
- 3366.439
- 3886.512
- 4483.945
- 5154.123
- 5884.491
- 6667.147
- 8025.7
- 9146.1
- 10516.5
- 12132.2
- 13954.7
- 15990.099
- 18125.129
- 20195.924
- 22430.449
- 24748.122
- 26769.436
- 28674.757
- 22438.691
- 26072.194
- 30325.264
- 35356.6
- 40850.141
- 46850.962
- 53456.774
- 60017.788
- 67185.766
- 75012.988
- 82995.088
- 91077.287
- 25730.551
- 28235.346
- 30329.617
- 31785.378
- 33039.545
- 34621.254
- 36227.381
- 37740.71
- 38370.697
- 38654.957
- 38625.976
- 38518.241
- 8526.05
- 8817.65
- 9019.8
- 9103
- 8970.45
- 9662.6
- 9859.65
- 9915.289
- 9927.68
- 10156.415
- 10433.867
- 10642.836
- 2227
- 2260
- 2448.046
- 2648.961
- 2847.132
- 3080.828
- 3279.001
- 3444.468
- 3585.176
- 3759.43
- 3859.606
- 3942.491
- 257.7
- 308.7
- 358.9
- 414.024
- 461.633
- 492.095
- 517.81
- 562.035
- 622.191
- 684.81
- 743.981
- 798.094
- 16630
- 17829.327
- 18680.721
- 19284.814
- 20662.648
- 21658.597
- 22356.726
- 22686.371
- 22797.027
- 22562.458
- 22404.337
- 22276.056
- 2534.927
- 2822.082
- 3051.242
- 3451.079
- 3992.121
- 4657.072
- 5507.565
- 6349.365
- 7290.203
- 7212.583
- 7852.401
- 8860.588
- 60.011
- 61.325
- 65.345
- 70.787
- 76.595
- 86.796
- 98.593
- 110.812
- 125.911
- 145.608
- 170.372
- 199.579
- 4005.677
- 4419.65
- 4943.029
- 5618.198
- 6472.756
- 8128.505
- 11254.672
- 14619.745
- 16945.857
- 21229.759
- 24501.53
- 27601.038
- 2755.589
- 3054.547
- 3430.243
- 3965.841
- 4588.696
- 5260.855
- 6147.783
- 7171.347
- 8307.92
- 9535.314
- 10870.037
- 12267.493
- 6860.147
- 7271.135
- 7616.06
- 7971.222
- 8313.288
- 8686.367
- 9032.824
- 9230.783
- 9826.397
- 10336.594
- 10111.559
- 10150.265
- 2143.249
- 2295.678
- 2467.895
- 2662.19
- 2879.013
- 3140.897
- 3464.522
- 3868.905
- 4260.884
- 4578.212
- 5359.092
- 6144.562
- 1127
- 1445.929
- 1750.2
- 1977.6
- 2152.4
- 2325.3
- 2651.869
- 2794.552
- 3235.865
- 3802.309
- 4197.776
- 4553.009
- 3558.137
- 3844.277
- 4237.384
- 4442.238
- 4593.433
- 4827.803
- 5048.043
- 5199.318
- 5302.888
- 5383.01
- 5410.052
- 5447.502
- 1489.518
- 1533.07
- 1582.962
- 1646.912
- 1694.51
- 1746.919
- 1861.252
- 1945.87
- 1999.21
- 2011.612
- 2011.497
- 2009.245
- 2526.994
- 2780.415
- 3080.153
- 3428.839
- 3840.161
- 4353.666
- 5828.892
- 6921.858
- 6099.799
- 6633.514
- 7753.31
- 9118.773
- 14264.935
- 16151.549
- 18356.657
- 20997.321
- 23935.81
- 27129.932
- 31140.029
- 35933.379
- 39964.159
- 42835.005
- 44433.622
- 43997.828
- 28549.87
- 29841.614
- 31158.061
- 32850.275
- 34513.161
- 36439
- 37983.31
- 38880.702
- 39549.438
- 39855.442
- 40152.517
- 40448.191
- 7982.342
- 9128.546
- 10421.936
- 11737.396
- 13016.733
- 14116.836
- 15410.151
- 16495.304
- 17587.06
- 18698.655
- 19576.783
- 20378.239
- 8504.667
- 9753.392
- 11183.227
- 12716.129
- 14597.019
- 17104.986
- 20367.053
- 24725.96
- 28227.588
- 32160.729
- 37090.298
- 42292.929
- 290.243
- 326.741
- 370.006
- 420.69
- 480.105
- 551.425
- 649.901
- 779.348
- 962.344
- 1054.486
- 1130.269
- 1133.066
- 7124.673
- 7363.802
- 7561.588
- 7867.931
- 8122.293
- 8251.648
- 8325.26
- 8421.403
- 8718.867
- 8897.619
- 8954.175
- 9031.088
- 4815
- 5126
- 5666
- 6063
- 6401.4
- 6316.424
- 6468.126
- 6649.942
- 6995.447
- 7193.761
- 7361.757
- 7554.661
- 3661.549
- 4149.908
- 4834.621
- 5680.812
- 6701.172
- 7932.503
- 9410.494
- 11242.847
- 13219.062
- 15081.016
- 17155.814
- 19314.747
- 8550.362
- 10164.215
- 11918.938
- 13648.692
- 15226.039
- 16785.196
- 18501.39
- 19757.799
- 20686.918
- 21628.605
- 22454.239
- 23174.294
- 8322.925
- 9452.826
- 10863.958
- 12607.312
- 14706.593
- 17129.565
- 19844.382
- 23040.63
- 26605.473
- 30686.889
- 34593.779
- 38139.64
- 21289.402
- 25041.917
- 29263.397
- 34024.249
- 39276.153
- 44148.285
- 48827.16
- 52910.342
- 56667.095
- 60216.677
- 62806.748
- 65068.149
- 1219.113
- 1357.445
- 1528.098
- 1735.55
- 2056.351
- 2308.582
- 2644.765
- 3154.264
- 3747.553
- 4320.89
- 4977.378
- 5701.579
- 662.85
- 764.9
- 887.498
- 960.155
- 975.199
- 1039.009
- 1116.479
- 1191.336
- 1183.669
- 1138.101
- 1101.832
- 1056.608
- 3647.735
- 3950.849
- 4286.552
- 4786.986
- 5303.507
- 6005.061
- 6734.098
- 7724.976
- 8523.077
- 9231.669
- 9770.575
- 10276.158
- 22235.677
- 25670.939
- 29788.695
- 33411.317
- 37492.953
- 42404.033
- 47328.791
- 52881.328
- 58179.144
- 63047.647
- 67308.928
- 71158.647
- 5824.797
- 6675.501
- 7688.797
- 8900.294
- 10190.285
- 11457.758
- 12939.4
- 15283.05
- 18252.19
- 21210.254
- 24739.869
- 29170.398
- 50430
- 51430
- 53292
- 54959
- 56079
- 56179
- 56339.704
- 56981.62
- 57866.349
- 58808.266
- 59912.431
- 60776.238
- 157553
- 171984
- 186538
- 198712
- 209896
- 220239
- 232187.835
- 242803.533
- 256894.189
- 272911.76
- 287675.526
- 301139.947
- 2252.965
- 2424.959
- 2598.466
- 2748.579
- 2829.526
- 2873.52
- 2953.997
- 3045.153
- 3149.262
- 3262.838
- 3363.085
- 3447.496
- 5439.568
- 6702.668
- 8143.375
- 9709.552
- 11515.649
- 13503.563
- 15620.766
- 17910.182
- 20265.563
- 22374.398
- 24287.67
- 26084.662
- 26246.839
- 28998.543
- 33796.14
- 39463.91
- 44655.014
- 50533.506
- 56142.181
- 62826.491
- 69940.728
- 76048.996
- 80908.147
- 85262.356
- 1030.585
- 1070.439
- 1133.134
- 1142.636
- 1089.572
- 1261.091
- 1425.876
- 1691.21
- 2104.779
- 2826.046
- 3389.578
- 4018.332
- 4963.829
- 5498.09
- 6120.081
- 6740.785
- 7407.075
- 8403.99
- 9657.618
- 11219.34
- 13367.997
- 15826.497
- 18701.257
- 22211.743
- 2672
- 3016
- 3421
- 3900
- 4506.497
- 5216.55
- 6100.407
- 7272.406
- 8381.163
- 9417.789
- 10595.811
- 11746.035
- 3080.907
- 3646.34
- 4277.736
- 4995.432
- 5861.135
- 6642.107
- 7636.524
- 9216.418
- 10704.34
- 11404.948
- 11926.563
- 12311.143
Back to our example:#
What is going on here?
code evaluation is delayed
the
filter
function quotes columnscountry
andyear
the
filter
function then creates a data mask (to mingle variables from the environment and the data frame)the columns
country
andyear
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")
country | continent | year | lifeExp | pop | gdpPercap |
---|---|---|---|---|---|
<fct> | <fct> | <int> | <dbl> | <int> | <dbl> |
Canada | Americas | 1952 | 68.750 | 14785584 | 11367.16 |
Canada | Americas | 1957 | 69.960 | 17010154 | 12489.95 |
Canada | Americas | 1962 | 71.300 | 18985849 | 13462.49 |
Canada | Americas | 1967 | 72.130 | 20819767 | 16076.59 |
Canada | Americas | 1972 | 72.880 | 22284500 | 18970.57 |
Canada | Americas | 1977 | 74.210 | 23796400 | 22090.88 |
Canada | Americas | 1982 | 75.760 | 25201900 | 22898.79 |
Canada | Americas | 1987 | 76.860 | 26549700 | 26626.52 |
Canada | Americas | 1992 | 77.950 | 28523502 | 26342.88 |
Canada | Americas | 1997 | 78.610 | 30305843 | 28954.93 |
Canada | Americas | 2002 | 79.770 | 31902268 | 33328.97 |
Canada | Americas | 2007 | 80.653 | 33390141 | 36319.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)
identity(2 * 3)
a <- 2
b <- 3
identity(a * b)
Quoting functions#
take the expression itself, not the value
typeof(quote(6))
typeof(quote(2 * 3))
typeof(quote(a * b))
identity(quote(a * b))
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)
mpg | cyl | disp | hp | drat | wt | qsec | vs | am | gear | carb |
---|---|---|---|---|---|---|---|---|---|---|
<dbl> | <dbl> | <dbl> | <dbl> | <dbl> | <dbl> | <dbl> | <dbl> | <dbl> | <dbl> | <dbl> |
sum(mtcars2$am)
temp <- mtcars$am
sum(temp)
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
year
filter(gapminder, !!col1 == val1, !!col2 == val2)
country | continent | year | lifeExp | pop | gdpPercap |
---|---|---|---|---|---|
<fct> | <fct> | <int> | <dbl> | <int> | <dbl> |
Canada | Americas | 2007 | 80.653 | 33390141 | 36319.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")
country | continent | year | lifeExp | pop | gdpPercap |
---|---|---|---|---|---|
<fct> | <fct> | <int> | <dbl> | <int> | <dbl> |
Canada | Americas | 1952 | 68.750 | 14785584 | 11367.16 |
Canada | Americas | 1957 | 69.960 | 17010154 | 12489.95 |
Canada | Americas | 1962 | 71.300 | 18985849 | 13462.49 |
Canada | Americas | 1967 | 72.130 | 20819767 | 16076.59 |
Canada | Americas | 1972 | 72.880 | 22284500 | 18970.57 |
Canada | Americas | 1977 | 74.210 | 23796400 | 22090.88 |
Canada | Americas | 1982 | 75.760 | 25201900 | 22898.79 |
Canada | Americas | 1987 | 76.860 | 26549700 | 26626.52 |
Canada | Americas | 1992 | 77.950 | 28523502 | 26342.88 |
Canada | Americas | 1997 | 78.610 | 30305843 | 28954.93 |
Canada | Americas | 2002 | 79.770 | 31902268 | 33328.97 |
Canada | Americas | 2007 | 80.653 | 33390141 | 36319.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")
country | continent | year | lifeExp | pop | gdpPercap |
---|---|---|---|---|---|
<fct> | <fct> | <int> | <dbl> | <int> | <dbl> |
Canada | Americas | 1952 | 68.750 | 14785584 | 11367.16 |
Canada | Americas | 1957 | 69.960 | 17010154 | 12489.95 |
Canada | Americas | 1962 | 71.300 | 18985849 | 13462.49 |
Canada | Americas | 1967 | 72.130 | 20819767 | 16076.59 |
Canada | Americas | 1972 | 72.880 | 22284500 | 18970.57 |
Canada | Americas | 1977 | 74.210 | 23796400 | 22090.88 |
Canada | Americas | 1982 | 75.760 | 25201900 | 22898.79 |
Canada | Americas | 1987 | 76.860 | 26549700 | 26626.52 |
Canada | Americas | 1992 | 77.950 | 28523502 | 26342.88 |
Canada | Americas | 1997 | 78.610 | 30305843 | 28954.93 |
Canada | Americas | 2002 | 79.770 | 31902268 | 33328.97 |
Canada | Americas | 2007 | 80.653 | 33390141 | 36319.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
- 2
- 3
- 1
- 2
- 3
x <- quote(mpg)
typeof(x)
select(mtcars, !!x)
mpg | |
---|---|
<dbl> | |
Mazda RX4 | 21.0 |
Mazda RX4 Wag | 21.0 |
Datsun 710 | 22.8 |
Hornet 4 Drive | 21.4 |
Hornet Sportabout | 18.7 |
Valiant | 18.1 |
Duster 360 | 14.3 |
Merc 240D | 24.4 |
Merc 230 | 22.8 |
Merc 280 | 19.2 |
Merc 280C | 17.8 |
Merc 450SE | 16.4 |
Merc 450SL | 17.3 |
Merc 450SLC | 15.2 |
Cadillac Fleetwood | 10.4 |
Lincoln Continental | 10.4 |
Chrysler Imperial | 14.7 |
Fiat 128 | 32.4 |
Honda Civic | 30.4 |
Toyota Corolla | 33.9 |
Toyota Corona | 21.5 |
Dodge Challenger | 15.5 |
AMC Javelin | 15.2 |
Camaro Z28 | 13.3 |
Pontiac Firebird | 19.2 |
Fiat X1-9 | 27.3 |
Porsche 914-2 | 26.0 |
Lotus Europa | 30.4 |
Ford Pantera L | 15.8 |
Ferrari Dino | 19.7 |
Maserati Bora | 15.0 |
Volvo 142E | 21.4 |
old_col <- quote(mpg)
new_col <- quote(kml)
mutate(mtcars, !!new_col := !!old_col * 0.425144)
#mutate(mtcars, mpg = mpg * 0.425144)
mpg | cyl | disp | hp | drat | wt | qsec | vs | am | gear | carb | kml |
---|---|---|---|---|---|---|---|---|---|---|---|
<dbl> | <dbl> | <dbl> | <dbl> | <dbl> | <dbl> | <dbl> | <dbl> | <dbl> | <dbl> | <dbl> | <dbl> |
21.0 | 6 | 160.0 | 110 | 3.90 | 2.620 | 16.46 | 0 | 1 | 4 | 4 | 8.928024 |
21.0 | 6 | 160.0 | 110 | 3.90 | 2.875 | 17.02 | 0 | 1 | 4 | 4 | 8.928024 |
22.8 | 4 | 108.0 | 93 | 3.85 | 2.320 | 18.61 | 1 | 1 | 4 | 1 | 9.693283 |
21.4 | 6 | 258.0 | 110 | 3.08 | 3.215 | 19.44 | 1 | 0 | 3 | 1 | 9.098082 |
18.7 | 8 | 360.0 | 175 | 3.15 | 3.440 | 17.02 | 0 | 0 | 3 | 2 | 7.950193 |
18.1 | 6 | 225.0 | 105 | 2.76 | 3.460 | 20.22 | 1 | 0 | 3 | 1 | 7.695106 |
14.3 | 8 | 360.0 | 245 | 3.21 | 3.570 | 15.84 | 0 | 0 | 3 | 4 | 6.079559 |
24.4 | 4 | 146.7 | 62 | 3.69 | 3.190 | 20.00 | 1 | 0 | 4 | 2 | 10.373514 |
22.8 | 4 | 140.8 | 95 | 3.92 | 3.150 | 22.90 | 1 | 0 | 4 | 2 | 9.693283 |
19.2 | 6 | 167.6 | 123 | 3.92 | 3.440 | 18.30 | 1 | 0 | 4 | 4 | 8.162765 |
17.8 | 6 | 167.6 | 123 | 3.92 | 3.440 | 18.90 | 1 | 0 | 4 | 4 | 7.567563 |
16.4 | 8 | 275.8 | 180 | 3.07 | 4.070 | 17.40 | 0 | 0 | 3 | 3 | 6.972362 |
17.3 | 8 | 275.8 | 180 | 3.07 | 3.730 | 17.60 | 0 | 0 | 3 | 3 | 7.354991 |
15.2 | 8 | 275.8 | 180 | 3.07 | 3.780 | 18.00 | 0 | 0 | 3 | 3 | 6.462189 |
10.4 | 8 | 472.0 | 205 | 2.93 | 5.250 | 17.98 | 0 | 0 | 3 | 4 | 4.421498 |
10.4 | 8 | 460.0 | 215 | 3.00 | 5.424 | 17.82 | 0 | 0 | 3 | 4 | 4.421498 |
14.7 | 8 | 440.0 | 230 | 3.23 | 5.345 | 17.42 | 0 | 0 | 3 | 4 | 6.249617 |
32.4 | 4 | 78.7 | 66 | 4.08 | 2.200 | 19.47 | 1 | 1 | 4 | 1 | 13.774666 |
30.4 | 4 | 75.7 | 52 | 4.93 | 1.615 | 18.52 | 1 | 1 | 4 | 2 | 12.924378 |
33.9 | 4 | 71.1 | 65 | 4.22 | 1.835 | 19.90 | 1 | 1 | 4 | 1 | 14.412382 |
21.5 | 4 | 120.1 | 97 | 3.70 | 2.465 | 20.01 | 1 | 0 | 3 | 1 | 9.140596 |
15.5 | 8 | 318.0 | 150 | 2.76 | 3.520 | 16.87 | 0 | 0 | 3 | 2 | 6.589732 |
15.2 | 8 | 304.0 | 150 | 3.15 | 3.435 | 17.30 | 0 | 0 | 3 | 2 | 6.462189 |
13.3 | 8 | 350.0 | 245 | 3.73 | 3.840 | 15.41 | 0 | 0 | 3 | 4 | 5.654415 |
19.2 | 8 | 400.0 | 175 | 3.08 | 3.845 | 17.05 | 0 | 0 | 3 | 2 | 8.162765 |
27.3 | 4 | 79.0 | 66 | 4.08 | 1.935 | 18.90 | 1 | 1 | 4 | 1 | 11.606431 |
26.0 | 4 | 120.3 | 91 | 4.43 | 2.140 | 16.70 | 0 | 1 | 5 | 2 | 11.053744 |
30.4 | 4 | 95.1 | 113 | 3.77 | 1.513 | 16.90 | 1 | 1 | 5 | 2 | 12.924378 |
15.8 | 8 | 351.0 | 264 | 4.22 | 3.170 | 14.50 | 0 | 1 | 5 | 4 | 6.717275 |
19.7 | 6 | 145.0 | 175 | 3.62 | 2.770 | 15.50 | 0 | 1 | 5 | 6 | 8.375337 |
15.0 | 8 | 301.0 | 335 | 3.54 | 3.570 | 14.60 | 0 | 1 | 5 | 8 | 6.377160 |
21.4 | 4 | 121.0 | 109 | 4.11 | 2.780 | 18.60 | 1 | 1 | 4 | 2 | 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)
country | continent | year | lifeExp | pop | gdpPercap |
---|---|---|---|---|---|
<fct> | <fct> | <int> | <dbl> | <int> | <dbl> |
Afghanistan | Asia | 1952 | 28.801 | 8425333 | 779.4453 |
Albania | Europe | 1952 | 55.230 | 1282697 | 1601.0561 |
Algeria | Africa | 1952 | 43.077 | 9279525 | 2449.0082 |
Angola | Africa | 1952 | 30.015 | 4232095 | 3520.6103 |
Argentina | Americas | 1952 | 62.485 | 17876956 | 5911.3151 |
Australia | Oceania | 1952 | 69.120 | 8691212 | 10039.5956 |
Austria | Europe | 1952 | 66.800 | 6927772 | 6137.0765 |
Bahrain | Asia | 1952 | 50.939 | 120447 | 9867.0848 |
Bangladesh | Asia | 1952 | 37.484 | 46886859 | 684.2442 |
Belgium | Europe | 1952 | 68.000 | 8730405 | 8343.1051 |
Benin | Africa | 1952 | 38.223 | 1738315 | 1062.7522 |
Bolivia | Americas | 1952 | 40.414 | 2883315 | 2677.3263 |
Bosnia and Herzegovina | Europe | 1952 | 53.820 | 2791000 | 973.5332 |
Botswana | Africa | 1952 | 47.622 | 442308 | 851.2411 |
Brazil | Americas | 1952 | 50.917 | 56602560 | 2108.9444 |
Bulgaria | Europe | 1952 | 59.600 | 7274900 | 2444.2866 |
Burkina Faso | Africa | 1952 | 31.975 | 4469979 | 543.2552 |
Burundi | Africa | 1952 | 39.031 | 2445618 | 339.2965 |
Cambodia | Asia | 1952 | 39.417 | 4693836 | 368.4693 |
Cameroon | Africa | 1952 | 38.523 | 5009067 | 1172.6677 |
Canada | Americas | 1952 | 68.750 | 14785584 | 11367.1611 |
Central African Republic | Africa | 1952 | 35.463 | 1291695 | 1071.3107 |
Chad | Africa | 1952 | 38.092 | 2682462 | 1178.6659 |
Chile | Americas | 1952 | 54.745 | 6377619 | 3939.9788 |
China | Asia | 1952 | 44.000 | 556263527 | 400.4486 |
Colombia | Americas | 1952 | 50.643 | 12350771 | 2144.1151 |
Comoros | Africa | 1952 | 40.715 | 153936 | 1102.9909 |
Congo, Dem. Rep. | Africa | 1952 | 39.143 | 14100005 | 780.5423 |
Congo, Rep. | Africa | 1952 | 42.111 | 854885 | 2125.6214 |
Costa Rica | Americas | 1952 | 57.206 | 926317 | 2627.0095 |
⎠| ⎠| ⎠| ⎠| ⎠| ⎠|
Sierra Leone | Africa | 2007 | 42.568 | 6144562 | 862.5408 |
Singapore | Asia | 2007 | 79.972 | 4553009 | 47143.1796 |
Slovak Republic | Europe | 2007 | 74.663 | 5447502 | 18678.3144 |
Slovenia | Europe | 2007 | 77.926 | 2009245 | 25768.2576 |
Somalia | Africa | 2007 | 48.159 | 9118773 | 926.1411 |
South Africa | Africa | 2007 | 49.339 | 43997828 | 9269.6578 |
Spain | Europe | 2007 | 80.941 | 40448191 | 28821.0637 |
Sri Lanka | Asia | 2007 | 72.396 | 20378239 | 3970.0954 |
Sudan | Africa | 2007 | 58.556 | 42292929 | 2602.3950 |
Swaziland | Africa | 2007 | 39.613 | 1133066 | 4513.4806 |
Sweden | Europe | 2007 | 80.884 | 9031088 | 33859.7484 |
Switzerland | Europe | 2007 | 81.701 | 7554661 | 37506.4191 |
Syria | Asia | 2007 | 74.143 | 19314747 | 4184.5481 |
Taiwan | Asia | 2007 | 78.400 | 23174294 | 28718.2768 |
Tanzania | Africa | 2007 | 52.517 | 38139640 | 1107.4822 |
Thailand | Asia | 2007 | 70.616 | 65068149 | 7458.3963 |
Togo | Africa | 2007 | 58.420 | 5701579 | 882.9699 |
Trinidad and Tobago | Americas | 2007 | 69.819 | 1056608 | 18008.5092 |
Tunisia | Africa | 2007 | 73.923 | 10276158 | 7092.9230 |
Turkey | Europe | 2007 | 71.777 | 71158647 | 8458.2764 |
Uganda | Africa | 2007 | 51.542 | 29170398 | 1056.3801 |
United Kingdom | Europe | 2007 | 79.425 | 60776238 | 33203.2613 |
United States | Americas | 2007 | 78.242 | 301139947 | 42951.6531 |
Uruguay | Americas | 2007 | 76.384 | 3447496 | 10611.4630 |
Venezuela | Americas | 2007 | 73.747 | 26084662 | 11415.8057 |
Vietnam | Asia | 2007 | 74.249 | 85262356 | 2441.5764 |
West Bank and Gaza | Asia | 2007 | 73.422 | 4018332 | 3025.3498 |
Yemen, Rep. | Asia | 2007 | 62.698 | 22211743 | 2280.7699 |
Zambia | Africa | 2007 | 42.384 | 11746035 | 1271.2116 |
Zimbabwe | Africa | 2007 | 43.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)
mpg | cyl | disp | hp |
---|---|---|---|
<dbl> | <dbl> | <dbl> | <dbl> |
1.0452636 | 6 | 160.0 | 110 |
1.0452636 | 6 | 160.0 | 110 |
1.1348577 | 4 | 108.0 | 93 |
1.0651734 | 6 | 258.0 | 110 |
0.9307824 | 8 | 360.0 | 175 |
0.9009177 | 6 | 225.0 | 105 |
0.7117748 | 8 | 360.0 | 245 |
1.2144968 | 4 | 146.7 | 62 |
1.1348577 | 4 | 140.8 | 95 |
0.9556696 | 6 | 167.6 | 123 |
0.8859854 | 6 | 167.6 | 123 |
0.8163011 | 8 | 275.8 | 180 |
0.8610981 | 8 | 275.8 | 180 |
0.7565718 | 8 | 275.8 | 180 |
0.5176544 | 8 | 472.0 | 205 |
0.5176544 | 8 | 460.0 | 215 |
0.7316846 | 8 | 440.0 | 230 |
1.6126925 | 4 | 78.7 | 66 |
1.5131436 | 4 | 75.7 | 52 |
1.6873542 | 4 | 71.1 | 65 |
1.0701509 | 4 | 120.1 | 97 |
0.7715041 | 8 | 318.0 | 150 |
0.7565718 | 8 | 304.0 | 150 |
0.6620003 | 8 | 350.0 | 245 |
0.9556696 | 8 | 400.0 | 175 |
1.3588427 | 4 | 79.0 | 66 |
1.2941359 | 4 | 120.3 | 91 |
1.5131436 | 4 | 95.1 | 113 |
0.7864365 | 8 | 351.0 | 264 |
0.9805569 | 6 | 145.0 | 175 |
0.7466169 | 8 | 301.0 | 335 |
1.0651734 | 4 | 121.0 | 109 |
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)
mpg | drat | carb |
---|---|---|
<dbl> | <dbl> | <dbl> |
1.0452636 | 3.90 | 4 |
1.0452636 | 3.90 | 4 |
1.1348577 | 3.85 | 1 |
1.0651734 | 3.08 | 1 |
0.9307824 | 3.15 | 2 |
0.9009177 | 2.76 | 1 |
0.7117748 | 3.21 | 4 |
1.2144968 | 3.69 | 2 |
1.1348577 | 3.92 | 2 |
0.9556696 | 3.92 | 4 |
0.8859854 | 3.92 | 4 |
0.8163011 | 3.07 | 3 |
0.8610981 | 3.07 | 3 |
0.7565718 | 3.07 | 3 |
0.5176544 | 2.93 | 4 |
0.5176544 | 3.00 | 4 |
0.7316846 | 3.23 | 4 |
1.6126925 | 4.08 | 1 |
1.5131436 | 4.93 | 2 |
1.6873542 | 4.22 | 1 |
1.0701509 | 3.70 | 1 |
0.7715041 | 2.76 | 2 |
0.7565718 | 3.15 | 2 |
0.6620003 | 3.73 | 4 |
0.9556696 | 3.08 | 2 |
1.3588427 | 4.08 | 1 |
1.2941359 | 4.43 | 2 |
1.5131436 | 3.77 | 2 |
0.7864365 | 4.22 | 4 |
0.9805569 | 3.62 | 6 |
0.7466169 | 3.54 | 8 |
1.0651734 | 4.11 | 2 |
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:#
Tidy evaluation by Lionel Henry & Hadley Wickham
Tidy eval in context talk by Jenny Bryan
iris[c(2, 4)]
Sepal.Width | Petal.Width |
---|---|
<dbl> | <dbl> |
3.5 | 0.2 |
3.0 | 0.2 |
3.2 | 0.2 |
3.1 | 0.2 |
3.6 | 0.2 |
3.9 | 0.4 |
3.4 | 0.3 |
3.4 | 0.2 |
2.9 | 0.2 |
3.1 | 0.1 |
3.7 | 0.2 |
3.4 | 0.2 |
3.0 | 0.1 |
3.0 | 0.1 |
4.0 | 0.2 |
4.4 | 0.4 |
3.9 | 0.4 |
3.5 | 0.3 |
3.8 | 0.3 |
3.8 | 0.3 |
3.4 | 0.2 |
3.7 | 0.4 |
3.6 | 0.2 |
3.3 | 0.5 |
3.4 | 0.2 |
3.0 | 0.2 |
3.4 | 0.4 |
3.5 | 0.2 |
3.4 | 0.2 |
3.2 | 0.2 |
⎠| ⎠|
3.2 | 2.3 |
2.8 | 2.0 |
2.8 | 2.0 |
2.7 | 1.8 |
3.3 | 2.1 |
3.2 | 1.8 |
2.8 | 1.8 |
3.0 | 1.8 |
2.8 | 2.1 |
3.0 | 1.6 |
2.8 | 1.9 |
3.8 | 2.0 |
2.8 | 2.2 |
2.8 | 1.5 |
2.6 | 1.4 |
3.0 | 2.3 |
3.4 | 2.4 |
3.1 | 1.8 |
3.0 | 1.8 |
3.1 | 2.1 |
3.1 | 2.4 |
3.1 | 2.3 |
2.7 | 1.9 |
3.2 | 2.3 |
3.3 | 2.5 |
3.0 | 2.3 |
2.5 | 1.9 |
3.0 | 2.0 |
3.4 | 2.3 |
3.0 | 1.8 |