From mboxrd@z Thu Jan 1 00:00:00 1970 From: Erik Iverson Subject: Re: [Org-Babel] and R... non-numeric cells Date: Thu, 12 Aug 2010 10:20:09 -0500 Message-ID: <4C641129.2080400@ccbr.umn.edu> References: <871va3hnvj.fsf@mundaneum.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable Return-path: Received: from [140.186.70.92] (port=37061 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OjZZn-00059r-Q4 for emacs-orgmode@gnu.org; Thu, 12 Aug 2010 11:20:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OjZZl-0004GB-Ib for emacs-orgmode@gnu.org; Thu, 12 Aug 2010 11:20:15 -0400 Received: from walleye.ccbr.umn.edu ([128.101.116.11]:4730) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OjZZl-0004G4-96 for emacs-orgmode@gnu.org; Thu, 12 Aug 2010 11:20:13 -0400 In-Reply-To: <871va3hnvj.fsf@mundaneum.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: =?UTF-8?B?U8OpYmFzdGllbiBWYXViYW4=?= Cc: emacs-orgmode@gnu.org Hello, I'm *guessing* that this is more likely an issue of R than of org-mode. Have you tried tangling the code and simply running the scripts through R= ? Essentially, the as.matrix function call is returning a character=20 matrix, which could mean your object 'alldata' has some factors instead=20 of numeric columns. R 2.7.1 is, by R standards, ancient, so it would not surprise me a bit if the differences were because of that old version. Unless you can show that this is somehow org-mode related, I'd construct a reproducible example and ask R-help. In any case, reproducible example will help in solving the problem. Good luck! --Erik S=C3=A9bastien Vauban wrote: > Hello, >=20 > For a report I'm writing, I've been helped by a colleague of mine (let'= s call > him Albert) for the R graphics generation. >=20 > Here's an extract of my doc: >=20 > --8<---------------cut here---------------start------------->8--- > #+TBLNAME: investissement-2010-2013 > #+ATTR_LaTeX: align=3DlSSSS > | | \s{Ann=C3=A9e 2010} | \s{Ann=C3=A9e 2011} | = \s{Ann=C3=A9e 2012} | \s{Ann=C3=A9e 2013} | > |------------------------+----------------+----------------+-----------= -----+----------------| > | RFO | 2596376.30 | 1500000.00 | 50000= 0.00 | 500000.00 | > | RFO r=C3=A9seau structurant | 3804467.00 | 6534066.00 | 3= 804467.00 | 0.00 | > | =C3=89quipements | 1000000.00 | 150000.00 | = 50000.00 | 50000.00 | > |------------------------+----------------+----------------+-----------= -----+----------------| > | Total (HTVA) | 7400843.30 | 8184066.00 | 435446= 7.00 | 550000.00 | > #+TBLFM: @5$2=3Dvsum(@-I..@-II);%.2f::@5$3=3Dvsum(@-I..@-II);%.2f::@5$4= =3Dvsum(@-I..@-II);%.2f::@5$5=3Dvsum(@-I..@-II);%.2f >=20 > whose graphical representation is: >=20 > #+srcname: barplot-investment(ptable =3D investissement-2010-2013) > #+begin_src R :file 1-01-investissement-2010-2013.png :exports none :se= ssion > source("mcplot.R", local=3DTRUE) > ## select the last row only, exclude first column, scale: unit =3D 1M > alldata <- as.matrix(ptable[2:4, -1]) / 1000000 > axisLabels <- c("Ann=C3=A9e", "Montant HTVA (M=E2=82=AC)") > mcStackedBarplot(alldata, "Investissements", c(2010:2013), ptable[-nrow= (ptable),1], legend.location=3D"topright") > #+end_src > --8<---------------cut here---------------end--------------->8--- >=20 > That works perfectly for him (on Ubuntu 9.04, R 2.7.1, Emacs 22.2.1, Or= g 6.35) >=20 > Not for me... on Ubuntu 10.04, R 2.10.1, Emacs 23.1.1, Org 7.01, ESS 5.= 10: I > get the message >=20 > *Error in as.matrix(ptable[2:4, -1])/1e+06 : > non-numeric argument to binary operator* >=20 > As 1M is numeric, the non-numeric operand must be > =3Das.matrix(ptable[2:4, -1])=3D... Verification: >=20 > --8<---------------cut here---------------start------------->8--- >> ptable > V1 V2 V3 V= 4 > 1 \\s{Ann=C3=A9e 2010} \\s{Ann=C3=A9e 2011} \\s{= Ann=C3=A9e 2012} > 2 RFO 2596376.3 1500000.0 500000.= 0 > 3 RFO r=C3=A9seau structurant 3804467.0 6534066.0 380= 4467.0 > 4 =C3=89quipements 1000000.0 150000.0 5= 0000.0 > 5 Total (HTVA) 7400843.3 8184066.0 4354467.= 0 > V5 > 1 \\s{Ann=C3=A9e 2013} > 2 500000.0 > 3 0.0 > 4 50000.0 > 5 550000.0 >=20 >> as.matrix(ptable[2:4, -1]) > V2 V3 V4 V5 =20 > 2 "2596376.3" "1500000.0" "500000.0" "500000.0" > 3 "3804467.0" "6534066.0" "3804467.0" "0.0" =20 > 4 "1000000.0" "150000.0" "50000.0" "50000.0"=20 > --8<---------------cut here---------------end--------------->8--- >=20 > The numerics are written between double quotes... Why!? >=20 > I had temporarily patched the above problem in my document by updating = the line > with the assignment: >=20 > --8<---------------cut here---------------start------------->8--- > #+srcname: barplot-investment-sva(ptable =3D investissement-2010-2013) > #+begin_src R :file 1-01-investissement-sva-2010-2013.png :exports none= :session > source("mcplot.R", local=3DTRUE) > ## select the last row only, exclude first column, scale: unit =3D 1M > alldata <- matrix(as.numeric(as.matrix(ptable[2:4, -1])), nrow=3D3, nco= l=3D4) / 1000000 > axisLabels <- c("Ann=C3=A9e", "Montant HTVA (M=E2=82=AC)") > mcStackedBarplot(alldata, "Investissements", c(2010:2013), ptable[2:4,1= ], legend.location=3D"topright") > #+end_src > --8<---------------cut here---------------end--------------->8--- >=20 > and I even just noticed that, instead of complexifying the expression, = I can > simplify it, in my case, as my =3Dptable=3D is numeric already: >=20 > --8<---------------cut here---------------start------------->8--- >> ptable[2:4, -1] > V2 V3 V4 V5 > 2 2596376.3 1500000.0 500000.0 500000.0 > 3 3804467.0 6534066.0 3804467.0 0.0 > 4 1000000.0 150000.0 50000.0 50000.0 > --8<---------------cut here---------------end--------------->8--- >=20 > But I still don't understand what is reponsible of a different treatmen= t of > string and numerics between our 2 machines. >=20 > Any idea? >=20 > Best regards, > Seb >=20