From mboxrd@z Thu Jan 1 00:00:00 1970 From: Vicente Vera Subject: Re: Strings converted to numbers in Org table? Date: Mon, 27 Feb 2017 13:49:26 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a1142d42c0cf3c705498359ca Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:55105) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciLgB-0007aH-P8 for emacs-orgmode@gnu.org; Mon, 27 Feb 2017 08:49:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciLgA-0002xk-Tl for emacs-orgmode@gnu.org; Mon, 27 Feb 2017 08:49:31 -0500 Received: from mail-ot0-x22a.google.com ([2607:f8b0:4003:c0f::22a]:34819) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ciLgA-0002wT-N9 for emacs-orgmode@gnu.org; Mon, 27 Feb 2017 08:49:30 -0500 Received: by mail-ot0-x22a.google.com with SMTP id w44so51816970otw.2 for ; Mon, 27 Feb 2017 05:49:27 -0800 (PST) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode --001a1142d42c0cf3c705498359ca Content-Type: text/plain; charset=UTF-8 Probably the issue is related to this function in `ob-core.el'? org-babel-read: "Convert the string value of CELL to a number if appropriate." Behind the curtains lies the built-in function `string-to-number'. Maybe that conversion should be made optional to leave the strings untouched. 2017-02-24 1:40 GMT+00:00 Vicente Vera : > Hello. I'm trying to get an Org table from an R data frame but data is > lost in the process. > > Here is a MWE. Note that: > > - In R every value is a string. "var2" contains no numbers (is a > character vector). > > - Upon conversion to a table Org removes the zero from "var2" last > value. > > ------------------------------ > > #+BEGIN_SRC R :session *mwe* :results value table :colnames yes > tst <- data.frame(var1 = c("a", "b", "c", "d", "e", "f", "g"), > var2 = c("150", "210", "140", "150", "192", "497", > "3.350"), > stringsAsFactors = FALSE) > tst > #+END_SRC > > #+RESULTS: > | var1 | var2 | > |------+------| > | a | 150 | > | b | 210 | > | c | 140 | > | d | 150 | > | e | 192 | > | f | 497 | > | g | 3.35 | > > ------------------------------ > > Here's the output as seen in R: > > : > tst > : var1 var2 > : 1 a 150 > : 2 b 210 > : 3 c 140 > : 4 d 150 > : 5 e 192 > : 6 f 497 > : 7 g 3.350 > > Details on the data frame: > > : > str(tst) > : 'data.frame': 7 obs. of 2 variables: > : $ var1: chr "a" "b" "c" "d" ... > : $ var2: chr "150" "210" "140" "150" ... > > It seems Org knows that the values on column "var2" are numbers and > converts the strings to numbers, applying some obscure trimming on the > digits. The "3.350" value needs to be left as is. > > --001a1142d42c0cf3c705498359ca Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Probably the issue is related to this function in `ob-core= .el'?

org-babel-read: "Convert the string value of CELL to = a number if
appropriate."

Behind the curtains lies the built= -in function `string-to-number'.

Maybe that conversion should be= made optional to leave the strings
untouched.

2017-02-24 1:40 GMT+00:00 Vicente= Vera <vicentemvp@gmail.com>:
Hello. I'm trying to get an Org table from an = R data frame but data is
lost in the process.

Here is a MWE. Note= that:

- In R every value is a string. "var2" contains no = numbers (is a
=C2=A0 character vector).

- Upon conversion to a ta= ble Org removes the zero from "var2" last
=C2=A0 value.
------------------------------

#+BEGIN_SRC R :session *mwe* :result= s value table :colnames yes
=C2=A0 tst <- data.frame(var1 =3D c("= ;a", "b", "c", "d", "e", "= ;f", "g"),
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 var2 = =3D c("150", "210", "140", "150", &= quot;192", "497", "3.350"),
=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 stringsAsFactors =3D FALSE)
=C2=A0 tst
#+END_SR= C

#+RESULTS:
| var1 | var2 |
|------+------|
| a=C2=A0=C2= =A0=C2=A0 |=C2=A0 150 |
| b=C2=A0=C2=A0=C2=A0 |=C2=A0 210 |
| c=C2=A0= =C2=A0=C2=A0 |=C2=A0 140 |
| d=C2=A0=C2=A0=C2=A0 |=C2=A0 150 |
| e=C2= =A0=C2=A0=C2=A0 |=C2=A0 192 |
| f=C2=A0=C2=A0=C2=A0 |=C2=A0 497 |
| g= =C2=A0=C2=A0=C2=A0 | 3.35 |

------------------------------

He= re's the output as seen in R:

: > tst
:=C2=A0=C2=A0 var1= =C2=A0 var2
: 1=C2=A0=C2=A0=C2=A0 a=C2=A0=C2=A0 150
: 2=C2=A0=C2=A0= =C2=A0 b=C2=A0=C2=A0 210
: 3=C2=A0=C2=A0=C2=A0 c=C2=A0=C2=A0 140
: 4= =C2=A0=C2=A0=C2=A0 d=C2=A0=C2=A0 150
: 5=C2=A0=C2=A0=C2=A0 e=C2=A0=C2=A0= 192
: 6=C2=A0=C2=A0=C2=A0 f=C2=A0=C2=A0 497
: 7=C2=A0=C2=A0=C2=A0 g = 3.350

Details on the data frame:

: > str(tst)
: 'da= ta.frame':=C2=A0=C2=A0=C2=A0 7 obs. of=C2=A0 2 variables:
:=C2=A0 $ = var1: chr=C2=A0 "a" "b" "c" "d" ...=
:=C2=A0 $ var2: chr=C2=A0 "150" "210" "140&quo= t; "150" ...

It seems Org knows that the values on column = "var2" are numbers and
converts the strings to numbers, applyi= ng some obscure trimming on the
digits. The "3.350" value need= s to be left as is.


--001a1142d42c0cf3c705498359ca--