我已经创建了一个调用API的函数,但是我对length(url)有问题。我将代码简化如下,以显示问题:
library(jsonlite)
library(httr)
df<-data.frame("names"=c("20523717759","20555589574"))
calling<- function(x){
url1<-paste("https://api.sunat.cloud/ruc/",x,sep = "", collapse = NULL)
url1
res<- GET(url1)
}
sapply(df,calling)
下一个错误:
Error in parse_url(url) : length(url) == 1 is not TRUE
追溯是这样的:
13.
stop(simpleError(msg, call = if (p <- sys.parent(1L)) sys.call(p)))
12.
stopifnot(length(url) == 1)
11.
parse_url(url)
10.
is.url(url)
9.
stopifnot(is.url(url))
8.
build_url(parse_url(url)[c("scheme", "hostname", "port")])
7.
handle_name(url)
6.
handle_find(url)
5.
handle_url(handle, url, ...)
4.
GET(url1)
3.
FUN(X[[i]], ...)
2.
lapply(X = X, FUN = FUN, ...)
1.
sapply(df, calling)
如何更改我的函数“ calling”以应用于我的df?谢谢!
答案 0 :(得分:0)
在这里,我们可能需要提取“名称”列,然后使用
sapply(df$names, calling)