[R] RCurl and postForm()

Elmore, Ryan Ryan.Elmore at nrel.gov
Fri Apr 29 21:14:04 CEST 2011


Hi everybody,

I think that I am missing something fundamental in how strings are passed from a postForm() call in R to the curl or libcurl functions underneath.  For example, I can do the following using curl from the command line:

$ curl -d "Archbishop Huxley" "http://www.datasciencetoolkit.org/text2people"
[{"gender":"u","first_name":"","title":"archbishop","surnames":"Huxley","start_index":0,"end_index":17,"matched_string":"Archbishop Huxley"}]

Trying the same thing, or what I *think* is the same thing (obvious not) in R (Mac OS 10.6.7, R 2.13.0) produces:

> library(RCurl)
Loading required package: bitops
> api <- "http://www.datasciencetoolkit.org/text2people"
> postForm(api, a="Archbishop Huxley")
[1] "[{\"gender\":\"u\",\"first_name\":\"\",\"title\":\"archbishop\",\"surnames\":\"Huxley\",\"start_index\":44,\"end_index\":61,\"matched_string\":\"Archbishop Huxley\"},{\"gender\":\"u\",\"first_name\":\"\",\"title\":\"archbishop\",\"surnames\":\"Huxley\",\"start_index\":88,\"end_index\":105,\"matched_string\":\"Archbishop Huxley\"}]"
attr(,"Content-Type")
                charset
"text/html"     "utf-8"

I can match the result given on the DSTK API's website by using system(), but doesn't seem like the R-like way of doing something.

> system("curl -d 'Archbishop Huxley' 'http://www.datasciencetoolkit.org/text2people'")
158   141  141   141    0[{"gender":"u","first_name":"","title":"archbishop","surnames":"Huxley","start_index":0,"end_index":17,"matched_string":"Archbishop Huxley"}]    17    599     72 --:--:-- --:--:-- --:--:--   670

If you want to see some additional information related to this question, I posted on StackOverflow a few days ago:
http://stackoverflow.com/questions/5797688/post-request-using-rcurl

I am working on this R wrapper for the data science toolkit as a way of illustrating how to make an R package for the Denver RUG and ran into this problem.  Any help to this problem will be greatly appreciated by the Denver RUG!

Cheers,
Ryan



More information about the R-help mailing list