On Tue, 14 Jul 2015, lom pik wrote:

Hi,

-- this was only tested with the current git version

I was trying to export a table as a variable to R via babel evaluation.
However it seems that is the rows are empty , the exported table ends at
the last non-empty value.

For example,the second row of tbl-issue defined below ends with 2 columns
[8,9]. The next table however works ok. I've narrowed down the cause to the
orgtbl-to-tsv function as highlighted below.

Not a bug IMO.

See the R documentation page for `read.table'. Note `fill'.


#+NAME: tbl-issue
| 1 | 2 | 3 | 5 | 6 | 7 |
| 8 | 9 |   |   |   |   |
#+BEGIN_SRC R :session *R* :var df2=tbl-issue  :results value    ## won't
work
print(df2)
#+END_SRC

You have two options (at least):

1. Place `NA' in the last cell of the last line

2. add ' , fill=TRUE ' like this:

#+BEGIN_SRC emacs-lisp
  (setq
   ob-R-transfer-variable-table-with-header
   "%s <- local({
       con <- textConnection(
         %S
       )
       res <- utils::read.table(
         con,
         header    = %s,
         row.names = %s,
         sep       = \"\\t\",
         as.is     = TRUE, fill=TRUE
       )
       close(con)
       res
     })")
#+END_SRC


Either way you will get:

#+RESULTS:
| 1 | 2 |   3 |   5 |   6 |   7 |
| 8 | 9 | nil | nil | nil | nil |


HTH,

Chuck


Reply via email to