Learn R Programming

Rgretl (version 0.2.2)

run_grcli: running gretl scripts

Description

The function runs gretl scripts from inside R. Currently it outputs a list with components specified by output argument.

Usage

run_grcli(text, 
          input = list(matr = list(), char = character()),
          output=list(matr=character(), char=character(),
                      series = character()),
          data=NULL)
# run_grcli(text) # only prints
# run_grcli(text, data = data_frame)
# run_grcli(text, data = "gret_file.gdt")

Arguments

text

gretl script formed as a character vector, see Examples.

input

determines additional components of input: scalars, vectors, matrices, and character strings:

char = c(name1 = value1,name2 = value2,...)

For 'matr' values can be numeric vectors, or matrices. For example, run_grcli('print x',input = list(matr = list(x=pi/4))) will print x = 0.78539816. Numeric vectors will be translated as [gretl] column matrices. If x is explicitly created in R as a matrix object its dimentions will be preserved.

'char' values are one-element character vectors.

output

determines components of the output list: it should contain names of gretl script objects (in the text argument) as character vectors; matr can contain names of gretl scalars and matrices; char can contain names of gretl string objects; series can contain names of gretl series. Series are broadcasted back to R as numeric vectors.

data

a name (without quotes) of an R data.frame, ts, or mts object; a name of gretl (or gretl-supported, e.g. Stata, Eviews, SAS, SPSS, etc) data file as character string.

Value

A list with components specified by output argument. Output components could be numeric atomic vectors, matrices, or character vectors; gretl scalars, row and column matrices, and series are converted to atomic vectors.

Examples

Run this code
# NOT RUN {
# The differences with the native gretl script are:
# (i) name of character vector (gr.script <- here)
# (ii) quotes: for make hansl code a character string;
#      quotes inside script should be escaped, e.g. 
#      text <- "eval \"hello, word\""
gr.script <- 
"open denmark.gdt -q
ols diff(LRY) 0 diff(LRM) IBO --simple-print
restrict --silent
b[2] + b[3] = 0.3
end restrict
pv = $pvalue
if pv > 0.05
restrict --full
b[2] + b[3] = 0.3
end restrict
set warnings off
modtest --white-nocross 
endif"
run_grcli(gr.script)

Rz = run_grcli('print w v x\n eval x**y\n z = mexp(y)\n print z',
           input = list(matr = list(w = 1,v = 1:4, x= matrix(1:2,1),
           y = matrix(rep(1,9),3))),
           output = list(matr = "z"))
Rz$z

# }
# NOT RUN {
# After gretl is properly installed one can
# safely copy-past and run this example

scr <-
"nulldata 10
set seed 13
series y = normal()
matrix x = seq(1,7)
matrix z = mshape({y},5,2)
string str = \"Hello, user!\"
print str"
ou <- run_grcli(scr,output = list(matr=c("x","z"),char="str",series = "y"))
ou
# }

Run the code above in your browser using DataLab