LaTex and Python integration or R [closed]

0

Hello, I have a project that involves automating reports. Currently all reports are made through word and graphics in excel, now I'm trying to deploy an application that automatically generates the graphics in linguagem R and I wanted these graphics to be formatted in a nice banner in LaTex (I've always heard well of this complier of texts).

In this application I'm using: log%% logically for graphs, R for data manipulation and integration with python banks.

Graphs are made in mysql , but you can do in R also, because I use the python library, which is accepted in both.

And in this I wanted to integrate all of this in the end into ggplot2 generating the file.

In this case I would like directions, guidelines and tips if possible.

    
asked by anonymous 12.03.2018 / 19:07

2 answers

4

In this case, the best solution is to use rmarkdown . To get an idea of how it works, open RStudio and go to the menu File > New File > R Markdown...

ChoosetheDocumentandPDFoptions(notethatLaTeXneedstobeinstalledtowork):

Thiswillgenerateyoua.Rmdfile.Thedefaultfilehasthefollowingcontent:

---title:"Untitled"
author: "Marcus Nunes"
date: "3/12/2018"
output: pdf_document
---

'''{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
'''

## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

'''{r cars}
summary(cars)
'''

## Including Plots

You can also embed plots, for example:

'''{r pressure, echo=FALSE}
plot(pressure)
'''

Note that the 'echo = FALSE' parameter was added to the code chunk to prevent printing of the R code that generated the plot.

If you are using Windows, just use the shortcut Ctrl + Shift + K to compile the document.

If you can not use RStudio, you have other ways to compile the report, but they are more complicated than simply running Ctrl + Shift + K. I wrote a few years ago scripts in bash to do this, but I migrated to RStudio for the ease that the program generates.

There are several references about R Markdown on the internet. This is a good course on the subject (disclaimer: I wrote it).

    
12.03.2018 / 20:05
4

First, I'm not familiar with the Python language, so I'm going to focus on the R language. For data manipulation with R and sql, you can take a look at the RSQLite package that is particularly well done.

Considering that you manipulate data and graphs in R and the report via LaTeX , here are some options to perform analyzes, graphs and report automatically and reproducibly:

1. R and LaTeX integrated by makefile

make is a way to automate processes that you would do by hand on your system. In your example, you would code a makefile script to first run the R / python script to do the analysis, then run the R script to create the graphs and save it to a folder and then run the LaTeX script to create the report using the outputs of the previous scripts.

Positive: complete flexibility for each step performed and good organization of each project script.

Negative: makefile is a bit difficult to create and is native to both linux and iOS systems. I do not know how it works in Windows.

2. R and LaTeX integrated by Sweave

Sweave is a .Rnw extension of knitr that allows you to embed R code in LaTeX documents to generate a PDF file. In short, you write the report in laTex and for each analysis / chart, you enter the R code.

Positive: flexible and easy to use if you know LaTeX

Negative: I have the impression that there are very few users compared to Rmarkdown , which makes it a bit more difficult to solve problems online.

3. R and LaTeX integrated by Rmarkdown

Rmarkdown is an R package that allows you to embed R-code in markdown documents. It has practically the same approach as Sweave , only more flexible because it allows exporting to various extensions (pdf, html, word ...).

Positive: More friendly and simple to learn if you do not know LaTeX. In addition to the cleanest syntax.

Negative: The formatting of the report is not as flexible as LaTeX, but the interesting thing is that you can incorporate LaTeX or html styles into the document.

In conclusion, I personally believe Rmarkdown will be the easiest and fastest way to achieve your goals.

    
12.03.2018 / 20:05