cmkimber / Elections_Ontario_App

Webapp to explore Elections Ontario data
0 stars 0 forks source link

factor releveling in pane 2 produces warnings in some years #7

Closed cmkimber closed 2 months ago

cmkimber commented 2 months ago

Issue in dev branch "pane_2".

During the reactive preparation of panel_2_df() for plotting, there is a call to mutate() that includes Party.Temp = fct_relevel(Party.Temp, "Other", after = Inf) to move the leve "Other" to the end of the order for plotting purposes. As the level "Other" is not present in all years (because parties receiving <0.5% of the vote did not exist in that election), this produces a warning: Caused by warning:! 1 unknown level inf: Other.

This call to fct_relevel() should be wrapped in a conditional that only executes when the level "Other" is present after filtering for Year.

cmkimber commented 2 months ago

A conditional check has been added to the call to mutate() that relevels the factor containing party names and drops "Other" to the end. This is accomplished using if...else because if_else() gave an error must have size 1, not size 8. despite the fact that the conditional statement should be returning a single TRUE/FALSE value as it does in the approach implemented now.