1

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

  1. Extract two dataframes (labelled by year) from staff_files, and extract another two dataframes from another eval_files
  2. For each dataframe, I select a subset of the columns
  3. Join the two dataframes together from staff_files, and join the the two dataframes together from eval_files
  4. From the joined dataframe born from eval_files, replace NA elements for specific column that start with "evaluation"
  5. 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.

  • 2
    I'm not a big fan of your formatting. But aside from that do you really want `%>%` at the end of your `df_staff_red` creation? – Dason Sep 25 '20 at 15:57
  • I can appreciate your formatting perspective, but does your suggestion affect the functionality of my code? I prefer it to use the pipe-operator that way, but I am primarily a python user so maybe it's not conventional. – 907Resident Sep 25 '20 at 16:07
  • Ah, I see what you are saying @Dason. You were right, I found the stray %>% that you were referring to. Thank you. – 907Resident Sep 25 '20 at 16:26

0 Answers0