4

I am trying to find out the R code which will give me the output of the statistical analysis(i.e. Regression, DOE, Gage RR) in pdf or html format by using R ( Not by using R-studio). I want to generate report of my statistical analysis. Is there any R code which we can run in to the R to make pdf or html file ??. I know it for graphs only,

pdf("output.pdf") x=rnorm(100,40,3) y=rnorm(100,100,5) fit=lm(y~x) summary(fit) plot(y) dev.off() 

This code gives me graph in pdf but I want all the summary of fit (ANOVA) and all information that R generates. Thanks

4
  • 2
    I do not want to use R-studio, I want to do it by using R only. Commented Jan 7, 2017 at 4:57
  • pdf is a PDF graphics device, which you could print text to with a lot of work, but it's not worth it. RMarkdown is the obvious answer here, and it can be used without RStudio, though RStudio does make using RMarkdown simpler and more powerful, so I'm not sure why you'd want to avoid it. Commented Jan 7, 2017 at 5:01
  • Thanks @alistaire, In my organisation I am not allowed to use R-studio. That's why I want to prepare .exe files by using R scripts. As we know in R-studio after clicking on "knitr" option in rmarkdown, code executes and we get nice output in pdf as well as in html format. I want code which can be used in R and which will work like "knitr" function of R-studio and give output in pdf or html format. Commented Jan 7, 2017 at 5:58
  • I believe the "Knit" button really just calls rmarkdown::render on the current file, so you can easily replicate that with a text editor that can handle RMarkdown and an R repl. Commented Jan 7, 2017 at 6:14

1 Answer 1

3

Yes, RMarkdown/knitr is the way to go.

See here for the documentation for creating a pdf document.

Your Rmd file might look something like the following:

--- title: "Report" author: "XXX" date: "January 7, 2017" output: pdf_document --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` ## Output ```{r} x <- rnorm(100, 40, 3) x y <- rnorm(100, 100, 5) y fit <- lm(y ~ x) summary(fit) ``` ## Plot ```{r plot, echo=FALSE} plot(y) ``` 

For an html document, simply change to output: html_document.

Render the pdf or html document with rmarkdown::render('filepath/yourfile.Rmd')

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks @alistaire, for your help. Could you please recommend me any book, website for to understand how to use all this in R ( not in R-studio) step by step bcz I am new to R. So that I can write nice programme in R. And how to use "rmarkdown" as well as "knitr" package in R ( not in R-studio) to get pdf / html output. thanks again.
Thanks @Conrad-mac

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.