<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/rj-editor-analyse-your-data-with-r-in-jamovi/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://blog.jamovi.org/2018/07/30/rj.html"> jamovi</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<h3>tl;dr</h3>
<ul>
<li><code>Rj Editor</code> lets you analyse data in jamovi with R, and make use of your favourite R packages from within the jamovi statistical spreadsheet</li>
<li><code>jmvconnect</code> makes it easy to access jamovi data sets from R</li>
</ul>
<p><span></span></p>
<p>Rj is a new module for <a rel="nofollow" href="https://www.jamovi.org/" target="_blank">the jamovi statistical spreadsheet</a> that allows you to use the R programming language to analyse data from within jamovi. Although jamovi is already built on top of R, and all the analyses it provides are written in R, to date it hasn’t been possible to enter R code directly. Rj changes that.</p>
<p><img alt="Statkat options" src="https://i1.wp.com/blog.jamovi.org/assets/images/rj.png?w=456&ssl=1" data-recalc-dims="1"></p>
<p>There are many reasons you might want to do this; there are a lot (thousands!) of analyses available in R packages that haven’t been <a rel="nofollow" href="https://dev.jamovi.org/" target="_blank">made available as jamovi modules</a> (yet!), and Rj allows you to make use of these analyses from within jamovi. Additionally, you can make use of <em>loops</em> and <em>if-statements</em>, allowing (among other things) conditional analyses and simulation studies.</p>
<p>For some, using R in a spreadsheet will be an ideal place to begin learning R. For others it can be an easy way to share R analyses with less technically savvy colleagues. (And some people just prefer to code!)</p>
<h2>Installation</h2>
<p>Rj is available from the jamovi library, and requires a recent version of jamovi. The jamovi library is accessible from in the Analyses tab -> <em>modules</em> menu at the top right of the jamovi window. Scroll down the list until you find Rj, and select install. jamovi will download Rj, install it, and then Rj will be available from the jamovi analysis menu (The menu should pulsate blue when you first install a module).</p>
<h2>Enter code</h2>
<p>To run an R analysis, select <code>Rj Editor</code> from the R analysis menu. This will bring up the editor for entering your R code. The data set is available to you as a data frame, simply as <code>data</code>. To get started, you might like to run descriptives on it.</p>
<p><img alt="Statkat options" src="https://i2.wp.com/blog.jamovi.org/assets/images/rj2.png?w=456&ssl=1" data-recalc-dims="1"></p>
<p>Or if you prefer the dplyr approach, you could go:</p>
<div>
<div>
<pre><code>library(jmv)
library(dplyr)
library(magrittr)

select(data, 1:3) %>%
    descriptives()
</code></pre>
</div>
</div>
<p>You’ll notice as you’re entering this code, Rj auto-suggests function names, like in RStudio.</p>
<p>To run the code, press Control+Shift+Enter (or ⌘+Shift+Enter if you’re on a Mac). jamovi will run the R code and the results will appear in the results panel like other analyses. You can continue to make changes to the code, and press Control+Shift+Enter to run it again.</p>
<p>By default, Rj makes use of the version of R bundled with jamovi. This includes many packages (jmv and all it’s dependencies, <a rel="nofollow" href="https://cran.r-project.org/package=jmv" target="_blank">see here</a>), and will be sufficient for many people, but if you need to make use of additional R packages then you’ll need to make use of the <em>System R</em> version. If you select the configuration gear to the top right of the code box, you’ll see an option to change the R version used.</p>
<p>The <em>System R</em> version uses the version of R you have installed (i.e. from CRAN). This has the advantage that your R code now has access to all of the packages you have installed for that version of R. jamovi should locate your system R installation automatically (It uses the same algorithm that RStudio uses). The last thing you will need is to have the <code>jmvconnect</code> R package installed in your system R library. This package allows your system R version to access the jamovi data sets. You can install it from an R terminal or from RStudio with:</p>
<div>
<div>
<pre><code>install.packages('jmvconnect')
</code></pre>
</div>
</div>
<p>Once this is done, moving from the <em>jamovi R</em> to the <em>System R</em> should be seamless.</p>
<p>It’s worth remembering that sharing jamovi files with colleagues becomes a bit more complicated when you make use of the <em>System R</em> version. If they want to make changes and re-run your analyses, they will need to have the same R packages installed – that’s the price of flexibility!</p>
<h2>Not all data</h2>
<p>When Rj runs R code, by default it makes the whole data set available as a data frame called <code>data</code>. However, it’s likely that your analysis only makes use of a few columns, and doesn’t need the whole data set. You can limit the columns made available to the analysis by including a special comment at the top of your script, of the form:</p>
<div>
<div>
<pre><code># (column1, column2, column3)

library(jmv)

...
</code></pre>
</div>
</div>
<p>In this instance, only the named columns will appear in the <code>data</code> data frame. This can speed the analysis up, particularly if you are working with large data sets. Additionally, this lets jamovi know that the analysis is only using these columns, and the analysis will not need to be re-run if changes are made to other columns.</p>
<h2>To the terminal!</h2>
<p>There may be times where you’ll want to transition to an R terminal or RStudio for analysing a data set. This is where the <a rel="nofollow" href="https://cran.r-project.org/package=jmvconnect" target="_blank"><code>jmvconnect</code> R package</a> comes in handy. <code>jmvconnect</code> let’s you read the data sets from a running jamovi instance into an R session. At time of writing it has two functions:</p>
<ul>
<li><code>what()</code></li>
<li><code>read()</code></li>
</ul>
<p><code>what()</code> lists the available data sets, and <code>read()</code> reads them. For example, you might go:</p>
<div>
<div>
<pre><code>> library(jmvconnect)
>
> what()

 Available Data Sets                   
 ─────────────────────────────────────
        Title           Rows    Cols   
 ─────────────────────────────────────
   1    iris             150       5   
   2    Tooth Growth      60       3   
 ─────────────────────────────────────
</code></pre>
</div>
</div>
<p>and then read the data set with:</p>
<div>
<div>
<pre><code>data &lt;- read('Tooth Growth')
</code></pre>
</div>
</div>
<p>or</p>
<div>
<div>
<pre><code>data &lt;- read(2)
</code></pre>
</div>
</div>
<p>Before you ask, we intend on adding support for reading .omv files from R too (and for saving/opening .RData files from inside jamovi).</p>
<h2>Work in progress</h2>
<p>Auto-suggest is a work in progress, but you’ll still find it pretty useful. At present, it only suggests functions from the base packages, the recommended packages, and jmv. This is something we’ll broaden in the future. We also need to add a help system where you can access package documentation.</p>
<p>Package installation for the <em>System R</em> is <em>technically</em> possible through Rj, but is less than ideal. The UI will hang, and you won’t receive any feedback as to what’s going on. This is something we’ll improve in the future. For now, you can just use an R terminal, or RStudio.</p>
<p>On some windows machines, an R window flashes briefly when running analyses using the <em>System R</em>. I’m not sure why this is, but I think it’s a bug in the <code>evaluate</code> package. If anyone knows any more about the issue, I’d be keen to hear from you.</p>
<p>Finally, if you’re using jamovi on linux from the PPA, it’s currently using an older version of R, and you you <em>may</em> encounter issues with plots when using the system R. If this is a problem, we recommend using the <a rel="nofollow" href="https://flathub.org/apps/details/org.jamovi.jamovi" target="_blank">flatpak version from flathub</a> instead.</p>
<h2>In summary</h2>
<p>Rj and jmvconnect make is easy to access R from jamovi, and jamovi from R.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://blog.jamovi.org/2018/07/30/rj.html"> jamovi</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/VQ3rnf7EzgY" height="1"></a></div>