launch a file rmd ( markdown ) from R without using RStudio - r

It makes a moment for which I look if it's possible to launch/execute a file rmd ( markdown ) from R without using RStudio.
Because I have constraints in the work: I cannot use Rstudio.
I have examine but everybody uses use Markdown since Rstudio.
Converting Rmarkdown to PDF without RStudio

Related

How do I knit in Rstudio?

Everytime I click on knitr option in Rmarkdown, Rstudio starts installing knitr and Markdown and doesn't process my code. Please help me with a solution.
I am sure the codes written are correct. I have installed knitr, markdown and rmarkdown as well. But, I am not able to call knitr using "library(knitr)" function.

R Markdown - Open .Rmd with shyni runtime outside R

I'm working on a document with Rmarkdown on RStudio. In that rmd I use shiny runtime and my question is if I could generate some file with that document to open it outside RStudio, just like rmd without shiny runtime which generates an .html.
I was searching but I found nothing, does anyone know some tool to do that?
Many thanks!
Xevi

Code / Process for running rmarkdown in base R

All my codes developed in base R and I don't want to use RStudio, however I want to use rmarkdown feature in base R which is available in Rstudio.
I have downloaded rmarkdown package in base r, but not able to derive a code to publish my work
All the output of my codes written in R should be view able through web browser.
First make sure you're using .Rmd as your file extension. If not, rename it to a .Rmd extension. Make sure you have Pandoc installed on your OS.
Next, add the following to the top of the file:
---
title: "Your notebook title"
output: html_document
---
output: could take any value. You can pass in the value of ioslides_presentation for example if you want but it looks like html_document fits the criteria of what you want pretty well.
Once you have that, write your code in any editor (or the R console if you prefer). Use the code chunks and markdown text formatting as you normally would:
```{r}
plot(1:10)
```
In my base R Console, this is how mynotebook.Rmd looks like:
Finally, use the render() function from rmarkdown. You can either attach it and run render():
library(rmarkdown)
render("mynotebook.Rmd")
Or, run rmarkdown::render("mynotebook.Rmd").
Notice that the use of RStudio is not required at all since Pandoc is the document converter performing this task. For the so inclined, this is what its documentation has to say:
When you run render, R Markdown feeds the .Rmd file to knitr,
which executes all of the code chunks and creates a new markdown (.md)
document which includes the code and it's output.
The markdown file generated by knitr is then processed by pandoc
which is responsible for creating the finished format.
This may sound complicated, but R Markdown makes it extremely simple
by encapsulating all of the above processing into a single render
function.

Is there some convenient way to convert rmarkdown to pandoc markdown?

I use rstudio to write r-markdown, but sometimes it is not compatible with markdown support by pandoc(math for example. If there is a way allow me to convert r-markdown to pandoc markdown, then it will be convenient to export my articles to pdf, org, rts, latex...
https://pandoc.org/ also seems doesn't mention rmarkdown support.
I have tried to export .html form rstudio and use pandoc convert the html file back to markdown, but it seems doesn't work.
Actually pandoc is used to create pdf and other formats from r-markdown. Therefore there is an intermediate file with pandoc compatible markdown. You could retain this file by:
rmarkdown::render("document.Rmd", output_format = "pdf_document", run_pandoc = FALSE)

What are the commands executed if I press the "Compile PDF" button on a "Rnw" file in RStudio?

Once again I am in the situation that I want to replicate what is happening when I press the Compile PDF button on an .Rnw file in RStudio with my own R script.
For example I create a new .Rnw file in RStudio with File > New File > R Sweave. It looks like this:
\documentclass{article}
\begin{document}
\SweaveOpts{concordance=TRUE}
<<echo=F, results=tex>>=
library(xtable)
xtable(mtcars)
#
\end{document}
I inserted a chunk with alt+cmd+i and used the autocompletion to set the chunk options. Hence I assume I did everything with the default settings as RStudio assumes it to be. When I press Compile PDF everything works without problems. But when I execute:
knitr::knit2pdf("Sweave-test.Rnw")
I get an Error "It seems you are using the Sweave-specific syntax". Hence there are additional steps needed.
What I came up with so far is the following:
library(knitr)
tempfile1 <- tempfile(fileext=".Rnw")
Sweave2knitr(file = "input.Rnw", output = tempfile1)
tempfile2 <- tempfile(fileext=".tex")
knit(tempfile1, output=tempfile2)
tools::texi2pdf(tempfile2, clean=T)
system(paste("open", sub(".tex", ".pdf", basename(tempfile2))))
(The last line is OSX specific I think).
But I am curious to know what RStudio is doing exactly. I looked into the RStudio github page but am not sure where to find the command. Other Stackoverlow questions show that there are slight differences between what the button does and knit2pdf. It seems the question has been asked over and over again, also in relation to the Knit Html button. It might use functions from the knitr package, the markdown, the rmarkdown package, texi2pdf from the tools package, Sweave from the utils package or pandoc. I have no Idea...
Related question (that all got some rather vague answers):
Difference: "Compile PDF" button in RStudio vs. knit() and knit2pdf()
Difference between "Compile PDF" and knit2pdf
How to convert R Markdown to HTML? I.e., What does "Knit HTML" do in Rstudio 0.96?
What does “Knit HTML” do in Rstudio 0.98?
Compile .Rnw file with command
How to build Knitr document from the command line
Currently I am using RStudio 1.0.136.
I suspect it is just Sweave to turn a Rnw file into tex file and then calling pdflatex.exe to turn it from a tex file into a pdf file.
Sweave("Sweave-test.Rnw")
system("pdflatex.exe Sweave-test.tex")
And if you encountered a File Sweave.sty not found, you will need to add a path this file in your MiKTeX Options, please see here.

Resources