用户可能知道R但需要运行以下python代码
import requests
import json
query = "asthma"
r = requests.post("https://ndar.nih.gov/api/search/nda_sw_removal/collection/full", query)
collections = json.loads(r.text)
collections
使用R库,如何在R中重写request.post调用?
挑战是python对query
参数的确切作用。
答案 0 :(得分:2)
我猜您正在寻找类似httr的内容:
取自here的例子:
b2 <- "http://httpbin.org/post"
POST(b2, body = "A simple text string")
取自here的另一个例子:
r <- POST("http://httpbin.org/post", body = list(a = 1, b = 2, c = 3))
基于Slam在评论中提出的建议:
答案 1 :(得分:0)
library(httr)
query = "asthma"
r = POST("https://ndar.nih.gov/api/search/nda_sw_removal/collection/full", body=query)
library(jsonlite)
aa<-fromJSON(content(r,'text'))
str(aa)
View(aa$collection$results)