使用Tidyverse | |时出现困难错误eval(lhs,parent,parent):未找到对象“*tmp*”
前几天我使用了这个功能,但由于某种原因它停止了工作。我编写了一个函数来执行以下操作: 考虑两个数据帧列表:a staff_文件和b eval_文件 从staff_文件中提取两个按年份标记的数据帧,并从另一个eval_文件中提取另外两个数据帧 对于每个数据帧,我选择列的子集 将staff_文件中的两个数据帧连接在一起,并将eval_文件中的两个数据帧连接在一起 从从eval_文件生成的联接数据框中,替换以evaluation开头的特定列的NA元素 将以前合并的staff_文件和eval_文件合并在一起 尝试执行我的函数后,我收到以下错误:使用Tidyverse | |时出现困难错误eval(lhs,parent,parent):未找到对象“*tmp*”,r,error-handling,tidyverse,R,Error Handling,Tidyverse,前几天我使用了这个功能,但由于某种原因它停止了工作。我编写了一个函数来执行以下操作: 考虑两个数据帧列表:a staff_文件和b eval_文件 从staff_文件中提取两个按年份标记的数据帧,并从另一个eval_文件中提取另外两个数据帧 对于每个数据帧,我选择列的子集 将staff_文件中的两个数据帧连接在一起,并将eval_文件中的两个数据帧连接在一起 从从eval_文件生成的联接数据框中,替换以evaluation开头的特定列的NA元素 将以前合并的staff_文件和eval_文件合并在
Error in eval(lhs, parent, parent) : object '*tmp*' not found
请在此处查看完整代码:
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
类似的未回答/未接受回答的问题也被问到了。我不太喜欢你的格式。但除此之外,您真的希望在df_staff_红色创建结束时%>%吗?我很欣赏您的格式观点,但您的建议是否会影响我代码的功能?我更喜欢这样使用管道操作符,但我主要是python用户,所以可能不是传统的。啊,我明白你说的@Dason。你是对的,我找到了你所指的流浪%>%。非常感谢。