You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用wru包predict_race指定census.geo触发下标越界错误求助

wru包predict_race函数指定census.geo与party参数时触发下标越界错误

使用wru包的predict_race函数时,仅设置surname.only=TRUE可正常运行,且Census API密钥有效。但当指定census.geo参数(如"tract"或"county")并传入party="PID"调用该函数时,会触发Error in tmp[[1]] : subscript out of bounds错误。已尝试简化数据文件,问题仍未解决。

测试代码

library(wru)

CENSUS_API_KEY<-'My_own_key'

Voterfile <- readr::read_csv("test.csv")
predict_race(voter.file = Voterfile, surname.only = TRUE)

predict_race(voter.file = Voterfile, census.geo = "tract", census.key=CENSUS_API_KEY, party = "PID")

报错信息

predict_race(voter.file = Voterfile, census.geo = "tract", census.key=CENSUS_API_KEY, party = "PID")
Predicting race for 2020
Collecting 2020 Census data...
Error in tmp[[1]] : subscript out of bounds

测试数据dput结果

structure(list(VoterID = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), surname = c("Khanna", 
"Imai", "Rivera", "Fifield", "Zhou", "Ratkovic", "Johnson", "Lopez", 
"Wantchekon", "Morse"), state = c("NJ", "NJ", "NY", "NJ", "NJ", 
"NJ", "NY", "NJ", "NJ", "DC"), CD = c(12, 12, 12, 12, 12, 12, 
9, 12, 12, 0), county = c(21, 21, 61, 21, 21, 21, 61, 21, 21, 
1), tract = c(4000, 4501, 4800, 4501, 4501, 4000, 14900, 4501, 
4501, 1301), block = c(3001, 1025, 6001, 1025, 1025, 1025, 4000, 
1025, 1025, 3005), age = c(29, 40, 33, 27, 28, 35, 25, 33, 50, 
29), sex = c(0, 0, 0, 0, 1, 0, 0, 0, 0, 1), party = c("Ind", 
"Dem", "Rep", "Dem", "Dem", "Ind", "Dem", "Rep", "Rep", "Rep"
), PID = c(0, 1, 2, 1, 1, 0, 1, 2, 2, 2), place = c(74000, 60900, 
51000, 60900, 60900, 60900, 51000, 60900, 60900, 50000), pred.whi = c(0.021711601, 
0.015364583, 0.092415538, 0.854810748, 0.001548762, 0.852374629, 
0.831282563, 0.062022518, 0.396500218, 0.861168219), pred.bla = c(0.000955265, 
0.000232082, 0.004709997, 0.001087074, 0.000182351, 0.005259059, 
0.061324255, 0.00466914, 0.139072288, 0.04984491), pred.his = c(0.00283, 
0.00902, 0.786, 0.0178, 7.03e-05, 0.00809, 0.0106, 0.822, 0.268, 
0.0113), pred.asi = c(0.93364592, 0.90245186, 0.09924761, 0.04546436, 
0.99501901, 0.02529163, 0.01602557, 0.08321206, 0.11018413, 0.01633532
), pred.oth = c(0.040860431, 0.072931231, 0.0175463, 0.080798514, 
0.003179566, 0.108982246, 0.080770461, 0.028205698, 0.085832686, 
0.061340015)), spec = structure(list(cols = list(VoterID = structure(list(), class = c("collector_double", 
"collector")), surname = structure(list(), class = c("collector_character", 
"collector")), state = structure(list(), class = c("collector_character", 
"collector")), CD = structure(list(), class = c("collector_double", 
"collector")), county = structure(list(), class = c("collector_double", 
"collector")), tract = structure(list(), class = c("collector_double", 
"collector")), block = structure(list(), class = c("collector_double", 
"collector")), age = structure(list(), class = c("collector_double", 
"collector")), sex = structure(list(), class = c("collector_double", 
"collector")), party = structure(list(), class = c("collector_character", 
"collector")), PID = structure(list(), class = c("collector_double", 
"collector")), place = structure(list(), class = c("collector_double", 
"collector")), pred.whi = structure(list(), class = c("collector_double", 
"collector")), pred.bla = structure(list(), class = c("collector_double", 
"collector")), pred.his = structure(list(), class = c("collector_double", 
"collector")), pred.asi = structure(list(), class = c("collector_double", 
"collector")), pred.oth = structure(list(), class = c("collector_double", 
"collector"))), default = structure(list(), class = c("collector_guess", 
"collector")), delim = ","), class = "col_spec"), problems = <pointer: (nil)>, row.names = c(NA, 
10L), class = c("spec_tbl_df", "tbl_df", "tbl", "data.frame"))

内容的提问来源于stack exchange,提问作者david schraub

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 21:14:59