In some cases the class of a variable can change depending on the filter, leading to runtime error in the script. I have a simple sex column (values M and F), and when no filter or selecting only men the variable is a factor or character, but when using a filter to keep only women, the variable in the R dataframe is a logical variable (with FALSE values).
To avoid errors due to changing classes, variables should have classes determined from the whole dataset and not vary as filters vary.