3

I'm working on a PHP web app that calls R through curl and RApache. Most things work fine. But one lattice plot throws this error:

RApache Warning/Error!!!Error in uy + c(-1, 1) : non-numeric argument to binary operator

I tried saving the data structures that feed into the plot and doing the plot in my local R, but then the plot works just fine. So I can't replicate the error.

These are the loaded libraries when the script runs in RApache:

library(Brew)
library(Cairo)
library(rjson)
library(DBI)
library(RMySQL)
library(reshape)
library(plyr)
library('RColorBrewer')
library(ggplot2)
library(lattice)
library(latticeExtra)
library(hexbin)

Here is a bit of the script:

colgrad.pal<-colorRampPalette(brewer.pal(11,'Spectral'), interpolate='spline')

//problem plot
dists.med.lplot<-levelplot(value~starttime+groupname|dists, data=MDist.median,
  col.regions=rev(colgrad.pal(200)),colorkey=list(col=rev(colgrad.pal(200))),
  xlab='Time(s)',ylab='Treatment',
  main='Level Plot of Median Distance',
  layout=c(1,3))

And here is a link to a datafile. I read it in like this: //link appears untrustworthy, so removed

Data looks like this:

'data.frame':   2880 obs. of  6 variables:
 $ groupname: Factor w/ 8 levels "rowA","rowB",..: 1 1 1 1 1 1 1 1 1 1 ...
 $ fCycle   : Factor w/ 6 levels "Cycle 1","Cycle 2",..: 6 6 6 6 6 6 6 6 6 6 ...
 $ fPhase   : Factor w/ 2 levels "Dark","Light": 1 1 1 1 1 1 1 1 1 1 ...
 $ starttime: int  0 60 120 180 240 300 360 420 480 540 ...
 $ dists    : Factor w/ 3 levels "inadist","lardist",..: 1 1 1 1 1 1 1 1 1 1 ...
 $ value    : num  47.5 64 78.3 39.2 53.7 ...

Any ideas on what the problem is or how to better troubleshoot this?

ETA version/platform info

        [platform] => sparc-sun-solaris2.10
        [arch] => sparc
        [os] => solaris2.10
        [system] => sparc, solaris2.10
        [status] => 
        [major] => 2
        [minor] => 10.1
        [year] => 2009
        [month] => 12
        [day] => 14
        [svn rev] => 50720
        [language] => R
        [version.string] => R version 2.10.1 (2009-12-14)
dnagirl
  • 20,196
  • 13
  • 80
  • 123
  • What version(s) of R, RApache, and what OS are you using? – Joshua Ulrich Oct 18 '10 at 18:20
  • @Joshua Ulrich: R version 2.10.1, probably RApache 1.1.9 (no dates on the distro, but it was the most recent at the end of this July), OS Solaris2.10 – dnagirl Oct 18 '10 at 18:47
  • could you get a traceback of the error somehow? On a sidenote, the safety report of Norton on your link is rather worrying... http://safeweb.norton.com/report/show?url=filebin.ca Don't know if it's a real risk in your file or just a general idea they have from the site, but it's worth looking at. – Joris Meys Oct 18 '10 at 19:41
  • @Joris Meys: that's disturbing about the file. My local version is just a .csv and doesn't raise any alarms. I will look for another file dump site, and remove the offending link. – dnagirl Oct 18 '10 at 19:47
  • 1
    I check the file itself, and your file doesn't give anything. Hence, problem is the site. I checked a bit further, and apparently it's a problem with malicious files hosted somewhere else on filebin.ca. FWIW, I use dropbox (www.dropbox.com) for file sharing (among other things). Tried a lot of ways, but after setting this up I never looked for anything else again. It's worth a try. – Joris Meys Oct 18 '10 at 20:14

1 Answers1

2

The error smells of an issue with your data. I would try the following:

  • before the actual call to plot() et al, save all your (relevant) data via save(x, y, z, ..., file="/tmp/dbg.RData")
  • then load all the relevant data from the saved file in a 'normal' R session and inspect and compare
  • this should allow you to pinpoint a data issue that you may then be able to circumvent with more sanity checks etc to prevent your actual code from falling over.
Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • That's excellent advice. I had 'saved' the data with `write.table(MDist.median ,file=fn,row.names=F)`. The file produced by `write.table()` gives no errors when processed in 'normal' R. But using the `save()` method reproduces the error exactly. Strange thing is, the resulting data frames look the same to me. – dnagirl Oct 18 '10 at 19:24
  • 1
    It appears that the `save()`d data.frame did not consider the first column a factor, but the `write.table()`d data.frame did. So I changed the code to explicitly set the factors for my data.frame and now everything works! – dnagirl Oct 18 '10 at 20:09
  • Sweet. Glad to have been of help. – Dirk Eddelbuettel Oct 18 '10 at 20:10