I see a related question has already been asked, but it misses my particular use case.
If I have an org-mode table with some data, and I want to import it into an R session, using read.table
. However, I get an error saying Error in read.table(test) 'file' must be a character string or connection
:
#+TBLNAME: my_tab
| x | y |
|-------+---|
| 1.2 | d |
| 234.3 | e |
| 32 | f |
| 64 | g |
|-------+---|
#+begin_src R :var test=my_tab :results output :exports none :eval never-export
my_df <- read.table(test)
#+end_src
#+RESULTS:
: Error in read.table(test) :
: 'file' must be a character string or connection
But the following does work:
#+begin_src R :var test=my_tab :results output :exports none :eval never-export
my_df <- data.frame(test)
#+end_src
I'm not quite sure what it is that stops the import from happening in one case but not the other; perhaps it's an issue with type conversion or specifying the correct separator, but no changes I make seem to fix it.
Is there some way to stop the error and just use read.table()
?