I came across this service that will format my local markdown files rather nicely. Per the example, it is easy to get a nicely formatted response with a sample curl command.
What I am looking to do is utilize some of the options available, namely the version and “name” parameters. How would I go about structuring the curl command? Below are the code samples that I have used within R.
This code works nicely, but lacks the specified options:
doc.up <- "curl -X POST --data-urlencode content@test-markdown.md \ http://documentup.com/compiled > index.html"
system(doc.up)
I tried to specify the name option, but no dice:
doc.up <- "curl -X POST --data-urlencode name@mynamevar content@test-markdown.md \ http://documentup.com/compiled > index.html"
system(doc.up)
Any help will be greatly appreciated!
EDIT: Per some of the suggestions below, I have attempted a few ways to use Rcurl and HTTR. I am using the default Markdown template within Rstudio, but for completeness sake, I saved it as test-markdown.Rmd and compiled it test-markdown.md.
Using RCurl, I attempted:
## attempt 1
f <- paste(readLines('test-markdown.md'),collapse="\n" )
h <- dynCurlReader()
wp <- curlPerform(url="http://documentup.com/compiled",
postfields = c(content=f))
## attempt 2
postForm("http://documentup.com/compiled",
"content" = fileUpload('test-markdown.md'))
Using httr, I tried:
## attempt 3
tmp <- POST("http://documentup.com/compiled", body = list(content= upload_file(f)))
content(tmp)
## attempt 4
tmp <- POST("http://documentup.com/compiled", body = list(content= upload_file("test-markdown.md")))
The following code works for me: