问题
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