emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Eric Schulte <eric.schulte@gmx.com>
To: Daniel Drake <silophophe@gmail.com>
Cc: "emacs-orgmode@gnu.org" <emacs-orgmode@gnu.org>
Subject: Re: [0][babel][R] Undesired conversion of integers to floats in R code block output
Date: Sat, 18 Feb 2012 09:23:36 -0700	[thread overview]
Message-ID: <87boowrtyv.fsf@gmx.com> (raw)
In-Reply-To: <4F3D53D6.40407@gmail.com> (Daniel Drake's message of "Thu, 16 Feb 2012 11:07:02 -0800")

[-- Attachment #1: Type: text/plain, Size: 1800 bytes --]

Daniel Drake <silophophe@gmail.com> writes:

> Hi All,
>
> I'm using R in org-mode/babel to analyze data from a psychological
> study.  The subjects in this study are identified by nine digit integers
> (e.g., 987654321) that I treat as strings (or factors) in my R data
> frames.
>
> Tables output by an R code block that contain these subject IDs are
> not formatted properly: the subject IDs seem to be treated as numbers
> and a decimal point and a trailing zero are appended.  For example,
> what should be
> |   subj.id |
> |-----------|
> | 987654321 |
> becomes
> |     subj.id |
> | 987654321.0 |
> (I've included real, self-contained code below.)
>
> When I write the data frames directly to a file from within the R code
> block (using a write.table function call that mimics the one in
> ob-R.el), the integer IDs are preserved; but when code from ob-R.el
> writes them out, the values get reformated as floats.
>
> I've noticed that eight digit integers are not modified in the same
> way, which makes me wonder if there is a 'digits' threshold I could
> modify to prevent this from happening.
>
> I've pretty much ruled out the possibility that this transformation
> occurs in R; however I'm not proficient enough in elisp to follow the
> operations that happen after the data frame is written to a file in
> the org-babel-R-write-object-command.
>
> Any pointers to help me figure this out would be very appreciated!
> (I've seen this thread:
> http://comments.gmane.org/gmane.emacs.orgmode/31373, but do not know
> if the conversion to calc has been made already or if it is the source
> of the problem.)
>

Hi Dan,

When I launch Emacs without any personal configuration (emacs -Q),
evaluate ob-R.el to add R support, and then execute your code blocks I
get the following behavior.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: dan.org --]
[-- Type: text/x-org, Size: 570 bytes --]

* Test
** table as generated by org-mode/babel
#+name: make
#+begin_src R  :results value  :colnames yes
  temp <- data.frame('A'=c('987654321'),'B'=c('98765432'))
  ## -- this call mimics the one in ob-R.el
  write.table(temp,file='test_r.tsv',sep='\t',na='nil',row.names=FALSE,col.names=TRUE,quote=FALSE)
  temp
#+end_src

#+RESULTS: make
|         A |        B |
|-----------+----------|
| 987654321 | 98765432 |

** table as generated by R directly
#+name: read
#+begin_src sh  :results output
   cat test_r.tsv
#+end_src

#+RESULTS: read
: A	B
: 987654321	98765432

[-- Attachment #3: Type: text/plain, Size: 311 bytes --]


I would recommend installing the latest version of Org-mode from source
as that tends to fix many problems, and will at least ensure that we are
both working from the same code base moving forward.  See
http://orgmode.org/worg/org-faq.html#Keeping-current

Best,

-- 
Eric Schulte
http://cs.unm.edu/~eschulte/

  reply	other threads:[~2012-02-18 16:23 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-16 19:07 [0][babel][R] Undesired conversion of integers to floats in R code block output Daniel Drake
2012-02-18 16:23 ` Eric Schulte [this message]
2012-02-19  7:02   ` Daniel Drake
2012-02-19 16:48     ` Eric Schulte
2012-02-19 17:40       ` Daniel Drake
2012-02-19 18:28         ` Daniel Drake
2012-02-19 19:27           ` Daniel Drake
2012-02-19 20:46             ` Eric Schulte
2012-02-19 21:19               ` Daniel Drake
2012-02-19 21:35               ` Achim Gratz
2012-02-20 17:36                 ` Achim Gratz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87boowrtyv.fsf@gmx.com \
    --to=eric.schulte@gmx.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=silophophe@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).