From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Berry, Charles" via "General discussions about Org-mode." Subject: Re: rmarkdown-like production of multiple plots in org Date: Thu, 2 Apr 2020 17:39:22 +0000 Message-ID: References: Reply-To: "Berry, Charles" Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:48967) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jK3os-0000te-Ld for emacs-orgmode@gnu.org; Thu, 02 Apr 2020 13:40:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jK3or-0002Dx-BF for emacs-orgmode@gnu.org; Thu, 02 Apr 2020 13:39:58 -0400 Received: from mx0a-00395d01.pphosted.com ([148.163.133.170]:4038) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1jK3oq-0002DA-PN for emacs-orgmode@gnu.org; Thu, 02 Apr 2020 13:39:57 -0400 In-Reply-To: Content-Language: en-US Content-ID: 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: Matt Price Cc: Org Mode > On Mar 31, 2020, at 12:23 PM, Matt Price wrote: >=20 > I'm completely new to R. >=20 > I've started working with a project that creates plots using the ggplot p= ackage -- so by default it creates grid objects, rather than writing to fil= es. =20 >=20 > In rmarkdown/rstudio, I can write something like this in a SOMEFILE.Rmd := =20 >=20 > ``` > install_github('eeholmes/CoV19') > library(CoV19) > getdata(); > plot4(world, 'Ontario Canada')=20 > plot2(world, 'Italy')=20 > plot4(states, "WA") > ``` >=20 > 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 optio= ns 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 multi= ple plots!) So this applies to various filetypes in addition to *.Rmd (*.Rnw, for one).= =20 > In RStudio, running just that block will also create all three blocks an= d display them in the editor. =20 >=20 > 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 hav= e the interactivity of `org-babel-execute-src-block' and does not insert th= e graphics into the *.org file.=20 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::kni= t, then add links for the png's back to the *.org file. I haven't thought m= uch about this - getting this to work in a simple case would not be too har= d, but there may be a can of worms that this approach opens. HTH, Chuck