Is there a way to get an R Markdown document from a recently knitted document (html, pdf or Word)? - r

So I just recently started to learn how to use RStudio for my Bio class. For my latest submission, I knitted my lab, which was made as an R Markdown, into an HTML file. For some reason, I might have deleted my RMD file, which was also needed in the submission. Is there any way to convert my HTML (PDF or even Word) file back into an R Markdown file?
Thank you so much!
-SuperEli

No, one rmarkdown file generates a unique word/html/pdf
however, different rmarkdown files may generate same output results.

Related

Is there a way to convert an .Rmd file exported as a basic R Script using purl back into an .Rmd file?

I have a dataset that I am trying to get published as part of the supplementary information of a study that is in .Rmd format. The .Rmd file is set up to not only provide an easily readable printout of the statistical analyses performed in the study, but it also set up so to be a tool for other researchers working in the same area to use on their data. The intent being all they would have to do is insert their data and re-knit the file and their results would be printed out without having to rework the R code from scratch.
However, the journal will not accept .Rmd scripts as .Rmd files and possibly will not accept knitted .html printouts of an .Rmd file. The journal suggested to me that I save the .Rmd file as a plain R script using purl() and submit that instead. However, this creates a problem in that the script no longer generates an easily navigable printout (i.e., issues with headers and document text) and is more difficult to use. At the same time, I noticed that purl() seems to produce an R script that contains most of the information of the .Rmd file, particularly if one uses the options documentation=1 or documentation=2.
I am trying to figure out if there is any way to convert an .Rmd file back into an .Rmd file after it has been exported as a basic R script using purl? This way I could potentially submit the analysis as a basic R script as per the journal's requirements, but the user could convert it back into the script that produces a knitted html report if that is what they desire.

Is there any way to open multiple R markdown files and knit them at the same time?

I have several RMD files in one folder and I need to knit them one by one everyday to get html for each of them. Is there any way or function that I can open them at the same time and knit them by running only few lines code or one function?
did you have a look at this chapter: https://bookdown.org/yihui/rmarkdown/parameterized-reports.html. I think that is exactly what you will need.

Input .tex in Rmarkdown

I'm using Rmarkdown/Bookdown to write a paper/PDF document, which is an amazing tool #Yihui, thanks! Now I'm trying to include a table I have already put in LaTeX into the document by reading in this external .tex file. However, when knitting in RStudio with a \include{some-file.tex} or input{some-file.tex} in the body of the .Rmd outside of a chunk a LaTeX Error: Can be used only in preamble. is produced and the process stopped. I haven't found a way how to directly input through knit or otherwise into a chunk as well.
I found this question here: Rmarkdown v2, embed Latex document, although while the question is similar, there is no answer which would reflect how to input/include .tex-files into an .Rmd.
Why would I want this? Sometimes LaTeX tables offer more layout options than building directly in R, like for tables only with text rather than R-computed numbers. Also, when running models on a cluster, exporting results directly into .tex ready for compilation saves a lot of computation compared to have to open all these heavy .RData files just for getting the results into a PDF. Similarly, having sometimes multiple types of reports with different audiences, having the full R code in one main .Rmd file and integrating only the necessary results in other files reduces complexity by not having to redo all steps in each file newly. This way, I can keep one report with the full picture and do not have to check if I included every little change in various documents simultaneously.
So finally the question is how to get prepared .tex-Files into a .Rmd-document?
Thanks for your answers!

Converting Tex file generated by Knitr into .doc

Why is it important? My collaborators would like to be able to modify my .pdf reports and they are not able to modify the actual .tex code. They are sooo used to word !
How I write my reports? I use knitr. What a great and useful tool; thanks Yihui :)
What I'm looking for? convert the generated pdf report into .doc (my collaborators favorite !)
a solution might help: Pandoc (http://johnmacfarlane.net/pandoc/). As it's explained in the introduction of page of Pandoc, it can be used to convert LaTex to .docx and to markup. I then thought converting the .tex file of each of my reports (a .tex file is generated when I run my knitr .Rnw file) and convert it to .docx using pandoc:
pandoc -s myTexRepot.tex -o aDocReport.docx
issue: 1) Figures are missing in my .docx file. 2) I generate all my tables in my reports using xtable(), none of them can be converted! 3) Also, I lose all table of contents, section numbering.
Markup to Word: Issue (1) above is still an issue in converting Markup code to .doc
Is there any better idea to approach the issue of converting latex to doc. If Pandoc is the best, would you know how I can solve the issues above?
I really appreciate your help.
since you are already using knitr, you can call the rmarkdown:render() function to knit the document.
there is a parameter in render() called output_format[1]. the parameter along with the YAML header in your knitr document will allow you do generate the pdf and word document simultaneously
[1] output_format
R Markdown output format to convert to. Pass "all" to render all formats defined within the file. Pass the name of a format (e.g. "html_document") to render a single format or pass a vector of format names to render multiple formats. Alternatively you can pass an output format object; e.g. html_document(). If NULL is passed then the output format is the first one defined in the YAML metadata of the input file (defaulting to HTML if none is specified).

How to create R documentation file (.Rd) in latex?

Is there a simple way to create R documentation file for simple R functions?
I know I can edit a .Rd file in R-studio and preview it in HTML file. But how to put it into latex to edit and preview? Is there some latex package producing R documentation format?
There is the Rd2latex function in the tools package that will convert from the .Rd format to LaTeX format. This will let you preview the documentation in LaTeX. However this does not allow converting edits to the LaTeX document back to the .Rd document.
Look at Sweave, maybe it helpful for you.
Sweave is a tool that allows to embed the R code for complete data analyses in latex documents.
The purpose is to create dynamic reports, which can be updated automatically if data or analysis change. Instead of inserting a prefabricated graph or table into the report, the master document contains the R code necessary to obtain it. When run through R, all data analysis output (tables, graphs, etc.) is created on the fly and inserted into a final latex document.
The report can be automatically updated if data or analysis change, which allows for truly reproducible research.
Check out printr http://yihui.name/printr/ . It should do what you need if you are using knitr.
The problem with Rd2latex is that i haven't figured out which style file I need to use, otherwise it works fine.
When you generate the latex code with the Rd2latex function, make sure that you copy the Rd.sty file from the R directory, paste it and somewhere that latex can see it and use \usepackage{Rd}.
Try the knitr package, an easy way to generate flexible and fast dynamic reports with R for LaTex.

Resources