R 什么是错误'vec_assign()':'value'应该循环使用以适应'x'。想告诉我吗
我有一个函数,它可以进行一些基本的web获取。成功登录后调用此函数。(网站已被屏蔽xxxxxx) 搜索功能:R 什么是错误'vec_assign()':'value'应该循环使用以适应'x'。想告诉我吗,r,tidyverse,tibble,R,Tidyverse,Tibble,我有一个函数,它可以进行一些基本的web获取。成功登录后调用此函数。(网站已被屏蔽xxxxxx) 搜索功能: search <-function(HorseList){ url <- "http://tnetwork.xxxxxx.com/tnet/HorseSearch.aspx" s <- GET(url) xxxxxx <- tibble( horse_name = character(), race_date = c
search <-function(HorseList){
url <- "http://tnetwork.xxxxxx.com/tnet/HorseSearch.aspx"
s <- GET(url)
xxxxxx <- tibble(
horse_name = character(),
race_date = character(),
race_nbr = character(),
trk = character(),
peak = character(),
dist_run = character()
)
for (row in 1:nrow(HorseList))
{
url <-paste(c('http://tnetwork.xxxxxx.com/tnet/HorseSearchAPI.aspx?HorseName=',toString(HorseList[[row, 1]])),collapse='')
#print(url)
h <- GET(url)
temp<-content(h, "text")
doc <- htmlParse(temp)
horse_name <- HorseList[[row,1]]
horse_ID <-xpathSApply(doc,"//*[@id=\"resultsDiv\"]/p[1]/a/@href")
horse_ID <-substr(horse_ID,27,40)
h_list <- list()
c <- nchar(horse_ID)
if (length(c)>0)
{
h_list[1] <- horse_ID
}
id_count <- length(h_list)
for (k in 1:id_count)
{
url <-paste(c('http://tnetwork.xxxxxx.com/tnet/t_PastPerf.aspx?HorseID=',toString(h_list[k])),collapse='')
t <- GET(url)
temp <- content(t, "text")
pastperf <- htmlParse(temp)
row_count<-length(xpathSApply(pastperf,"//*[@id=\"pastPerfTable\"]/tr"))
for(j in 2:row_count)
{
j<- toString(j)
race_data <- xpathSApply(pastperf,paste("//*[@id=\"pastPerfTable\"]/tr[",j,"]/td[1][1]"),xmlValue)
race_date <- substr(race_data,1,10)
race_number <-trimws(substr(race_data,12,100))
horse_name <- URLdecode(toString(horse_name))
race_nbr = str_match(race_number,'(Race\\s\\d+)(.*)')[,2]
trk = str_match(race_number,'(Race\\s\\d+)(.*)')[,3]
peak <-xpathSApply(pastperf,paste("//*[@id=\"pastPerfTable\"]/tr[",j,"]/td[13]"),xmlValue)
cum_distance <-xpathSApply(pastperf,paste("//*[@id=\"pastPerfTable\"]/tr[",j,"]/td[14]"),xmlValue)
newrow <- paste(horse_name,',',race_date,',',race_nbr,',',trk, ',',peak,',',cum_distance)
xxxxxx <- add_row(trakus, horse_name = horse_name, race_date = race_date, race_nbr = race_nbr, trk=trk, peak = peak, dist_run = cum_distance)
}
}
}
return(xxxxxx)
}
我运行了rlang::last_error()和last_trace()命令以获得一些额外的见解,但我仍然不确定发生了什么
> rlang::last_error()
<error/rlang_error>
Internal error in `vec_assign()`: `value` should have been recycled to fit `x`.
Backtrace:
1. base::source("~/TimeForm/Scripts/past_perf.R", echo = TRUE)
6. global::search(horse_list) ~/TimeForm/Scripts/past_perf.R:627:2
7. tibble::add_row(...) ~/TimeForm/Scripts/past_perf.R:85:8
8. tibble:::rbind_at(.data, df, pos)
9. vctrs::vec_rbind(old, new)
Run `rlang::last_trace()` to see the full context.
> rlang::last_trace()
<error/rlang_error>
Internal error in `vec_assign()`: `value` should have been recycled to fit `x`.
Backtrace:
x
1. +-base::source("~/TimeForm/Scripts/past_perf.R", echo = TRUE)
2. +-base::source("~/TimeForm/Scripts/past_perf.R", echo = TRUE)
3. | +-base::withVisible(eval(ei, envir))
4. | \-base::eval(ei, envir)
5. | \-base::eval(ei, envir)
6. \-global::search(horse_list) ~/TimeForm/Scripts/past_perf.R:627:2
7. \-tibble::add_row(...) ~/TimeForm/Scripts/past_perf.R:85:8
8. \-tibble:::rbind_at(.data, df, pos)
9. \-vctrs::vec_rbind(old, new)
10. \-(function () ...
>rlang::last_error()
`vec_assign()`:`value`中的内部错误应被回收以适合`x`。
回溯:
1.base::source(“~/TimeForm/Scripts/pass\u perf.R”,echo=TRUE)
6.全局::搜索(马列表)~/TimeForm/Scripts/pass\u perf.R:627:2
7.tibble::add_row(…)~/TimeForm/Scripts/pass_perf.R:85:8
8.tibble:::rbind_at(.data,df,pos)
9vctrs::vec\u rbind(旧、新)
运行`rlang::last_trace()`查看完整上下文。
>rlang::最后一次跟踪()
`vec_assign()`:`value`中的内部错误应被回收以适合`x`。
回溯:
x
1. +-base::source(“~/TimeForm/Scripts/pass\u perf.R”,echo=TRUE)
2. +-base::source(“~/TimeForm/Scripts/pass\u perf.R”,echo=TRUE)
3. | +-基础::可见(评估(ei,环境))
4. | \-基础:评估(ei、envir)
5. | \-基础:评估(ei、envir)
6. \-全局::搜索(马列表)~/TimeForm/Scripts/pass\u perf.R:627:2
7. \-tibble::add_row(…)~/TimeForm/Scripts/pass_perf.R:85:8
8. \-tibble:::rbind_at(.data,df,pos)
9. \-vctrs::vec\u rbind(旧、新)
10. \-(函数()。。。
此时将显示添加_行()我的代码中的行可能是罪魁祸首,但我不确定错误说明了什么,也不知道如何修复它。有人有什么见解可以分享吗?我发现问题发生在处理空字符字段、空值或使用NA时。如果替换空值,则通过映射纠正了问题
map_depth(.depth = 1, map_if, is_empty, ~paste0(""))
当然,您需要调整depth命令,以便在列表构造的适当级别进行更正
理想情况下,bind_rows()将更可靠地处理包含NA或NULL值的向量
map_depth(.depth = 1, map_if, is_empty, ~paste0(""))