Skip to content

Weird problem with latest RQuantLib not working with QuantMod on R 2.13.1

8 messages · chandra bajpai, R. Michael Weylandt, Dirk Eddelbuettel +1 more

#
Hi,
I just got a new machine and installed a fresh version of R 2.13.1
(latest version) and
I think I found a problem with RQuantLib causing a problem an external
module (QuantMod).

I've got a 3 line program that shows the problem:

R Version - R 2.13.1  (32 bit)
OS: WIndows 7-64 bit
RQuantLib ver: 0.3.8
QuantMod ver: 0.3-17

R Test Program Execution:
Loading required package: Rcpp
Error in if (adjust) { : argument is not interpretable as logical
Now if I comment out library(RQuantLib), it works perfectly.

What am I doing wrong?  Any workaround?
bw - This works perfectly on my R 2.11.1 machine.

Thanks,
Chandra
#
HI Michael...thanks for the quick reply, I'm to to R, how does one
report such a bug?
I wonder if it's the bug exists in 2.12 at all.

Thanks,
Chandra

On Tue, Sep 27, 2011 at 11:21 PM, R. Michael Weylandt
<michael.weylandt at gmail.com> wrote:
#
Chandra already contacted me too (off-list) and Jeff and I will indeed look
into this.  But as a traceback() immediately shows, the code in quantmod
stumbles over a test where 'adjust' is used. This variable is set earlier if
unset -- and there seems to be a bad side-effect with a (namespace-protected)
function of that name in RQuantLib.

The easiest workaround for now is to ... simply specify adjust=TRUE (or FALSE
depending on what you want).

Here is an example (using littler's r, Rscript would work similarly):

  edd at max:~$ r -lquantmod,RQuantLib -e 'getSymbols("GOOG", from = "2011-05-01", to="2011-05-30", auto.assign = TRUE); print(head(GOOG))'

  Attaching package: 'utils'

  The following object(s) are masked from 'package:Rcpp':

      .DollarNames, prompt

  Error in if (adjust) { : argument is not interpretable as logical
  Execution halted

and by simply adding adjust=TRUE it all works, as it does when RQuantLib is
not loaded:

  edd at max:~$ r -lquantmod,RQuantLib -e 'getSymbols("GOOG", from = "2011-05-01", to="2011-05-30", auto.assign = TRUE, adjust=TRUE); print(head(GOOG))'
  
  Attaching package: 'utils'
  
  The following object(s) are masked from 'package:Rcpp':
  
      .DollarNames, prompt
  
             GOOG.Open GOOG.High GOOG.Low GOOG.Close GOOG.Volume GOOG.Adjusted
  2011-05-02    545.70    545.73   537.12     538.56     2133700        538.56
  2011-05-03    537.13    542.01   529.63     533.89     2081500        533.89
  2011-05-04    535.17    539.00   533.02     535.79     2117000        535.79
  2011-05-05    533.86    539.42   531.50     534.27     1997800        534.27
  2011-05-06    538.15    541.46   535.18     535.30     2056100        535.30
  2011-05-09    535.00    538.49   531.10     537.68     1948700        537.68
  edd at max:~$ 
  

Cheers, Dirk
#
Chandra,

FYI, here is a simple patch I tossed at Jeff earlier today and which he is
pondering.  In the meantime, apply it to quantmod sources and you're safe
from any interferene from objects named 'adjust' by rewriting the test a
little more conservatively.

Hope this helps,  Dirk


Index: pkg/R/getSymbols.R
===================================================================
--- pkg/R/getSymbols.R	(revision 567)
+++ pkg/R/getSymbols.R	(working copy)
@@ -190,7 +190,7 @@
 function(Symbols,env,return.class='xts',index.class="Date",
          from='2007-01-01',
          to=Sys.Date(),
-         ...)
+         ..., adjust)
 {
      importDefaults("getSymbols.yahoo")
      this.env <- environment()
@@ -198,7 +198,7 @@
         # import all named elements that are NON formals
         assign(var, list(...)[[var]], this.env)
      }
-     if(!exists("adjust", environment()))
+     if(missing("adjust"))
        adjust <- FALSE
 
      default.return.class <- return.class
#
Hi Chandra,

A bug in getSymbols yahoo.  Patched in rev 568 on R-forge.  exists was
walking up the enclosing frames until it found a bound variable
'adjust' which in this case came from RQuantlib.  I added
inherits=FALSE to patch.

Thanks for the report (as well as thanks to Dirk for a suggested fix).

Best,
Jeff
On Tue, Sep 27, 2011 at 10:12 PM, chandra bajpai <cbajpai at gmail.com> wrote:

  
    
#
On 28 September 2011 at 14:58, Dirk Eddelbuettel wrote:
| FYI, here is a simple patch I tossed at Jeff earlier today and which he is

Jeff being Jeff, a more compact patch has now been committed.  Upgrade to
HEAD of svn also fixes things.

Dirk