I used this function the other day but for some reason it ceased working. I wrote a function to do the following:
Consider two lists of dataframes: (a) staff_files and (b) eval_files
- Extract two dataframes (labelled by year) from staff_files, and extract another two dataframes from another eval_files
- For each dataframe, I select a subset of the columns
- Join the two dataframes together from staff_files, and join the the two dataframes together from eval_files
- From the joined dataframe born from eval_files, replace NA elements for specific column that start with "evaluation"
- Join the previously joined staff_files and eval_files together
After attempting to execute my function, I receive the following error:
Error in eval(lhs, parent, parent) : object '*tmp*' not found
Please see the full code here:
staff_eval_comp = function(staff_files, eval_files, earlier_yr = 2017, later_yr = 2018){
# df_lst_staff : list of dataframes for staff file for one given year
# df_lst_eval : list of dataframes for evaluation file for the same given year as the staff dataframe
# earlier_yr : in the paired comparison, this the first year
# later_yr : in the paired comparison, this the next consecutive year after the earlier_yr
# return : returns a new list of dataframes that verifies the educator was present that year by comparing the staff ID to the evaluation ID
# Get a vector for years
yrs = seq(earlier_yr, later_yr, 1)
# Select subset (i.e. reduced = red) of columns from staff dataframes
df_staff_red = staff_files %>% list_select(contains(as.character(seq(earlier_yr, later_yr, 1)))) %>%
map(., ~select(., starts_with(c("deident_tchnum", "sch_id"))) ) %>%
reduce(full_join, by=c("deident_tchnum", "sch_id"),
suffix=c(as.character(earlier_yr), as.character(later_yr))) %>%
# Select subset (i.e. reduced = red) of columns from staff dataframes
df_eval_red = eval_files %>% list_select(contains(as.character(seq(earlier_yr, later_yr, 1)))) %>%
map(., ~select(., starts_with(c("deident_tchnum","year", "sch_id", "eval_presence")))) %>%
reduce(full_join, by=c("deident_tchnum", "sch_id"),
suffix=c(as.character(earlier_yr), as.character(later_yr)))
# Clean up evaluation dataframe
df_eval_red = df_eval_red %>% mutate_at(., vars(starts_with("eval_presence")), lst(if_else( is.na(.), 0, .)))
# Join the staff and eval dataframe
dfx_staff_eval = df_staff_red %>% left_join(., df_eval_red, by=c("deident_tchnum", "sch_id"))
# Return joined dataframe
return(dfx_staff_eval)
}
dfx = staff_eval_comp(staff_files, eval_files, 2012, 2013)
Error in eval(lhs, parent, parent) : object '*tmp*' not found
Similar unanswered/unaccepted answered questions have been asked here and here.