我遇到了this service,它会很好地格式化我的本地降价文件。根据示例,使用样本curl命令很容易获得格式良好的响应。
我要做的是利用一些可用的选项,即版本和“名称”参数。我将如何构建curl命令?以下是我在R中使用的代码示例。
此代码运行良好,但缺少指定的选项:
doc.up <- "curl -X POST --data-urlencode content@test-markdown.md \ http://documentup.com/compiled > index.html"
system(doc.up)
我尝试指定名称选项,但没有骰子:
doc.up <- "curl -X POST --data-urlencode name@mynamevar content@test-markdown.md \ http://documentup.com/compiled > index.html"
system(doc.up)
任何帮助将不胜感激!
编辑:根据以下一些建议,我尝试了几种方法来使用Rcurl
和HTTR
。我在Rstudio中使用默认的Markdown模板,但为了完整起见,我将其保存为test-markdown.Rmd并将其编译为test-markdown.md。
使用RCurl,我试图:
## 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'))
使用httr,我试过了:
## 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")))
答案 0 :(得分:5)
以下代码适用于我:
library(httr)
url <- "http://documentup.com/compiled"
contents <- readLines("README.md")
resp <- POST(url, body = list(content = contents, name = "plyr"))
content(resp)
答案 1 :(得分:1)
@ Btibert3实际上,您可以使用rstudio.markdownToHTML
选项将其绑定到RStudio。见http://www.rstudio.com/ide/docs/authoring/markdown_custom_rendering