emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Roger Mason <rmason@mun.ca>
To: emacs-orgmode@gnu.org
Subject: Passing a variable into an R source block.
Date: Fri, 28 May 2021 13:22:44 -0230	[thread overview]
Message-ID: <y658s3y4zzn.fsf@mun.ca> (raw)

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	other threads:[~2021-05-28 15:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-28 15:52 Roger Mason [this message]
2021-05-28 17:30 ` Passing a variable into an R source block Berry, Charles via General discussions about Org-mode.
2021-05-29 14:13   ` Roger Mason
2021-05-28 19:29 ` William Denton

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=y658s3y4zzn.fsf@mun.ca \
    --to=rmason@mun.ca \
    --cc=emacs-orgmode@gnu.org \
    /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).