Convert HTML to R Markdown

允我心安 提交于 2019-12-08 09:54:17

问题


Is there a way to convert an html file, such as https://cran.r-project.org/web/packages/tidytext/vignettes/tidytext.html, and convert it to an executable R Markdown file (rmd)?


回答1:


In short, no.

The pandoc binary is almost pure awesomeness, and I use it eg to convert the html output from an Rd file back into markdown (to be included in other markdown documents).

But that uses pandoc for what it knows: convert from markdown to html etc. pandoc itself knows nothing about R. So apart from the metaphysical difficulty of getting the code back from the output it created, you have a tool mismatch.

So in some: you probably want the original source code as you cannot recreate Rmd from the html output it produces.




回答2:


If a markdown file (.md) is sufficient then download and install pandoc if you don't already have it. Then run this from the commmand line or use system("pandoc ...") or shell("pandoc ...") from within R.

pandoc https://cran.r-project.org/web/packages/tidytext/vignettes/tidytext.html -o out.md

For a particular file, it would be possible to post-process the source code and output sections but would represent some additional effort, possibly substantial.



来源:https://stackoverflow.com/questions/41336628/convert-html-to-r-markdown

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!