boxuancui / DataExplorer

Automate Data Exploration and Treatment
http://boxuancui.github.io/DataExplorer/
Other
512 stars 88 forks source link

Display error message when there is not enough valid bars #95

Closed jl5000 closed 5 years ago

jl5000 commented 6 years ago

I think I may have discovered a bug when trying to create a report from the following dataset:

structure(list(country = c("Indonesia", "Togo", "Djibouti", "Trinidad and Tobago", 
"Bolivia", "Sao Tome and Principe", "Saudi Arabia", "Mexico", 
"Kuwait", "Botswana", "Ghana", "Turkey", "Hungary", "Madagascar", 
"Romania", "Mexico", "Kuwait", "Zambia", "Germany", "Guatemala", 
"Bosnia and Herzegovina", "Australia", "Senegal", "Rwanda", "Chad", 
"Jordan", "Cote d'Ivoire", "Malaysia", "Zimbabwe", "Zambia", 
"Botswana", "Zimbabwe", "United States", "Mozambique", "Reunion", 
"Mexico", "Nepal", "Iran", "Guinea-Bissau", "Jamaica", "Kenya", 
"Sierra Leone", "Mauritius", "Sri Lanka", "Mexico", "Libya", 
"Honduras", "Croatia", "Switzerland", "Puerto Rico", "Nicaragua", 
"Zimbabwe", "Congo, Rep.", "Hong Kong, China", "Saudi Arabia", 
"Uganda", "Indonesia", "Japan", "Gabon", "Algeria", "Ecuador", 
"Greece", "Libya", "Venezuela", "Panama", "Mexico", "Iceland", 
"Mali", "Senegal", "Haiti", "Greece", "Oman", "Ecuador", "Finland", 
"Colombia", "Switzerland", "Dominican Republic", "Argentina", 
"Japan", "Slovak Republic", "Morocco", "Eritrea", "Ghana", "Gambia", 
"Botswana", "Ireland", "Central African Republic", "Guinea", 
"Cameroon", "Nigeria", "Malawi", "Colombia", "Vietnam", "Poland", 
"Brazil", "Comoros", "Gabon", "Sudan", "Cambodia", "Vietnam", 
"Slovenia", "Sao Tome and Principe", "Serbia", "Brazil", "Cameroon", 
"Sweden", "Romania", "Cambodia", "Switzerland", "Montenegro", 
"Burkina Faso", "Burundi", "Thailand", "Uganda", "West Bank and Gaza", 
"Central African Republic", "Bahrain", "Central African Republic", 
"Vietnam", "Denmark", "Burundi", "Taiwan", "Argentina", "Myanmar", 
"Switzerland", "Uruguay", "Syria", "Congo, Dem. Rep.", "Thailand", 
"Kenya", "Benin", "Indonesia", "Mongolia", "Egypt", "Hungary", 
"Syria", "Eritrea", "Bulgaria", "Mozambique", "Nicaragua", "Slovenia", 
"Cameroon", "Colombia", "Netherlands", "Croatia", "Haiti", "Yemen, Rep.", 
"Ghana", "Myanmar", "Rwanda", "Gambia", "Peru", "Gabon", "Tanzania", 
"Botswana", "Morocco", "Equatorial Guinea", "Netherlands", "Guinea", 
"South Africa", "Pakistan", "Tanzania", "Congo, Dem. Rep.", "Namibia", 
"Korea, Rep.", "Romania", "Uruguay", "Peru", "Iraq", "Montenegro"
), year = c(2002, 2007, 1962, 1992, 2002, 1972, 1952, 2007, 1982, 
2002, 1957, 1957, 1957, 1977, 1977, 1992, 1992, 1952, 2007, 1967, 
2007, 1967, 1982, 1992, 1992, 1982, 1952, 1992, 1952, 2007, 1982, 
1972, 1977, 1982, 1982, 2002, 1957, 1997, 2007, 1952, 1992, 2007, 
1987, 1987, 1957, 2002, 1987, 1992, 1992, 1972, 1962, 1987, 1977, 
1987, 1987, 1982, 1992, 1992, 1997, 1992, 1987, 1987, 1997, 1977, 
1967, 1987, 1962, 1987, 1962, 1982, 1992, 1952, 1977, 1997, 1997, 
1972, 1967, 1957, 2002, 1957, 1952, 1992, 1952, 1957, 1952, 1982, 
1982, 1957, 1992, 2002, 1982, 1982, 1992, 2007, 1977, 1992, 1972, 
1957, 1962, 1982, 2002, 1957, 1962, 1972, 1972, 1957, 1952, 2007, 
1957, 1962, 1997, 1972, 1967, 1967, 2007, 1997, 2002, 2007, 1967, 
1952, 1992, 1982, 1997, 1952, 2007, 1962, 2002, 2007, 1987, 1952, 
1952, 1977, 1997, 1992, 1972, 1967, 2002, 1997, 1952, 1977, 2007, 
1967, 2002, 1987, 1977, 1992, 1997, 2007, 1997, 1967, 2002, 2002, 
1957, 1972, 1997, 1992, 1972, 1982, 1997, 1952, 1977, 1982, 2002, 
1967, 1957, 1957, 1977, 1962, 1982, 1987), pop = c(211060000, 
5701579, 89898, 1183669, 8445134, 76595, 4005677, 108700891, 
1497494, 1630347, 6391288, 25670939, 9839000, 8007166, 21658597, 
88111030, 1418095, 2672000, 82400996, 4690773, 4552198, 11872264, 
6147783, 7290203, 6429417, 2347031, 2977019, 18319502, 3080907, 
11746035, 970347, 5861135, 220239000, 12587223, 517810, 102479927, 
9682338, 63327987, 1472041, 1426095, 25020539, 6144562, 1042663, 
16495304, 35015548, 5368585, 4372203, 4494013, 6995447, 2847132, 
1590597, 9216418, 1536769, 5584510, 14619745, 12939400, 184816000, 
124329269, 1126189, 26298373, 9545158, 9974490, 4759670, 13503563, 
1405486, 80122492, 182053, 7634008, 3430243, 5198399, 10325429, 
507833, 7278866, 5134406, 37657830, 6401400, 4049146, 19610538, 
127065841, 3844277, 9939217, 3668440, 5581001, 323150, 442308, 
3480000, 2476971, 2876726, 12467171, 119901274, 6502825, 27764644, 
69940728, 38518241, 114313951, 454429, 537977, 9753392, 6083619, 
56142181, 2011497, 61325, 7616060, 100840058, 7021028, 7363802, 
16630000, 14131858, 5126000, 474528, 10352843, 3529983, 34024249, 
8900294, 4018332, 3696513, 656397, 4369038, 39463910, 4334000, 
5809236, 18501390, 36203463, 20092996, 7554661, 2598466, 17155814, 
64606759, 52910342, 6464046, 1738315, 136725000, 2494803, 59402198, 
10394091, 5680812, 4414865, 8066057, 6446316, 2554598, 2009245, 
6335506, 41008227, 14665278, 4318673, 6326682, 15826497, 22873338, 
43247867, 3451079, 1457766, 26769436, 434904, 14706593, 1536536, 
25798239, 277603, 14310401, 8048834, 14264935, 78152686, 19844382, 
55379852, 706640, 22611552, 17829327, 2873520, 10516500, 14173318, 
569473), gdpPercap = c(2873.91287, 882.9699438, 3020.989263, 
7370.990932, 3413.26269, 1532.985254, 6459.554823, 11977.57496, 
31354.03573, 11003.60508, 1043.561537, 2218.754257, 6040.180011, 
1544.228586, 9356.39724, 9472.384295, 34932.91959, 1147.388831, 
32170.37442, 3242.531147, 7446.298803, 14526.12465, 1518.479984, 
737.0685949, 1058.0643, 4161.415959, 1388.594732, 7277.912802, 
406.8841148, 1271.211593, 4551.14215, 799.3621758, 24072.63213, 
462.2114149, 5267.219353, 10742.44053, 597.9363558, 8263.590301, 
579.231743, 2898.530881, 1341.921721, 862.5407561, 4783.586903, 
1876.766827, 4131.546641, 9534.677467, 3023.096699, 8447.794873, 
31871.5303, 9123.041742, 3634.364406, 706.1573059, 3259.178978, 
20038.47269, 21198.26136, 682.2662268, 2383.140898, 26824.89511, 
14722.84188, 5023.216647, 6481.776993, 16120.52839, 9467.446056, 
13143.95095, 4421.009084, 8688.156003, 10350.15906, 684.1715576, 
1654.988723, 2011.159549, 17541.49634, 1828.230307, 6679.62326, 
23723.9502, 6117.361746, 27195.11304, 1653.723003, 6856.856212, 
28604.5919, 6093.26298, 1688.20357, 582.8585102, 911.2989371, 
520.9267111, 851.2411407, 12618.32141, 956.7529907, 576.2670245, 
1793.163278, 1615.286395, 632.8039209, 4397.575659, 989.0231487, 
15389.92468, 6660.118654, 1246.90737, 11401.94841, 1770.337074, 
496.9136476, 707.2357863, 20660.01936, 860.7369026, 6289.629157, 
4985.711467, 1684.146528, 9911.878226, 3144.613186, 1713.778686, 
17909.48973, 4649.593785, 946.2949618, 464.0995039, 1295.46066, 
908.9185217, 3025.349798, 740.5063317, 23403.55927, 706.016537, 
637.1232887, 9692.385245, 631.6998778, 7426.354774, 10967.28195, 
331, 37506.41907, 5603.357717, 4090.925331, 277.5518587, 2982.653773, 
853.540919, 1062.7522, 1382.702056, 1902.2521, 3794.755195, 10168.65611, 
1881.923632, 765.3500015, 5970.38876, 468.5260381, 5486.371089, 
25768.25759, 1508.453148, 5755.259962, 23651.32361, 11305.38517, 
1456.309517, 2117.484526, 1327.60891, 415, 510.9637142, 660.5855997, 
5909.020073, 4976.198099, 915.9850592, 8647.142313, 2948.047252, 
672.4122571, 21399.46046, 869.4497668, 4725.295531, 1175.921193, 
874.2426069, 241.1658765, 3793.694753, 1487.593537, 3943.370225, 
6504.339663, 4957.037982, 14517.90711, 11732.51017)), .Names = c("country", 
"year", "pop", "gdpPercap"), row.names = c(NA, -170L), class = c("tbl_df", 
"tbl", "data.frame"))

The error I get is:

Quitting from lines 125-132 (report.rmd) Show Traceback

Rerun with Debug Error in gList(NA = list(wrapvp = list(x = 0.5, y = 0.5, width = 1, : only 'grobs' allowed in "gList"

I have a feeling it's because there is one categorical column, but it has more than 50 categories. I tried joining it with another dataset with another categorical column with less than 50 categories and it worked.

boxuancui commented 6 years ago

Yes, plot_bar has a maxcat argument, which defaults to 50. In this case, country column will be ignored and plot_bar is trying to plot a data.frame without any discrete features.

Two workarounds using the config argument from create_report:

jl5000 commented 6 years ago

Thanks for the quick response. It may be worth providing an informative error message to this effect in case other people encounter it.

boxuancui commented 6 years ago

I might be able to raise a warning from plot_bar. Let me see what I can do.