emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Passing a variable into an R source block.
@ 2021-05-28 15:52 Roger Mason
  2021-05-28 17:30 ` Berry, Charles via General discussions about Org-mode.
  2021-05-28 19:29 ` William Denton
  0 siblings, 2 replies; 4+ messages in thread
From: Roger Mason @ 2021-05-28 15:52 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

I have an SQL source block that returns this:

#+RESULTS: query

|            date | jid   | te                               | rgkmax |     time | elapsed                       |
|-----------------+-------+----------------------------------+--------+----------+-------------------------------|
| 20210528-053900 | 647_1 | 20210528-053900 1 -1333.58106425 |      7 | 01:00:00 | Job Wall-clock time: 00:03:16 |
| 20210528-053900 | 647_1 | 20210528-053900 2 -1333.25006295 |      7 | 01:00:00 | Job Wall-clock time: 00:03:16 |
| 20210528-053900 | 647_1 | 20210528-053900 3 -1332.40596663 |      7 | 01:00:00 | Job Wall-clock time: 00:03:16 |
| 20210528-053900 | 647_1 | 20210528-053900 4 -1327.18802970 |      7 | 01:00:00 | Job Wall-clock time: 00:03:16 |
| 20210528-053900 | 647_1 | 20210528-053900 5 -1320.63944318 |      7 | 01:00:00 | Job Wall-clock time: 00:03:16 |


I would like to pass this into R for further processing.  At the moment
I have this:

#+begin_src R :session :colnames yes :var data=query
  r <- data.frame($data)
  t <- data.frame( str_split_fixed(r$te, " ", 3) )
  colnames(t) <- c('date','cycle','energy')
  df <- data.frame(r$date,r$jid,t$cycle,t$energy,r$x,r$time,r$elapsed)
      # colnames(df) <- c('date','jid','cycle','energy','time','elapsed')
      # df <- transmute(df,date,jid,cycle,energy,time,elapsed = str_remove(elapsed,"Job Wall-clock time: "))
      # tail(filter(df,jid == '$jid'),1)$energy
#+end_src

and the output is:

  /tmp/unknown!4fCXoM:20:17: unexpected '$'
19:    })
20: r <- data.frame($

I presume that is because R uses '$' to select a column from a data
frame.

I tried quoting like this:

r <- data.frame("$data")

but the output is then:

#+RESULTS:
| t.cycle | t.energy |
|---------+----------|

whereas I was expecting 7 columns of data from data frame 'df'.

I don't know if this is an org problem or an R problem, but if someone
can cast light on it, please do.

Thanks,
Roger

GNU Emacs 27.2 (build 1, amd64-portbld-freebsd11.4, X toolkit, cairo
version 1.16.0, Xaw3d scroll bars)
Org mode version 9.2.3 (release_9.2.3-390-gfb5091 @ /home/rmason/.emacs.d/org-git/lisp/)


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-05-29 14:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-28 15:52 Passing a variable into an R source block Roger Mason
2021-05-28 17:30 ` Berry, Charles via General discussions about Org-mode.
2021-05-29 14:13   ` Roger Mason
2021-05-28 19:29 ` William Denton

Code repositories for project(s) associated with this 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).