From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Price Subject: Re: rmarkdown-like production of multiple plots in org Date: Thu, 2 Apr 2020 13:52:24 -0400 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000007a053605a25270f8" Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:50434) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jK3zI-0006px-Nw for emacs-orgmode@gnu.org; Thu, 02 Apr 2020 13:50:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jK3zH-00077h-0C for emacs-orgmode@gnu.org; Thu, 02 Apr 2020 13:50:44 -0400 Received: from mail-oi1-x22b.google.com ([2607:f8b0:4864:20::22b]:34091) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jK3zG-00077O-Qy for emacs-orgmode@gnu.org; Thu, 02 Apr 2020 13:50:42 -0400 Received: by mail-oi1-x22b.google.com with SMTP id d3so3615172oic.1 for ; Thu, 02 Apr 2020 10:50:42 -0700 (PDT) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane-mx.org@gnu.org Sender: "Emacs-orgmode" To: "Berry, Charles" Cc: Org Mode --0000000000007a053605a25270f8 Content-Type: text/plain; charset="UTF-8" Thanks Chuck and all other respondents. Huh. I'll keep experimenting. I like Chuck's idea of helper function that pipes theoutput as described but for now, it might actually beeasier to stay with Rmarkdown (!). thanks, Matt On Thu, Apr 2, 2020 at 1:39 PM Berry, Charles wrote: > > > > On Mar 31, 2020, at 12:23 PM, Matt Price wrote: > > > > I'm completely new to R. > > > > I've started working with a project that creates plots using the ggplot > package -- so by default it creates grid objects, rather than writing to > files. > > > > In rmarkdown/rstudio, I can write something like this in a SOMEFILE.Rmd > : > > > > ``` > > install_github('eeholmes/CoV19') > > library(CoV19) > > getdata(); > > plot4(world, 'Ontario Canada') > > plot2(world, 'Italy') > > plot4(states, "WA") > > ``` > > > > I sort of love how the rmarkdown package will just create all 3 of those > plots, save them to auto-named files, and render to HTML. > > Actually, this is knitr (which rmarkdown Imports) at work. There are > options as to how knitr will handle multiple plots in a chunk as described > in > > https://yihui.org/knitr/options/#plots > > (which include `fig.show="animate"' to create an animation based on > multiple plots!) > > So this applies to various filetypes in addition to *.Rmd (*.Rnw, for > one). > > > > In RStudio, running just that block will also create all three blocks > and display them in the editor. > > > > By contrast, creating a series of many plots in org is fairly tedious. > I have to name the plot individually & put each function call in its own > src block. Is there any way to mimic the behaviour of rmarkdown instead? I > odn't understand babel or R enough to really even see how something like > that could be implemented, but I'd appreciate some pointers. Thank you! > > Getting babel to handle this seamlessly would be a significant effort. > > You can use ox-ravel (https://github.com/chasberry/orgmode-accessories.git) > to export to *.Rmd and then render the result. However, that does not have > the interactivity of `org-babel-execute-src-block' and does not insert the > graphics into the *.org file. > > I suppose that a function could be created to narrow to the src block, > export it as *.Rmd to a buffer, run that buffer as the `text' arg of > knitr::knit, then add links for the png's back to the *.org file. I haven't > thought much about this - getting this to work in a simple case would not > be too hard, but there may be a can of worms that this approach opens. > > HTH, > > Chuck > > > --0000000000007a053605a25270f8 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thanks Chuck and all other respondents.=C2=A0 Huh. I'l= l keep experimenting. I like Chuck's idea of helper function that pipes= theoutput as described but for now, it might actually beeasier to stay wit= h Rmarkdown (!). thanks, Matt

On Thu, Apr 2, 2020 at 1:39 PM Berry, Char= les <ccberry@health.ucsd.edu<= /a>> wrote:
<= br>
> On Mar 31, 2020, at 12:23 PM, Matt Price <
moptop99@gmail.com> wrote:
>
> I'm completely new to R.
>
> I've started working with a project that creates plots using the g= gplot package -- so by default it creates grid objects, rather than writing= to files.=C2=A0
>
> In rmarkdown/rstudio, I can write something like this in a SOMEFILE.Rm= d :
>
> ```
> install_github('eeholmes/CoV19')
> library(CoV19)
> getdata();
> plot4(world, 'Ontario Canada')
> plot2(world, 'Italy')
> plot4(states, "WA")
> ```
>
> I sort of love how the rmarkdown package will just create all 3 of tho= se plots, save them to auto-named files, and render to HTML.

Actually, this is knitr (which rmarkdown Imports) at work.=C2=A0 There are = options as to how knitr will handle multiple plots in a chunk as described = in

https://yihui.org/knitr/options/#plots

(which include `fig.show=3D"animate"' to create an animation = based on multiple plots!)

So this applies to various filetypes in addition to *.Rmd (*.Rnw, for one).=


>=C2=A0 In RStudio, running just that block will also create all three b= locks and display them in the editor.=C2=A0
>
> By contrast, creating a series of many plots in org is fairly tedious.= =C2=A0 I have to name the plot individually & put each function call in= its own src block. Is there any way to mimic the behaviour of rmarkdown in= stead? I odn't understand babel or R enough to really even see how some= thing like that could be implemented, but I'd appreciate some pointers.= =C2=A0 Thank you!

Getting babel to handle this seamlessly would be a significant effort.

You can use ox-ravel (https://github.com/chasber= ry/orgmode-accessories.git) to export to *.Rmd and then render the resu= lt.=C2=A0 However, that does not have the interactivity of `org-babel-execu= te-src-block' and does not insert the graphics into the *.org file.
I suppose that a function could be created to narrow to the src block, expo= rt it as *.Rmd to a buffer, run that buffer as the `text' arg of knitr:= :knit, then add links for the png's back to the *.org file. I haven'= ;t thought much about this - getting this to work in a simple case would no= t be too hard, but there may be a can of worms that this approach opens.
HTH,

Chuck


--0000000000007a053605a25270f8--