[Gretl-users] About interacting with R

Allin Cottrell cottrell at wfu.edu
Mon Aug 5 03:38:41 EDT 2013

On Mon, 5 Aug 2013, yinung at Gmail wrote:

> I am trying to write a function that can retrieve stock data via R from
> Yahoo finance as follows.
> This script is working both under my ubuntu and XP with gretl 1.9.12 cvs
> build date 2013-05-06.
> A problem occurred when I replace
>        getSymbols("@sym",return.class="ts",from="@s1",to="2012-08-02")
> with
>        getSymbols("@sym",return.class="ts",from="@s1",to="@s2")
> It seems that the second string replacement @s2 does not work. It cannot be
> recognized as a valid argument in R.
> Do anyone have an idea?

Yes, see below.

> <hansl>
> function list getsymbols(string sym[null],string s1[null], string s2[null])
>    foreign language=R
>        library(quantmod)
>        getSymbols("@sym",return.class="ts",from="@s1",to="2012-08-02")
>        tmpM <- @sym
>        gretl.export(tmpM)
>    end foreign
> append "@dotdir/tmpM.csv"
> list tmplist= *
> return tmplist
> end function
> nulldata 9
> string mys1="2012-07-22"
> setobs 5 @mys1 --time-series
> string mySym="MSFT"
> string mys1="2012-07-22"
> string mys2="2012-08-02"
> list xlist = getsymbols(mySym,mys1,mys1)

This is a nice application, there's simply a bug in the last 
line, which should read

list xlist = getsymbols(mySym,mys1,mys2)

With that modification it works fine here. However, it seems 
there is a bug in the R function GetSymbols(): if you set the 
final date to (e.g.) "2012-07-23" (for just two days of 
data) you get an error:

Error in round(frequency) : non-numeric argument to 
mathematical function

Maybe for some reason you have to get at least one week's 

Allin Cottrell

More information about the Gretl-users mailing list