<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/linpe-make-sending-and-receiving-data-analysis-faster-and-easier/"></div></div><div><a data-url="https://www.r-bloggers.com/linpe-make-sending-and-receiving-data-analysis-faster-and-easier/" data-counturl="https://www.r-bloggers.com/linpe-make-sending-and-receiving-data-analysis-faster-and-easier/" data-count="horizontal" data-text="Linpe: make sending and receiving data analysis faster and easier" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.quantide.com/linpe-make-sending-receiving-data-analysis-faster-easier/"> R blog | Quantide - R training &amp; consulting</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>When performing some kind of analysis in R it is usually common to use data stored in basic formats such as <em>.csv</em> or <em>.Rdata</em>, and then present the analysis using a <em>.Rmd</em> file.</p>
<p>This process solves a lot of processing-related problems and saves time by allowing the analyst to perform their statistical analysis and at the same time have their work in a nice format such as <em>.pdf</em> or <em>.html</em> ready to be shown to the recipients. However, this also means that whenever you need to send the analysis to someone, you need to <strong>knit</strong> the <em>.Rmd</em> and send at least two files:</p>
<ol>
<li>the data</li>
<li>and the knitted <em>.Rmd</em></li>
</ol>
<p>This is usually not a major problem, however what if you could embed the analysis in the data and send just a single file, in short:</p>
<blockquote><p>Is it possible to send a single file instead of two?</p>
</blockquote>
<p>The answer is yes, there is an R package specifically designed for doing that and shortening the hustle of sending files back and forth. The package I am talking about is <a target="_blank" href="https://github.com/quantide/linpe"><strong>linpe</strong></a>, created by Andrea Spanò, managing partner at <a target="_blank" href="http://www.quantide.com/">Quantide</a>.</p>
<h2>What does the linpe package do?</h2>
<p><img sizes="(max-width: 300px) 100vw, 300px" alt="how-linpe-works" class="wp-image-2802" src="https://i0.wp.com/www.quantide.com/wp-content/uploads/2016/09/ImmagineLinpe-300x214.png?resize=300%2C214" data-recalc-dims="1"></p>
<div>
<p>In short, the <em>linpe</em> package provides you with a neat set of functions to embed your <em>.Rmd</em> analysis in the data as an <strong>attribute</strong>, then save the resulting object to a single file, send it to whoever needs it and finally render the <em>.Rmd</em> as a <em>.pdf</em> or a <em>.html</em> file on the recipient pc. Furthermore, if the recipient of the analysis would like to add something to it or make some changes, the <strong>linpe</strong> package allows them to extract the embedded <em>.Rmd</em> file and make all the necessary edits before sending the analysis back.</p>
</div>
<div>
<h2>How does it work?</h2>
<p>Let me walk you through a short tutorial on how to use the <strong>linpe</strong> package.</p>
<p>First of all, suppose you have just completed your analyisis and saved it as an <em>.Rmd</em> file, for instance <em>test-linpe.Rmd</em>, with the following content:</p>
<pre># ---
# title: &quot;Test linpe&quot;
# output: html_document
# ---
# 
# ```{r setup, include=FALSE}
# knitr::opts_chunk$set(echo = TRUE)
# ```
# 
# 
# ```{r, message = FALSE}
# require(dplyr)
# require(ggplot2)
# ```
# 
# Do something
# 
# ```{r}
# mtcars %>% 
#  tbl_df() %>%
#  group_by(cyl) %>%
#  summarise(n = n(), mean_mpg = mean(mpg), sd_mpg = sd(mpg))
# ```  
#
#
# Plot something
#
# ```{r}
# ggplot(mtcars, aes(disp, mpg)) + geom_point()
# ```</pre>
<p>at this point you would usually send by email (or share via Dropbox, Gdrive or else…) both the <em>.Rmd</em> and the data file. However, if you decide to use <strong>linpe</strong>, you can choose to do the following instead:</p>
<pre>require(linpe)
# Link .Rmd to the data using linpe
mtcars_linpe &lt;- link(mtcars, file = &quot;test-linpe.Rmd&quot;)</pre>
<p>Now the <em>.Rmd</em> file <em>test-linpe.Rmd</em> has just been linked to the data and you can save the resulting object using the basic <em>save</em> function and then send it to your colleagues.</p>
<p>From now on, I’ll be referring to the <em>.Rmd</em> file attached to the data frame as a <strong>linpe</strong>.</p>
<p>Quoting the readme file in the <strong>Github</strong> repo of the package:</p>
<blockquote><p>Any <em>.Rmd</em> linked to a data frame is known as a <strong>linpe</strong>.</p>
</blockquote>
<pre># Save the linked dataset as an Rdata file
save(mtcars_linpe, file = &quot;mtcars-linpe.Rdata&quot;  )</pre>
<p>Once your colleague receives the <em>mtcars-linpe.Rdata</em> file, he can load it into R by using the usual <em>load</em> function</p>
<pre># Reload
load(&quot;mtcars-linpe.Rdata&quot;)</pre>
<p>Since you can link more than one <em>.Rmd</em> files using <strong>linpe</strong>, there is a specific function that lets you check what <strong>linpes</strong> are available to be rendered after having loaded the <em>.Rdata</em> object. By using the function <em>linpe</em> you can check the names of the available linpes.</p>
<p>The feature that lets you link to the data more than one analysis is perhaps one of the most interesting. If you are running three kind of analysis on the same dataset and you would like to keep them separated from each other, thend you would have at least 4 files to send. In that case <strong>linpe</strong> can make your life (and the one of the recipient) much easier.</p>
<p>Let’s check what linpes are available within the <em>mtcars_linpe</em> dataset</p>
<pre># Check name of linpes
linpe(mtcars_linpe)

##########################
## Output
##########################

# [1] &quot;test-linpe&quot;</pre>
<p>Finally, when you found the one you need to check, you can easily render it by using the <em>perform</em> function. Note that the second parameter of this function takes the name of the linpe to be rendered as an argument.</p>
<pre># Render the linpe
perform(mtcars_linpe, linpe = &quot;test-linpe&quot;)</pre>
<p>This line of code will render the <em>.Rmd</em> file attached to the data in the exact same way it happens when clicking <em>knit</em> in <strong>RStudio</strong>. Note that, of course, you’ll need to have installed all the packages used in the analysis in order for the rendering to go through without errors.</p>
<p>If you need to add something to the analysis or making some edits, you can open the source <em>.Rmd</em> file by using the <em>display</em> function</p>
<pre># Display .Rmd linked to the linpe
display(mtcars_linpe, linpe = &quot;test-linpe&quot;)</pre>
<p>Finally, in case you would like to remove the ‘linpe’ attribute from the data frame, you can use the <em>unlink</em> function as follows</p>
<pre>mtcars_linpe &lt;- unlink (mtcars_linpe, linpe = &quot;test-linpe&quot;)
linpe(mtcars_linpe)

##########################
## Output
##########################

# No limpe in mtcars_linpe 
# character(0)</pre>
</div>
<div>
<h2>Where can I find this package?</h2>
<p>The <strong>linpe package</strong> is available to be downloaded directly from its <a target="_blank" href="https://github.com/quantide/linpe">Github repository</a> under the GPL license.</p>
<p>Sending and receiving a lot of files can, sometimes, be frustrating, the aim <strong>linpe</strong> is to make this process more fluid and lean, while at the same time keeping all the advantages that make Rmarkdown so attractive to use when performing analysis.</p>
<p>Thank you for reading this article, please feel free to leave a comment if you have any questions or suggestions and share the post with others if you find it useful.</p>
</div>
<p> </p>
<p>The post <a target="_blank" rel="nofollow" href="http://www.quantide.com/linpe-make-sending-receiving-data-analysis-faster-easier/">Linpe: make sending and receiving data analysis faster and easier</a> appeared first on <a target="_blank" rel="nofollow" href="http://www.quantide.com/">Quantide – R training &amp; consulting</a>.</p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="https://www.r-bloggers.com/linpe-make-sending-and-receiving-data-analysis-faster-and-easier/"></div></div><div><a data-url="https://www.r-bloggers.com/linpe-make-sending-and-receiving-data-analysis-faster-and-easier/" data-counturl="https://www.r-bloggers.com/linpe-make-sending-and-receiving-data-analysis-faster-and-easier/" data-count="vertical" data-text="Linpe: make sending and receiving data analysis faster and easier" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://www.quantide.com/linpe-make-sending-receiving-data-analysis-faster-easier/"> R blog | Quantide - R training &amp; consulting</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 title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/kLDo0z5-Lyc"></a></div>