[R] writing binary data from RCurl and postForm

2015-08-05 Thread Greg Donald
I'm using RCurl with postForm() to post to a URL that responds with a PDF. I cannot figure out how to write the resulting PDF data to a file without corruption. result = postForm(url, binary=TRUE) Both this: capture.output(result, file='/tmp/export.pdf') and this: f = file('/tmp/export.pdf',

Re: [R] writing binary data from RCurl and postForm

2015-08-05 Thread Martin Morgan
On 08/05/2015 11:52 AM, Greg Donald wrote: I'm using RCurl with postForm() to post to a URL that responds with a PDF. I cannot figure out how to write the resulting PDF data to a file without corruption. result = postForm(url, binary=TRUE) Both this: capture.output(result,

Re: [R] writing binary data from RCurl and postForm

2015-08-05 Thread Hadley Wickham
I think that is because the value returned from postForm has an attribute; remove it by casting the return to a vector fl - tempfile(fileext=.pdf) writeBin(as.vector(postForm(url, binary=TRUE)), fl) The httr package might also be a good bet writeBin(content(POST(url)), fl) Or