gretlR is an R package that can run gretl
program from R
Markdown.
gretlR can be installed using the following commands in R.
Please load the gretlR package as follows:
```{r gretlR}
library(gretlR)
```
Then create a chunk for gretl
as shown below:
```{gretl gretlR,eval=T,echo=T,comment=NULL}
nulldata 500
set seed 13
gretl1 = normal()
gretl2 = normal()
setobs 12 1980:01 --time-series
gnuplot gretl1 --time-series --with-lines --output="line.png"
gnuplot gretl2 gretl1 --output="scatter.png"
ols gretl1 const gretl2
modeltab add
tabprint --output="olsTable.Rmd"
tabprint --output="olsTable.tex"
tabprint --output="olsTable.csv"
eqnprint --output="olsEquation.tex"
```
The above chunk creates a gretl program with the chunk’s content,
then automatically run the gretl script, which will save gretl outputs
in the new folder gretlR
created in the current working
directory.
We can dynamically and reproducibly fetch the
gretl
graph object we created with the gretl
chunk using the following R chunk:
For the scatter graph:
or the line graph:
we can also include the equation of the OLS generated by the
gretl
chunk and save as olsEquation.tex
.
If the output is pdf
, one can use the raw
LaTeX
codes as follows:
\input{gretlR/gretlR/olsEquation.tex}
Or use include_tex
function to include the equation as
shown below:
The OLS table output is saved by the gretl
chunk as
olsTable.Rmd
. The entire OLS table output can included as
child document as follows:
```{r child, child='gretlR/gretlR/olsTable.Rmd'}
```
The gretl
chunk also saves the OSL table as
olsTable.csv
. The import_kable
function can be
used to import it as a table. further customisation can be done with
kableExtra
package.
This function writes gretl
file.
This function executes existing gretl
files.
This function creates gretl
file from R object or a set
of character strings and executes it. It is a combination of
write_inp
and exec_inp
functions.
Demo can be accessed via demo(package="gretlR")
.
The R Markdown template for the gretlR
can be accessed
via
file -> New File -> R Markdown -> From Template -> gretlR
Please download a set of example files from Github.