emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Passing a variable into an R source block.


From: Roger Mason
Subject: Passing a variable into an R source block.
Date: Fri, 28 May 2021 13:22:44 -0230
User-agent: mu4e 1.5.6; emacs 27.2

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/)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]