<?xml version="1.0" encoding="UTF-8" ?>
<!-- RSS generated by PHPBoost on Mon, 18 May 2026 09:36:14 +0200 -->

<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Last articles - STHDA : R]]></title>
		<atom:link href="https://www.sthda.com/english/syndication/rss/articles/2" rel="self" type="application/rss+xml"/>
		<link>https://www.sthda.com</link>
		<description><![CDATA[Last articles - STHDA : R]]></description>
		<copyright>(C) 2005-2026 PHPBoost</copyright>
		<language>en</language>
		<generator>PHPBoost</generator>
		
		
		<item>
			<title><![CDATA[R2DOCX : Create a word document with R]]></title>
			<link>https://www.sthda.com/english/articles/2-r/7-r2docx-create-a-word-document-with-r/</link>
			<guid>https://www.sthda.com/english/articles/2-r/7-r2docx-create-a-word-document-with-r/</guid>
			<description><![CDATA[<!-- START HTML -->
<ul id="toc"></ul>
<!-- END HTML --><br />
<br />
Two ways to generate a word document. Either with <a href="http://yihui.name/knitr/demo/pandoc/">Knitr and pandoc</a> or with <a href="https://github.com/davidgohel/R2DOCX">R2DOCX</a>.<br />
<br />
<h3 class="formatter-title">Pandoc : Convert Markdown documents to other formats</h3><br />
<br />
For more information <a href="http://yihui.name/knitr/demo/pandoc/">click here</a><br />
<br />
The pandoc() function is included in the knitr package (version 1.2) and it could be used to convert Markdown documents to other formats such as Latex/PDF, HTML and Word (. Doc,. Docx).<br />
<br />
To install pandoc <a href="http://johnmacfarlane.net/pandoc/index.html">click-here</a><br />
<br />
<strong><span style="color:blue;">How to use pandoc()</span></strong><br />
<br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&amp;nbsp;
<span style="color: #0000FF; font-weight: bold;">library</span><span style="color: #080;">&amp;#40;</span>knitr<span style="color: #080;">&amp;#41;</span>
pandoc<span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">'foo.md'</span>, <span style="color: #0000FF; font-weight: bold;">format</span><span style="color: #080;">=</span><span style="color: #ff0000;">'html'</span><span style="color: #080;">&amp;#41;</span>  <span style="color: #228B22;"># HTML</span>
pandoc<span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">'foo.md'</span>, <span style="color: #0000FF; font-weight: bold;">format</span><span style="color: #080;">=</span><span style="color: #ff0000;">'latex'</span><span style="color: #080;">&amp;#41;</span> <span style="color: #228B22;"># LaTeX/PDF</span>
pandoc<span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">'foo.md'</span>, <span style="color: #0000FF; font-weight: bold;">format</span><span style="color: #080;">=</span><span style="color: #ff0000;">'docx'</span><span style="color: #080;">&amp;#41;</span>  <span style="color: #228B22;"># MS Word</span>
pandoc<span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">'foo.md'</span>, <span style="color: #0000FF; font-weight: bold;">format</span><span style="color: #080;">=</span><span style="color: #ff0000;">'odt'</span><span style="color: #080;">&amp;#41;</span>   <span style="color: #228B22;"># OpenDocument</span>
&amp;nbsp;</pre></pre></div></div><br />
<br />
<br />
<h3 class="formatter-title">Create a Word document with R2DOCX</h3><br />
<br />
Using R2DOCX package you can, create easly a Word document from a template or not and add a plot or table to the document. <br />
<br />
A comprehensive documentation is available <a href="https://github.com/davidgohel/R2DOCX">here</a><br />
An example is shown <a href="http://blog.revolutionanalytics.com/2013/06/create-word-documents-from-r-with-r2docx.html">here</a><br />
<br />
<br /><h4 class="formatter-title">Installation</h4><br /><br />
<br />
<strong>Compatibility R >= 3.0</strong><br />
<br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&amp;nbsp;
<span style="color: #0000FF; font-weight: bold;">install.<span style="">packages</span></span><span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">"devtools"</span><span style="color: #080;">&amp;#41;</span>
devtools<span style="color: #080;">::</span><span style="">install_github</span><span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">'R2DOC'</span>, <span style="color: #ff0000;">'davidgohel'</span><span style="color: #080;">&amp;#41;</span>
devtools<span style="color: #080;">::</span><span style="">install_github</span><span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">'R2DOCX'</span>, <span style="color: #ff0000;">'davidgohel'</span><span style="color: #080;">&amp;#41;</span>
&amp;nbsp;</pre></pre></div></div><br />
<br />
<strong><span style="color:blue;">For Mac users :</span></strong><br />
<br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&amp;nbsp;
<span style="color: #0000FF; font-weight: bold;">Sys.<span style="">setenv</span></span><span style="color: #080;">&amp;#40;</span>NOAWT<span style="color: #080;">=</span><span style="color: #ff0000;">1</span><span style="color: #080;">&amp;#41;</span> <span style="color: #228B22;">#prevents usage of awt.[http://cran.r-project.org/doc/manuals/r-devel/R-admin.html#Java-_0028OS-X_0029]</span>
<span style="color: #0000FF; font-weight: bold;">install.<span style="">packages</span></span><span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">"devtools"</span><span style="color: #080;">&amp;#41;</span>
devtools<span style="color: #080;">::</span><span style="">install_github</span><span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">'R2DOC'</span>, <span style="color: #ff0000;">'davidgohel'</span><span style="color: #080;">&amp;#41;</span>
devtools<span style="color: #080;">::</span><span style="">install_github</span><span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">'R2DOCX'</span>, <span style="color: #ff0000;">'davidgohel'</span><span style="color: #080;">&amp;#41;</span>
&amp;nbsp;</pre></pre></div></div><br />
<br />
<br />
<br /><h4 class="formatter-title">The available functions</h4><br /><br />
<ul class="formatter-ul">
	<li class="formatter-li"><strong>addPlot</strong> for adding plots.
	</li><li class="formatter-li"><strong>addParagraph</strong> for adding paragraphs of text.
	</li><li class="formatter-li"><strong>addTable</strong> for adding tables.
  	</li><li class="formatter-li"><strong>addHeader</strong> for adding headers.
	</li><li class="formatter-li"><strong>addTOC</strong> for adding tables of contents.
	</li><li class="formatter-li"><strong>addPageBreak</strong> for adding a page break.
	</li><li class="formatter-li"><strong>addLineBreak</strong> for adding a line break.
	</li><li class="formatter-li"><strong>replaceText</strong> for text replacement.<br />
</li></ul><br />
<br />
<br /><h4 class="formatter-title">Your first document</h4><br /><br />
<br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&amp;nbsp;
<span style="color: #0000FF; font-weight: bold;">Sys.<span style="">setenv</span></span><span style="color: #080;">&amp;#40;</span>NOAWT<span style="color: #080;">=</span><span style="color: #ff0000;">1</span><span style="color: #080;">&amp;#41;</span> <span style="color: #228B22;">#prevents usage of awt - required on Mac</span>
<span style="color: #0000FF; font-weight: bold;">library</span><span style="color: #080;">&amp;#40;</span>R2DOCX<span style="color: #080;">&amp;#41;</span>
&amp;nbsp;
<span style="color: #228B22;"># The file to create</span>
docx.<span style="">file</span> <span style="color: #080;"><-</span> <span style="color: #ff0000;">"document.docx"</span>
<span style="color: #228B22;"># Docx object to manipulate</span>
doc <span style="color: #080;"><-</span> <span style="color: #0000FF; font-weight: bold;">new</span> <span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">"Docx"</span>, <span style="color: #0000FF; font-weight: bold;">title</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"My example"</span> <span style="color: #080;">&amp;#41;</span>
<span style="color: #228B22;">#Add a table</span>
doc <span style="color: #080;">=</span> addTable<span style="color: #080;">&amp;#40;</span> doc, <span style="color: #CC9900; font-weight: bold;">iris</span><span style="color: #080;">&amp;#91;</span><span style="color: #ff0000;">1</span><span style="color: #080;">:</span><span style="color: #ff0000;">10</span>,<span style="color: #080;">&amp;#93;</span> <span style="color: #080;">&amp;#41;</span>
<span style="color: #228B22;"># Add atext</span>
doc <span style="color: #080;"><-</span> addParagraph<span style="color: #080;">&amp;#40;</span> doc, value <span style="color: #080;">=</span> <span style="color: #ff0000;">"Hello World!"</span>, stylename <span style="color: #080;">=</span> <span style="color: #ff0000;">"Normal"</span> <span style="color: #080;">&amp;#41;</span>
<span style="color: #228B22;"># Add a plot</span>
doc <span style="color: #080;">=</span> addPlot<span style="color: #080;">&amp;#40;</span> doc, <span style="color: #0000FF; font-weight: bold;">function</span><span style="color: #080;">&amp;#40;</span><span style="color: #080;">&amp;#41;</span> <span style="color: #0000FF; font-weight: bold;">plot</span><span style="color: #080;">&amp;#40;</span> <span style="color: #0000FF; font-weight: bold;">rnorm</span><span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">10</span><span style="color: #080;">&amp;#41;</span>, <span style="color: #0000FF; font-weight: bold;">rnorm</span><span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">10</span><span style="color: #080;">&amp;#41;</span> <span style="color: #080;">&amp;#41;</span>
               , width <span style="color: #080;">=</span> <span style="color: #ff0000;">10</span>, height <span style="color: #080;">=</span> <span style="color: #ff0000;">8</span>
<span style="color: #080;">&amp;#41;</span>
<span style="color: #228B22;"># Write the file</span>
writeDoc<span style="color: #080;">&amp;#40;</span> doc, docx.<span style="">file</span> <span style="color: #080;">&amp;#41;</span>
&amp;nbsp;</pre></pre></div></div><br />
<br />
<br /><h4 class="formatter-title">Create a Word document from template</h4><br /><br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&amp;nbsp;
<span style="color: #228B22;"># Document to create</span>
docx.<span style="">file</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"document.docx"</span>
<span style="color: #228B22;"># Word document used as template</span>
template.<span style="">file</span> <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">file.<span style="">path</span></span><span style="color: #080;">&amp;#40;</span> find.<span style="">package</span><span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">"R2DOCX"</span><span style="color: #080;">&amp;#41;</span>, <span style="color: #ff0000;">"templates/TEMPLATE_01.docx"</span>, fsep <span style="color: #080;">=</span> <span style="color: #ff0000;">"/"</span> <span style="color: #080;">&amp;#41;</span>
<span style="color: #228B22;"># Create an object</span>
doc <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">new</span><span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">"Docx"</span>
	, <span style="color: #0000FF; font-weight: bold;">title</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"My example"</span> 
	, basefile <span style="color: #080;">=</span> template.<span style="">file</span>
<span style="color: #080;">&amp;#41;</span>
<span style="color: #228B22;"># 2 keywords exist in the base file- Let's replace it</span>
doc <span style="color: #080;">=</span> replaceText<span style="color: #080;">&amp;#40;</span> doc, pattern <span style="color: #080;">=</span> <span style="color: #ff0000;">"AUTHOR"</span>, replacement <span style="color: #080;">=</span> <span style="color: #ff0000;">"John Doe"</span> <span style="color: #080;">&amp;#41;</span>
doc <span style="color: #080;">=</span> replaceText<span style="color: #080;">&amp;#40;</span> doc, pattern <span style="color: #080;">=</span> <span style="color: #ff0000;">"DATE"</span>, replacement <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">date</span><span style="color: #080;">&amp;#40;</span><span style="color: #080;">&amp;#41;</span> <span style="color: #080;">&amp;#41;</span>
&amp;nbsp;</pre></pre></div></div><br />
<br />
<br />
<br /><h4 class="formatter-title">Main title</h4><br /><br />
<br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&amp;nbsp;
<span style="color: #228B22;">#Main title</span>
<span style="color: #228B22;">#**************************************</span>
doc <span style="color: #080;">=</span> addParagraph<span style="color: #080;">&amp;#40;</span> doc, value <span style="color: #080;">=</span> <span style="color: #ff0000;">"Exemple"</span>, stylename <span style="color: #080;">=</span> <span style="color: #ff0000;">"TitleDoc"</span> <span style="color: #080;">&amp;#41;</span>
doc <span style="color: #080;">=</span> addPageBreak<span style="color: #080;">&amp;#40;</span> doc <span style="color: #080;">&amp;#41;</span> <span style="color: #228B22;">#saut de page</span>
&amp;nbsp;</pre></pre></div></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:500px; height:70px"><img src="https://www.sthda.com/english/upload/r2docx_titre.png"/></div></center>
<!-- END HTML --><br />
<br />
<br /><h4 class="formatter-title">Table of contents</h4><br /><br />
<br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&amp;nbsp;
<span style="color: #228B22;">#Table of content : TOC</span>
<span style="color: #228B22;">#**************************************</span>
<span style="color: #228B22;">#(user will be asked to update this TOC  when document will be opened the first time)</span>
doc <span style="color: #080;">=</span> addHeader<span style="color: #080;">&amp;#40;</span>doc, <span style="color: #ff0000;">"Table des matières"</span>, <span style="color: #ff0000;">1</span><span style="color: #080;">&amp;#41;</span><span style="color: #080;">;</span>
doc <span style="color: #080;">=</span> addTOC<span style="color: #080;">&amp;#40;</span>doc<span style="color: #080;">&amp;#41;</span>
doc <span style="color: #080;">=</span> addPageBreak<span style="color: #080;">&amp;#40;</span> doc <span style="color: #080;">&amp;#41;</span><span style="color: #228B22;">#saut de page</span>
&amp;nbsp;</pre></pre></div></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:520px; height:185px"><img src="https://www.sthda.com/english/upload/r2docx_toc.png"/></div></center>
<!-- END HTML --><br />
<br />
<br /><h4 class="formatter-title">Add texts (Normal et list)</h4><br /><br />
<br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&amp;nbsp;
<span style="color: #228B22;"># Add texts (Normal et list)</span>
<span style="color: #228B22;">#**************************************</span>
doc <span style="color: #080;">=</span> addHeader<span style="color: #080;">&amp;#40;</span>doc, <span style="color: #ff0000;">"Dataset presentation"</span>, <span style="color: #ff0000;">1</span><span style="color: #080;">&amp;#41;</span><span style="color: #080;">;</span>
<span style="color: #228B22;">#Normal style</span>
doc <span style="color: #080;">=</span> addParagraph<span style="color: #080;">&amp;#40;</span> doc, value <span style="color: #080;">=</span> <span style="color: #ff0000;">"Dataset 'measured.weights' is set of weights measurements collected on few people before savate training."</span>, stylename <span style="color: #080;">=</span> <span style="color: #ff0000;">"Normal"</span> <span style="color: #080;">&amp;#41;</span>
<span style="color: #228B22;">#Unordered list</span>
texts <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&amp;#40;</span> <span style="color: #ff0000;">"Column 'gender' is the subject gender."</span> 
           , <span style="color: #ff0000;">"Column 'id' is the unique subject identifier."</span> 
           , <span style="color: #ff0000;">"Column 'cat' is the subject weight category."</span> 
           , <span style="color: #ff0000;">"Column 'competitor' tells wether or not subject practice competition."</span> 
           , <span style="color: #ff0000;">"Column 'day' is the day of measurement."</span> 
           , <span style="color: #ff0000;">"Column 'weight' is the measured weight."</span> 
<span style="color: #080;">&amp;#41;</span>
doc <span style="color: #080;">=</span> addParagraph<span style="color: #080;">&amp;#40;</span> doc, value <span style="color: #080;">=</span> texts, stylename <span style="color: #080;">=</span> <span style="color: #ff0000;">"BulletList"</span> <span style="color: #080;">&amp;#41;</span>
&amp;nbsp;</pre></pre></div></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:515px; height:220px"><img src="https://www.sthda.com/english/upload/r2docx_texte.png"/></div></center>
<!-- END HTML --><br />
<br />
<br /><h4 class="formatter-title">Conditionnal formating of the text</h4><br /><br />
<br />
The <strong>addParagraph</strong> function is used to simply add text as shown above. It can also be used to replace text and to make conditional formatting in the document.<br />
<br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&amp;nbsp;
<span style="color: #228B22;"># template text</span>
x <span style="color: #080;">=</span> <span style="color: #ff0000;">"[animal] eats [food]."</span>
<span style="color: #228B22;"># define formatting properties for replacement text – see chapter "styles"</span>
textProp <span style="color: #080;">=</span> textProperties<span style="color: #080;">&amp;#40;</span> color <span style="color: #080;">=</span> <span style="color: #ff0000;">"blue"</span> <span style="color: #080;">&amp;#41;</span>
replacement.<span style="">styles</span> <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">list</span><span style="color: #080;">&amp;#40;</span> animal<span style="color: #080;">=</span> textProp, food<span style="color: #080;">=</span> textProp <span style="color: #080;">&amp;#41;</span>
<span style="color: #228B22;"># define replacement text</span>
replacements <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">list</span><span style="color: #080;">&amp;#40;</span> animal <span style="color: #080;">=</span> <span style="color: #ff0000;">"donkey"</span>, food <span style="color: #080;">=</span> <span style="color: #ff0000;">"grass"</span> <span style="color: #080;">&amp;#41;</span>
&amp;nbsp;
doc <span style="color: #080;"><-</span> addParagraph<span style="color: #080;">&amp;#40;</span> doc, value <span style="color: #080;">=</span> x, stylename <span style="color: #080;">=</span> <span style="color: #ff0000;">"Normal"</span>
                     , replacements <span style="color: #080;">=</span> replacements
                     , replacement.<span style="">styles</span> <span style="color: #080;">=</span> replacement.<span style="">styles</span>
<span style="color: #080;">&amp;#41;</span>
&amp;nbsp;</pre></pre></div></div><br />
..<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:218px; height:45px"><img src="https://www.sthda.com/english/upload/r2docx_replacement.png"/></div></center>
<!-- END HTML --><br />
<br />
<span class="notice"><strong>textProperties function</strong><br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">textProperties<span style="color: #080;">&amp;#40;</span>color <span style="color: #080;">=</span> <span style="color: #ff0000;">"black"</span>, font.<span style="">size</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">10</span>
		, font.<span style="">weight</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"normal"</span>, font.<span style="">style</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"normal"</span>
		, font.<span style="">family</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"Arial"</span> <span style="color: #080;">&amp;#41;</span></pre></pre></div></div><br />
<br />
<strong>color	</strong>: font color; <strong>font.size</strong>: size in pixel; <strong>font.weight</strong> : "normal" ou "bold"; <strong>font.style</strong>: "normal" ou "italic"; <strong>font.family</strong>: font family.<br />
</span><br />
<br /><h4 class="formatter-title">Add a table</h4><br /><br />
<br />
<strong><span style="color:blue;">Simple table: </span></strong><br />
<br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&amp;nbsp;
<span style="color: #228B22;"># Add a table</span>
<span style="color: #228B22;">#**************************************</span>
<span style="color: #228B22;"># Used data</span>
<span style="color: #0000FF; font-weight: bold;">data</span><span style="color: #080;">&amp;#40;</span> measured.<span style="">weights</span> <span style="color: #080;">&amp;#41;</span>
doc <span style="color: #080;">=</span> addHeader<span style="color: #080;">&amp;#40;</span>doc, <span style="color: #ff0000;">"Dataset"</span>, <span style="color: #ff0000;">1</span><span style="color: #080;">&amp;#41;</span><span style="color: #080;">;</span>
doc <span style="color: #080;">=</span> addHeader<span style="color: #080;">&amp;#40;</span>doc, <span style="color: #ff0000;">"Dataset first lines"</span>, <span style="color: #ff0000;">2</span><span style="color: #080;">&amp;#41;</span><span style="color: #080;">;</span>
<span style="color: #228B22;">#Simple table</span>
doc <span style="color: #080;">=</span> addTable<span style="color: #080;">&amp;#40;</span> doc
                , <span style="color: #0000FF; font-weight: bold;">data</span> <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">head</span><span style="color: #080;">&amp;#40;</span> measured.<span style="">weights</span>, n <span style="color: #080;">=</span> <span style="color: #ff0000;">10</span> <span style="color: #080;">&amp;#41;</span>
                , formats <span style="color: #080;">=</span> get.<span style="">light</span>.<span style="">formats</span><span style="color: #080;">&amp;#40;</span><span style="color: #080;">&amp;#41;</span>
<span style="color: #080;">&amp;#41;</span>
doc <span style="color: #080;">=</span> addLineBreak<span style="color: #080;">&amp;#40;</span> doc <span style="color: #080;">&amp;#41;</span><span style="color: #228B22;">#Line break</span>
&amp;nbsp;</pre></pre></div></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:511px; height:278px"><img src="https://www.sthda.com/english/upload/r2docx_table.png"/></div></center>
<!-- END HTML --><br />
<br />
<strong><span style="color:blue;">Rename table headers:</span></strong><br />
<br />
<strong>Before</strong> you rename:<br />
<br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&amp;nbsp;
doc <span style="color: #080;">=</span> addTable<span style="color: #080;">&amp;#40;</span> doc, <span style="color: #0000FF; font-weight: bold;">data</span> <span style="color: #080;">=</span> weights.<span style="">summary</span><span style="color: #080;">&amp;#41;</span>	
&amp;nbsp;</pre></pre></div></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:312px; height:147px"><img src="https://www.sthda.com/english/upload/r2docx_table2.png"/></div></center>
<!-- END HTML --><br />
<br />
<strong>After</strong> you rename :<br />
<br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&amp;nbsp;
doc <span style="color: #080;">=</span> addTable<span style="color: #080;">&amp;#40;</span> doc
		, <span style="color: #0000FF; font-weight: bold;">data</span> <span style="color: #080;">=</span> weights.<span style="">summary</span>
		, header.<span style="">labels</span> <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">list</span><span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">"id"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"Subject Identifier"</span>, <span style="color: #ff0000;">"avg.weight"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"Average Weight"</span>
				, <span style="color: #ff0000;">"regularity"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"Regularity"</span>, <span style="color: #ff0000;">"visit.n"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"Number of visits"</span>, <span style="color: #ff0000;">"last.day"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"Last visit"</span>
				<span style="color: #080;">&amp;#41;</span> <span style="color: #228B22;"># columns labels to display</span>
		<span style="color: #080;">&amp;#41;</span>
&amp;nbsp;</pre></pre></div></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:462px; height:182px"><img src="https://www.sthda.com/english/upload/r2docx_table_header_label.png"/></div></center>
<!-- END HTML --><br />
<br />
<strong><span style="color:blue;">Simple table customized with merged rows :</span></strong><br />
<br />
In the table below, the rows are merged on the 'day' column. The column 'gender' is colored by gender.<br />
<br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&amp;nbsp;
<span style="color: #228B22;"># simple addTable with row merging on 'day' column</span>
doc <span style="color: #080;">=</span> addHeader<span style="color: #080;">&amp;#40;</span>doc, <span style="color: #ff0000;">"Dataset last lines"</span>, <span style="color: #ff0000;">2</span><span style="color: #080;">&amp;#41;</span><span style="color: #080;">;</span>
sampledata <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">tail</span><span style="color: #080;">&amp;#40;</span> measured.<span style="">weights</span><span style="color: #080;">&amp;#91;</span> <span style="color: #0000FF; font-weight: bold;">order</span><span style="color: #080;">&amp;#40;</span>measured.<span style="">weights</span>$day<span style="color: #080;">&amp;#41;</span>, <span style="color: #080;">&amp;#93;</span>, n <span style="color: #080;">=</span> <span style="color: #ff0000;">20</span> <span style="color: #080;">&amp;#41;</span>
doc <span style="color: #080;">=</span> addTable<span style="color: #080;">&amp;#40;</span> doc
		, <span style="color: #0000FF; font-weight: bold;">data</span> <span style="color: #080;">=</span> sampledata
		, span.<span style="">columns</span> <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">"day"</span><span style="color: #080;">&amp;#41;</span>
		, col.<span style="">colors</span> <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">list</span><span style="color: #080;">&amp;#40;</span> <span style="color: #ff0000;">"gender"</span> <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">ifelse</span><span style="color: #080;">&amp;#40;</span> sampledata$gender <span style="color: #080;">==</span> <span style="color: #ff0000;">"male"</span> , <span style="color: #ff0000;">"#00c2ff"</span>, <span style="color: #ff0000;">"#ffcdd1"</span><span style="color: #080;">&amp;#41;</span> <span style="color: #080;">&amp;#41;</span>
<span style="color: #080;">&amp;#41;</span>
&amp;nbsp;</pre></pre></div></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:311px; height:453px"><img src="https://www.sthda.com/english/upload/r2docx_table_merge_row.png"/></div></center>
<!-- END HTML --><br />
<br />
<strong><span style="color:blue;">Customized table with grouped headers:</span></strong><br />
<br />
In this table, headers have been renamed, grouped headers are created, the type of columns is specified (%, integre, character, decimal, date). The values &amp;#8203;&amp;#8203;of the "Regularity" column were colored according to the value (gray if <0.5 and blue if> = 0.5).<br />
<br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&amp;nbsp;
<span style="color: #228B22;"># customized table</span>
doc <span style="color: #080;">=</span> addHeader<span style="color: #080;">&amp;#40;</span>doc, <span style="color: #ff0000;">"Dataset summary"</span>, <span style="color: #ff0000;">1</span><span style="color: #080;">&amp;#41;</span><span style="color: #080;">;</span>
doc <span style="color: #080;">=</span> addTable<span style="color: #080;">&amp;#40;</span> doc
		, <span style="color: #0000FF; font-weight: bold;">data</span> <span style="color: #080;">=</span> weights.<span style="">summary</span>
		, header.<span style="">labels</span> <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">list</span><span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">"id"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"Subject Identifier"</span>, <span style="color: #ff0000;">"avg.weight"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"Average Weight"</span>
				, <span style="color: #ff0000;">"regularity"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"Regularity"</span>, <span style="color: #ff0000;">"visit.n"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"Number of visits"</span>, <span style="color: #ff0000;">"last.day"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"Last visit"</span>
				<span style="color: #080;">&amp;#41;</span> <span style="color: #228B22;"># columns labels to display</span>
		, grouped.<span style="">cols</span><span style="color: #080;">=</span><span style="color: #0000FF; font-weight: bold;">list</span><span style="color: #080;">&amp;#40;</span> <span style="color: #ff0000;">"id"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"id"</span>
				, <span style="color: #ff0000;">"Summary"</span> <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&amp;#40;</span> <span style="color: #ff0000;">"avg.weight"</span>,  <span style="color: #ff0000;">"regularity"</span>, <span style="color: #ff0000;">"visit.n"</span>, <span style="color: #ff0000;">"last.day"</span> <span style="color: #080;">&amp;#41;</span> 
				<span style="color: #080;">&amp;#41;</span> <span style="color: #228B22;"># grouped headers line to add before headers line</span>
		, col.<span style="">types</span> <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">list</span><span style="color: #080;">&amp;#40;</span> <span style="color: #ff0000;">"id"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"character"</span>, <span style="color: #ff0000;">"avg.weight"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"double"</span>
				, <span style="color: #ff0000;">"regularity"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"percent"</span>, <span style="color: #ff0000;">"visit.n"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"integer"</span>
				, <span style="color: #ff0000;">"last.day"</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"date"</span> <span style="color: #080;">&amp;#41;</span> <span style="color: #228B22;"># reporting types of each columns </span>
		, col.<span style="">fontcolors</span> <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">list</span><span style="color: #080;">&amp;#40;</span> <span style="color: #ff0000;">"regularity"</span> <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">ifelse</span><span style="color: #080;">&amp;#40;</span> weights.<span style="">summary</span>$regularity <span style="color: #080;"><</span> <span style="color: #ff0000;">0.5</span> , <span style="color: #ff0000;">"gray"</span>, <span style="color: #ff0000;">"blue"</span><span style="color: #080;">&amp;#41;</span> <span style="color: #080;">&amp;#41;</span> <span style="color: #228B22;"># customized font colors for column "regularity"</span>
<span style="color: #080;">&amp;#41;</span>
&amp;nbsp;
&amp;nbsp;</pre></pre></div></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:530px; height:266px"><img src="https://www.sthda.com/english/upload/r2docx_table_customized.png"/></div></center>
<!-- END HTML --><br />
<br />
<br /><h4 class="formatter-title">Add a plot</h4><br /><br />
<br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&amp;nbsp;
<span style="color: #228B22;"># Add a plot</span>
<span style="color: #228B22;">#**************************************</span>
doc <span style="color: #080;">=</span> addPageBreak<span style="color: #080;">&amp;#40;</span> doc <span style="color: #080;">&amp;#41;</span>
doc <span style="color: #080;">=</span> addHeader<span style="color: #080;">&amp;#40;</span>doc, <span style="color: #ff0000;">"Graphics"</span>, <span style="color: #ff0000;">1</span><span style="color: #080;">&amp;#41;</span><span style="color: #080;">;</span>
doc <span style="color: #080;">=</span> addPlot<span style="color: #080;">&amp;#40;</span> doc,
               <span style="color: #0000FF; font-weight: bold;">function</span><span style="color: #080;">&amp;#40;</span><span style="color: #080;">&amp;#41;</span> <span style="color: #0000FF; font-weight: bold;">boxplot</span><span style="color: #080;">&amp;#40;</span>measured.<span style="">weights</span>$weight ~ measured.<span style="">weights</span>$id,
                                  xlab <span style="color: #080;">=</span> <span style="color: #ff0000;">"Subjects"</span>, ylab <span style="color: #080;">=</span> <span style="color: #ff0000;">"Weights"</span> , <span style="color: #0000FF; font-weight: bold;">col</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"#0088cc"</span>,
                                  <span style="color: #0000FF; font-weight: bold;">legend</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"My boxplot"</span><span style="color: #080;">&amp;#41;</span>,
               width<span style="color: #080;">=</span><span style="color: #ff0000;">7</span>, height<span style="color: #080;">=</span><span style="color: #ff0000;">7</span>
              <span style="color: #080;">&amp;#41;</span>
&amp;nbsp;</pre></pre></div></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:516px; height:534px"><img src="https://www.sthda.com/english/upload/r2docx_plot.png"/></div></center>
<!-- END HTML --><br />
<br />
<br /><h4 class="formatter-title">Text replacement</h4><br /><br />
<br />
To replace the keyword "AUTHOR" ,in the word document, with "Pearson":<br />
<br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&amp;nbsp;
doc <span style="color: #080;">=</span> replaceText<span style="color: #080;">&amp;#40;</span> doc, <span style="color: #ff0000;">"AUTHOR"</span>, <span style="color: #ff0000;">"Pearson"</span><span style="color: #080;">&amp;#41;</span>
&amp;nbsp;</pre></pre></div></div><br />
<br />
<br /><h4 class="formatter-title">Heading styles available in your document</h4><br /><br />
<br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&amp;nbsp;
doc <span style="color: #080;"><-</span> <span style="color: #0000FF; font-weight: bold;">new</span><span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">"Docx"</span>, <span style="color: #0000FF; font-weight: bold;">title</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"My example"</span> <span style="color: #080;">&amp;#41;</span>
styles<span style="color: #080;">&amp;#40;</span> doc <span style="color: #080;">&amp;#41;</span>
<span style="color: #228B22;"># [1] "Normal"                  "Titre1"                  "Titre2"                 </span>
<span style="color: #228B22;"># [4] "Titre3"                  "Titre4"                  "Titre5"                 </span>
<span style="color: #228B22;"># [7] "Titre6"                  "Titre7"                  "Titre8"                 </span>
<span style="color: #228B22;">#[10] "Titre9"                  "Policepardfaut"          "TableauNormal"          </span>
<span style="color: #228B22;"># ...</span>
doc <span style="color: #080;"><-</span> setHeaderStyle<span style="color: #080;">&amp;#40;</span>doc, stylenames <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">"Titre1"</span>, <span style="color: #ff0000;">"Titre2"</span>, <span style="color: #ff0000;">"Titre3"</span>, <span style="color: #ff0000;">"Titre4"</span>, <span style="color: #ff0000;">"Titre5"</span>, <span style="color: #ff0000;">"Titre6"</span>, <span style="color: #ff0000;">"Titre7"</span>, <span style="color: #ff0000;">"Titre8"</span>, <span style="color: #ff0000;">"Titre9"</span> <span style="color: #080;">&amp;#41;</span> <span style="color: #080;">&amp;#41;</span> 
doc <span style="color: #080;">=</span> addHeader<span style="color: #080;">&amp;#40;</span> doc, <span style="color: #ff0000;">"title 1"</span>, <span style="color: #ff0000;">1</span> <span style="color: #080;">&amp;#41;</span>
&amp;nbsp;</pre></pre></div></div><br />
<br />
<br />
<br /><h4 class="formatter-title">A full word document</h4><br /><br />
<br />
<span class="success">The full script used to create this word document can be downloaded here: <a href="https://www.sthda.com/english/upload/r2docx.r">R2DOCX.r</a></span><br />
<br />
<!-- START HTML -->
<a href="https://www.sthda.com/english/upload/r2docx_word.pdf" class="embed" >A full word document</a>
<!-- END HTML -->]]></description>
			<pubDate>Fri, 19 Jul 2013 01:04:01 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[Create an animated .gif image with R and ImageMagick]]></title>
			<link>https://www.sthda.com/english/articles/2-r/6-create-an-animated-gif-image-with-r-and-imagemagick/</link>
			<guid>https://www.sthda.com/english/articles/2-r/6-create-an-animated-gif-image-with-r-and-imagemagick/</guid>
			<description><![CDATA[<p class="float-left"><img src="https://www.sthda.com/english/upload/animated_image_with_r_and_imagemagick2.gif" alt="" class="valign_" /></p><br />
The purpose of this tutorial is to show you the steps to create an animated gif image with R and ImageMagick. You must first install  <a href="http://www.imagemagick.org/">ImageMagick</a>.<br />
<br />
<!-- START HTML -->
<div style="clear:both"></div>
<!-- END HTML --><br />
<br />
<span class="notice"><br />
It is also possible to create animated .gif images using only R, through write.gif() in  <a href="http://cran.r-project.org/web/packages/caTools/index.html">caTools </a>  package.<br />
</span><br />
<br />
<span class="warning"><br />
The R code described in this tutotriel were tested on Mac OS X 10.6.8 with R 2.13<br />
</span><br />
<br />
<br />
<br />
<br />
<h3 class="formatter-title">Example 1: Create a countdown </h3><br />
<br />
<br /><h4 class="formatter-title">R code</h4><br /><br />
<br />
The countdown is from 10 to 1. We will create it in 4 steps.<br />
<br />
1 - Creating a clean working directory called 'examples'.<br />
2 - Creating .png images, each containing a number (10 to 1).<br />
3 - Creating a single image. Gif using ImageMagick<br />
4 - delete png files that are no longer needed <br />
<br />
<strong>The corresponding R code is shown below: </strong><br />
<br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&amp;nbsp;
<span style="color: #228B22;">#crearing working directory</span>
<span style="color: #0000FF; font-weight: bold;">dir.<span style="">create</span></span><span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">"examples"</span><span style="color: #080;">&amp;#41;</span>
<span style="color: #0000FF; font-weight: bold;">setwd</span><span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">"examples"</span><span style="color: #080;">&amp;#41;</span> 
&amp;nbsp;
<span style="color: #228B22;">#Creating countdown .png files from 10 to "GO!"</span>
<span style="color: #0000FF; font-weight: bold;">png</span><span style="color: #080;">&amp;#40;</span><span style="color: #0000FF; font-weight: bold;">file</span><span style="color: #080;">=</span><span style="color: #ff0000;">"example%02d.png"</span>, width<span style="color: #080;">=</span><span style="color: #ff0000;">200</span>, height<span style="color: #080;">=</span><span style="color: #ff0000;">200</span><span style="color: #080;">&amp;#41;</span>
  <span style="color: #0000FF; font-weight: bold;">for</span> <span style="color: #080;">&amp;#40;</span>i <span style="color: #0000FF; font-weight: bold;">in</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">10</span><span style="color: #080;">:</span><span style="color: #ff0000;">1</span>, <span style="color: #ff0000;">"G0!"</span><span style="color: #080;">&amp;#41;</span><span style="color: #080;">&amp;#41;</span><span style="color: #080;">&amp;#123;</span>
    <span style="color: #0000FF; font-weight: bold;">plot.<span style="">new</span></span><span style="color: #080;">&amp;#40;</span><span style="color: #080;">&amp;#41;</span>
    <span style="color: #0000FF; font-weight: bold;">text</span><span style="color: #080;">&amp;#40;</span>.5, .5, i, cex <span style="color: #080;">=</span> <span style="color: #ff0000;">6</span><span style="color: #080;">&amp;#41;</span>
  <span style="color: #080;">&amp;#125;</span>
<span style="color: #0000FF; font-weight: bold;">dev.<span style="">off</span></span><span style="color: #080;">&amp;#40;</span><span style="color: #080;">&amp;#41;</span>
&amp;nbsp;
<span style="color: #228B22;"># Converting .png files in one .gif image using ImageMagick</span>
<span style="color: #0000FF; font-weight: bold;">system</span><span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">"/opt/local/bin/convert -delay 80 *.png example_1.gif"</span><span style="color: #080;">&amp;#41;</span>
<span style="color: #228B22;"># Remove .png files from working directory</span>
<span style="color: #0000FF; font-weight: bold;">file.<span style="">remove</span></span><span style="color: #080;">&amp;#40;</span><span style="color: #0000FF; font-weight: bold;">list.<span style="">files</span></span><span style="color: #080;">&amp;#40;</span>pattern<span style="color: #080;">=</span><span style="color: #ff0000;">".png"</span><span style="color: #080;">&amp;#41;</span><span style="color: #080;">&amp;#41;</span>
&amp;nbsp;</pre></pre></div></div><br />
<br />
<span class="success"><br />
<br />
1 - The <strong>system()</strong> function executs the conversion command as in a terminal. I use the absolute path to the convert command. In my case it is: /opt/ local/bin/convert. In some cases the command system("convert -delay 80 *. Example_1.gif png") works.<br />
<br />
2 - the flag -delay is the time between two images (the speed of the animation).<br />
3-The part "%02d" in the filename increment automatically the .png file names<br />
</span><br />
<br />
<br /><h4 class="formatter-title">Result</h4><br /><br />
<br />
<strong><span style="color:blue;">The result is :</span></strong><br />
<br />
 <img src="https://www.sthda.com/english/upload/animated_gif_with_r_and_imagemagick.gif" alt="" class="valign_" /><br />
<br />
<br />
<br />
<h3 class="formatter-title">Example 2: Creating a 3D animated graphic</h3><br />
<br />
We will create a 3D surface plot to visualize a linear model using <strong>lattice</strong> package. 3D graphics can be created also with <strong>rgl</strong> package.<br />
<br />
<br />
<br />
<br /><h4 class="formatter-title">R code</h4><br /><br />
<br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&amp;nbsp;
<span style="color: #0000FF; font-weight: bold;">library</span><span style="color: #080;">&amp;#40;</span>lattice<span style="color: #080;">&amp;#41;</span>
b0 <span style="color: #080;"><-</span> <span style="color: #ff0000;">10</span>
b1 <span style="color: #080;"><-</span> .5
b2 <span style="color: #080;"><-</span> .3
g <span style="color: #080;"><-</span> <span style="color: #0000FF; font-weight: bold;">expand.<span style="">grid</span></span><span style="color: #080;">&amp;#40;</span>x <span style="color: #080;">=</span> <span style="color: #ff0000;">1</span><span style="color: #080;">:</span><span style="color: #ff0000;">20</span>, y <span style="color: #080;">=</span> <span style="color: #ff0000;">1</span><span style="color: #080;">:</span><span style="color: #ff0000;">20</span><span style="color: #080;">&amp;#41;</span>
g$z <span style="color: #080;"><-</span> b0 <span style="color: #080;">+</span> b1<span style="color: #080;">*</span>g$x <span style="color: #080;">+</span> b2<span style="color: #080;">*</span>g$y
&amp;nbsp;
<span style="color: #0000FF; font-weight: bold;">png</span><span style="color: #080;">&amp;#40;</span><span style="color: #0000FF; font-weight: bold;">file</span><span style="color: #080;">=</span><span style="color: #ff0000;">"example%03d.png"</span>, width<span style="color: #080;">=</span><span style="color: #ff0000;">300</span>, heigh<span style="color: #080;">=</span><span style="color: #ff0000;">300</span><span style="color: #080;">&amp;#41;</span>
  <span style="color: #0000FF; font-weight: bold;">for</span> <span style="color: #080;">&amp;#40;</span>i <span style="color: #0000FF; font-weight: bold;">in</span> <span style="color: #0000FF; font-weight: bold;">seq</span><span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">0</span>, <span style="color: #ff0000;">350</span> , <span style="color: #ff0000;">10</span><span style="color: #080;">&amp;#41;</span><span style="color: #080;">&amp;#41;</span><span style="color: #080;">&amp;#123;</span>
    <span style="color: #0000FF; font-weight: bold;">print</span><span style="color: #080;">&amp;#40;</span>wireframe<span style="color: #080;">&amp;#40;</span>z ~ x <span style="color: #080;">*</span> y, <span style="color: #0000FF; font-weight: bold;">data</span> <span style="color: #080;">=</span> g,
              <span style="color: #0000FF; font-weight: bold;">screen</span> <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">list</span><span style="color: #080;">&amp;#40;</span>z <span style="color: #080;">=</span> i, x <span style="color: #080;">=</span> <span style="color: #080;">-</span><span style="color: #ff0000;">60</span><span style="color: #080;">&amp;#41;</span><span style="color: #080;">&amp;#41;</span><span style="color: #080;">&amp;#41;</span>
  <span style="color: #080;">&amp;#125;</span>
<span style="color: #0000FF; font-weight: bold;">dev.<span style="">off</span></span><span style="color: #080;">&amp;#40;</span><span style="color: #080;">&amp;#41;</span>
&amp;nbsp;
<span style="color: #228B22;"># converting .png file in .gif using ImageMagick</span>
<span style="color: #0000FF; font-weight: bold;">system</span><span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">"/opt/local/bin/convert -delay 40 *.png example_2_reduced.gif"</span><span style="color: #080;">&amp;#41;</span>
&amp;nbsp;
<span style="color: #228B22;"># Remove .png file</span>
<span style="color: #0000FF; font-weight: bold;">file.<span style="">remove</span></span><span style="color: #080;">&amp;#40;</span><span style="color: #0000FF; font-weight: bold;">list.<span style="">files</span></span><span style="color: #080;">&amp;#40;</span>pattern<span style="color: #080;">=</span><span style="color: #ff0000;">".png"</span><span style="color: #080;">&amp;#41;</span><span style="color: #080;">&amp;#41;</span>
&amp;nbsp;
&amp;nbsp;</pre></pre></div></div><br />
<br />
<br />
<br /><h4 class="formatter-title">Result</h4><br /><br />
<br />
<img src="https://www.sthda.com/english/upload/animated_image_with_r_and_imagemagick2.gif" alt="" class="valign_" /><br />
<br />
<br />
<em><strong>Source :</strong><br />
<a href="http://ryouready.wordpress.com/2010/11/21/animate-gif-images-in-r-imagemagick/">http://ryouready.wordpress.com/2010/11/21/animate-gif-images-in-r-imagemagick/</a></em>]]></description>
			<pubDate>Thu, 09 Aug 2012 21:10:01 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[Loading data in R from internet]]></title>
			<link>https://www.sthda.com/english/articles/2-r/5-loading-data-in-r-from-internet/</link>
			<guid>https://www.sthda.com/english/articles/2-r/5-loading-data-in-r-from-internet/</guid>
			<description><![CDATA[<h3 class="formatter-title">Importing a *. txt file from the Internet</h3><br />
<br />
Import decathlon.txt file from STHDA web site:  :<br />
<br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&amp;nbsp;
<span style="color: #0000FF; font-weight: bold;">data</span><span style="color: #080;">=</span><span style="color: #0000FF; font-weight: bold;">read.<span style="">table</span></span><span style="color: #080;">&amp;#40;</span><span style="color: #0000FF; font-weight: bold;">file</span><span style="color: #080;">=</span><span style="color: #ff0000;">"https://www.sthda.com/upload/decathlon.txt"</span>, 
                       header<span style="color: #080;">=</span><span style="color: #0000FF; font-weight: bold;">T</span>, <span style="color: #0000FF; font-weight: bold;">row.<span style="">names</span></span><span style="color: #080;">=</span><span style="color: #ff0000;">1</span>, sep<span style="color: #080;">=</span><span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\t</span>"</span><span style="color: #080;">&amp;#41;</span> <span style="color: #228B22;">#Importation des données</span>
<span style="color: #0000FF; font-weight: bold;">print</span><span style="color: #080;">&amp;#40;</span><span style="color: #0000FF; font-weight: bold;">data</span><span style="color: #080;">&amp;#41;</span> <span style="color: #228B22;"># Print the data</span>
&amp;nbsp;</pre></pre></div></div><br />
<br />
<br />
<h3 class="formatter-title">Load .rdata file from internet</h3><br />
<br />
To do this, you must first create a connection using the R <strong><span style="color:blue;">url</span></strong> function. You can then load the connexion.<br />
<br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&amp;nbsp;
con<span style="color: #080;"><-</span><span style="color: #0000FF; font-weight: bold;">url</span><span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">'https://www.sthda.com/upload/decathlon.rdata'</span><span style="color: #080;">&amp;#41;</span> <span style="color: #228B22;"># Create connexion</span>
<span style="color: #0000FF; font-weight: bold;">load</span><span style="color: #080;">&amp;#40;</span>con<span style="color: #080;">&amp;#41;</span> <span style="color: #228B22;">#Load the data</span>
<span style="color: #0000FF; font-weight: bold;">close</span><span style="color: #080;">&amp;#40;</span>con<span style="color: #080;">&amp;#41;</span> <span style="color: #228B22;">#close connexion</span>
<span style="color: #0000FF; font-weight: bold;">print</span><span style="color: #080;">&amp;#40;</span>d<span style="color: #080;">&amp;#41;</span> <span style="color: #228B22;"># Print the data</span>
&amp;nbsp;</pre></pre></div></div><br />
<br />
<h3 class="formatter-title">Download file from internet using R</h3><br />
<br />
To download a file from the Internet with R, we can use the function : <span style="color:blue;">download.file</span> :<br />
<br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&amp;nbsp;
<span style="color: #0000FF; font-weight: bold;">download.<span style="">file</span></span><span style="color: #080;">&amp;#40;</span><span style="color: #0000FF; font-weight: bold;">url</span><span style="color: #080;">=</span><span style="color: #ff0000;">'https://www.sthda.com/upload/decathlon.rdata'</span>, 
                         destfile <span style="color: #080;">=</span><span style="color: #ff0000;">"decathlon.rdata"</span><span style="color: #080;">&amp;#41;</span>
&amp;nbsp;</pre></pre></div></div><br />
<br />
The file will be downloaded and saved in the current directory with the name decathlon.rdata]]></description>
			<pubDate>Sat, 04 Aug 2012 18:33:01 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[XLConnect : read, write and manipulate Microsoft Excel files from within R]]></title>
			<link>https://www.sthda.com/english/articles/2-r/4-xlconnect-read-write-and-manipulate-microsoft-excel-files-from-within-r/</link>
			<guid>https://www.sthda.com/english/articles/2-r/4-xlconnect-read-write-and-manipulate-microsoft-excel-files-from-within-r/</guid>
			<description><![CDATA[<span style="color:blue;">XLConnect is a package that allows for reading, writing and manipulating Microsoft Excel files from within<br />
R. </span><br />
<br />
It does not require any installation of Microsoft Excel or any other special drivers to be able to read &amp; write Excel files. The only requirement is a recent version of a Java Runtime Environment (JRE).<br />
<br />
In order to get started have a look at the <a href="http://cran.r-project.org/web/packages/XLConnect/vignettes/XLConnect.pdf">package vignette</a>, the numerous demos available via demo(package = "XLConnect") or browse through the comprehensive<a href="http://cran.r-project.org/web/packages/XLConnect/XLConnect.pdf"> reference manual</a>.<br />
<br />
<h3 class="formatter-title">Installation</h3><br />
<br />
<h4 class="formatter-title">Software Requirements</h4><br />
<ul class="formatter-ul">
	<li class="formatter-li">R, version 2.10.0 or higher
	</li><li class="formatter-li">Java Runtime Environment (JRE), version 6.0 or higher<br />
</li></ul><br />
<br />
<span class="notice"><br />
if you don't have JRE on your computer, you have to install it :<br />
on linux /ubuntu use this command : apt-get install openjdk-6-jdk<br />
</span><br />
<br />
<h4 class="formatter-title">Package Installation</h4><br />
<br />
XLConnect can be easily installed by using the install.packages() command in your R session:<br />
<br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;"><span style="color: #0000FF; font-weight: bold;">install.<span style="">packages</span></span><span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">"XLConnect"</span><span style="color: #080;">&amp;#41;</span></pre></pre></div></div><br />
<br />
<h3 class="formatter-title">Writing Excel files</h3><br />
<br />
<h4 class="formatter-title">Basic functions</h4><br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&amp;nbsp;
<span style="color: #228B22;">#loading the package</span>
<span style="color: #0000FF; font-weight: bold;">require</span><span style="color: #080;">&amp;#40;</span>XLConnect<span style="color: #080;">&amp;#41;</span>
&amp;nbsp;
<span style="color: #228B22;">#creating an Excel workbook. Both .xls and .xlsx file formats can be used.</span>
wb <span style="color: #080;"><-</span> loadWorkbook<span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">"XLConnectExample1.xlsx"</span>, create <span style="color: #080;">=</span> TRUE<span style="color: #080;">&amp;#41;</span>
&amp;nbsp;
<span style="color: #228B22;">#creating sheets within an Excel workbook</span>
createSheet<span style="color: #080;">&amp;#40;</span>wb, name <span style="color: #080;">=</span> <span style="color: #ff0000;">"chickSheet"</span><span style="color: #080;">&amp;#41;</span>
&amp;nbsp;
<span style="color: #228B22;">#writing into sheets within an Excel workbook : </span>
<span style="color: #228B22;">#writing ChickWeight data frame into chickSheet</span>
writeWorksheet<span style="color: #080;">&amp;#40;</span>wb, <span style="color: #CC9900; font-weight: bold;">ChickWeight</span>, sheet <span style="color: #080;">=</span> <span style="color: #ff0000;">"chickSheet"</span>, startRow <span style="color: #080;">=</span> <span style="color: #ff0000;">3</span>, startCol <span style="color: #080;">=</span> <span style="color: #ff0000;">4</span><span style="color: #080;">&amp;#41;</span>
&amp;nbsp;
<span style="color: #228B22;">#saving a workbook to an Excel file :</span>
<span style="color: #228B22;">#saves a workbook to the corresponding Excel file and writes the file to disk.</span>
saveWorkbook<span style="color: #080;">&amp;#40;</span>wb<span style="color: #080;">&amp;#41;</span>
&amp;nbsp;</pre></pre></div></div><br />
<br />
<br />
<p style="text-align:center"><img src="https://www.sthda.com/english/upload/write_execel_with_r_1.png" alt="" /></p><br />
<br />
<br />
<h4 class="formatter-title">Writing sheet with one call</h4><br />
<br />
The four lines of code presented in the previous example can be replaced with a single call of the<br />
<strong><span style="color:blue;">writeWorksheetToFile()</span></strong> function:<br />
<br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&amp;nbsp;
<span style="color: #0000FF; font-weight: bold;">require</span><span style="color: #080;">&amp;#40;</span>XLConnect<span style="color: #080;">&amp;#41;</span>
writeWorksheetToFile<span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">"XLConnectExample2.xlsx"</span>, <span style="color: #0000FF; font-weight: bold;">data</span> <span style="color: #080;">=</span> <span style="color: #CC9900; font-weight: bold;">ChickWeight</span>, 
                                 sheet <span style="color: #080;">=</span> <span style="color: #ff0000;">"chickSheet"</span>, startRow <span style="color: #080;">=</span> <span style="color: #ff0000;">3</span>, startCol <span style="color: #080;">=</span> <span style="color: #ff0000;">4</span><span style="color: #080;">&amp;#41;</span>
&amp;nbsp;</pre></pre></div></div><br />
<br />
<span class="notice"><strong><span style="color:blue;">writeWorksheetToFile()</span></strong> loads the workbook, creates the sheet and finally saves the workbook. When you only need to write one sheet into an Excel file, this is probably the better choice. If you need to write more sheets, however, using the functions presented in the previous example will be more efficient. This is because calling <span style="color:blue;">writeWorksheetToFile()</span> multiple times will open, write and close the Excel file with each call. Using the functions in the first example will, in contrast, allow you to open the workbook, do multiple operations on it and only then close it.</span><br />
<br />
<br />
<h3 class="formatter-title">Reading from an Excel sheet</h3><br />
<br />
For this purpose, we will use the file created in the above example. We set the endRow argument to 10, to limit the result. We set the rest of arguments specifying boundaries as 0, so that they are automatically determined.<br />
Please note, that alternatively to setting the sheet argument to the name of the sheet we want to read from, "chickSheet", we could also specify it with the sheet index, as sheet = 1.<br />
<br />
<br />
<h4 class="formatter-title">Basic functions</h4><br />
<br />
<br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&amp;nbsp;
<span style="color: #228B22;">#loading the package</span>
<span style="color: #0000FF; font-weight: bold;">require</span><span style="color: #080;">&amp;#40;</span>XLConnect<span style="color: #080;">&amp;#41;</span>
&amp;nbsp;
<span style="color: #228B22;">#Loading an Excel workbook. Both .xls and .xlsx file formats can be used.</span>
wb <span style="color: #080;">=</span> loadWorkbook<span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">"XLConnectExample1.xlsx"</span>, create <span style="color: #080;">=</span> TRUE<span style="color: #080;">&amp;#41;</span>
&amp;nbsp;
<span style="color: #228B22;">#reading worksheets of an Excel workbook</span>
<span style="color: #0000FF; font-weight: bold;">data</span> <span style="color: #080;">=</span> readWorksheet<span style="color: #080;">&amp;#40;</span>wb, sheet <span style="color: #080;">=</span> <span style="color: #ff0000;">"chickSheet"</span>, startRow <span style="color: #080;">=</span> <span style="color: #ff0000;">0</span>, endRow <span style="color: #080;">=</span> <span style="color: #ff0000;">10</span>,
startCol <span style="color: #080;">=</span> <span style="color: #ff0000;">0</span>, endCol <span style="color: #080;">=</span> <span style="color: #ff0000;">0</span><span style="color: #080;">&amp;#41;</span>
&amp;nbsp;
<span style="color: #228B22;">#print data</span>
<span style="color: #0000FF; font-weight: bold;">data</span>
&amp;nbsp;</pre></pre></div></div><br />
<br />
<!-- START HTML -->
<pre>
  weight Time Chick Diet
1     42    0     1    1
2     51    2     1    1
3     59    4     1    1
4     64    6     1    1
5     76    8     1    1
6     93   10     1    1
7    106   12     1    1
</pre>
<!-- END HTML --><br />
<br />
<br />
<h4 class="formatter-title">Reading from an Excel sheet with one call</h4><br />
<br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&amp;nbsp;
<span style="color: #0000FF; font-weight: bold;">require</span><span style="color: #080;">&amp;#40;</span>XLConnect<span style="color: #080;">&amp;#41;</span>
<span style="color: #0000FF; font-weight: bold;">data</span> <span style="color: #080;">=</span> readWorksheetFromFile<span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">"XLConnectExample1.xlsx"</span>, sheet <span style="color: #080;">=</span> <span style="color: #ff0000;">"chickSheet"</span>, 
startRow <span style="color: #080;">=</span> <span style="color: #ff0000;">0</span>, endRow <span style="color: #080;">=</span> <span style="color: #ff0000;">10</span>, startCol <span style="color: #080;">=</span> <span style="color: #ff0000;">0</span>, endCol <span style="color: #080;">=</span> <span style="color: #ff0000;">0</span><span style="color: #080;">&amp;#41;</span>
&amp;nbsp;</pre></pre></div></div><br />
<br />
<h3 class="formatter-title">Adds an image to a worksheet using a named region</h3><br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&amp;nbsp;
<span style="color: #228B22;"># Load workbook (create if not existing)</span>
wb <span style="color: #080;">=</span> loadWorkbook<span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">"add_image_to_excel.xls"</span>, create<span style="color: #080;">=</span>TRUE<span style="color: #080;">&amp;#41;</span>
&amp;nbsp;
<span style="color: #228B22;"># Create a sheet named 'boxplot'</span>
createSheet<span style="color: #080;">&amp;#40;</span>wb, name <span style="color: #080;">=</span> <span style="color: #ff0000;">"boxplot"</span><span style="color: #080;">&amp;#41;</span>
&amp;nbsp;
<span style="color: #228B22;"># Create a named region called 'boxplot' referring to the sheet</span>
<span style="color: #228B22;"># called 'boxplot' </span>
createName<span style="color: #080;">&amp;#40;</span>wb, name <span style="color: #080;">=</span> <span style="color: #ff0000;">"boxplot"</span>, <span style="color: #0000FF; font-weight: bold;">formula</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"boxplot!$B$2"</span><span style="color: #080;">&amp;#41;</span>
&amp;nbsp;
<span style="color: #228B22;"># Create R plot to a png device</span>
<span style="color: #0000FF; font-weight: bold;">png</span><span style="color: #080;">&amp;#40;</span>filename <span style="color: #080;">=</span> <span style="color: #ff0000;">"boxplot.png"</span>, width <span style="color: #080;">=</span> <span style="color: #ff0000;">800</span>, height <span style="color: #080;">=</span> <span style="color: #ff0000;">600</span><span style="color: #080;">&amp;#41;</span>
<span style="color: #0000FF; font-weight: bold;">boxplot</span><span style="color: #080;">&amp;#40;</span>count ~ spray, <span style="color: #0000FF; font-weight: bold;">data</span> <span style="color: #080;">=</span> <span style="color: #CC9900; font-weight: bold;">InsectSprays</span>, <span style="color: #0000FF; font-weight: bold;">col</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"lightgray"</span><span style="color: #080;">&amp;#41;</span>
<span style="color: #0000FF; font-weight: bold;">dev.<span style="">off</span></span><span style="color: #080;">&amp;#40;</span><span style="color: #080;">&amp;#41;</span>
&amp;nbsp;
<span style="color: #228B22;"># Write image to the named region created above</span>
addImage<span style="color: #080;">&amp;#40;</span>wb, filename <span style="color: #080;">=</span> <span style="color: #ff0000;">"boxplot.png"</span>, name<span style="color: #080;">=</span><span style="color: #ff0000;">"boxplot"</span>, originalSize <span style="color: #080;">=</span> TRUE<span style="color: #080;">&amp;#41;</span>
&amp;nbsp;
<span style="color: #228B22;"># Save workbook (this actually writes the file to disk)</span>
saveWorkbook<span style="color: #080;">&amp;#40;</span>wb<span style="color: #080;">&amp;#41;</span>
&amp;nbsp;</pre></pre></div></div><br />
<br />
<br />
As a result, we obtain the following graph, written into Excel file<br />
<img src="https://www.sthda.com/english/upload/add_graph_to_excel.png" alt="" />]]></description>
			<pubDate>Fri, 27 Jul 2012 19:00:00 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[fgui: Generating automatically a GUI (graphical user interface) with R software]]></title>
			<link>https://www.sthda.com/english/articles/2-r/2-fgui-generating-automatically-a-gui-graphical-user-interface-with-r-software/</link>
			<guid>https://www.sthda.com/english/articles/2-r/2-fgui-generating-automatically-a-gui-graphical-user-interface-with-r-software/</guid>
			<description><![CDATA[<p class="float-left"><img src="https://www.sthda.com/english/upload/fgui_add.png" alt="" class="valign_" /></p><br />
<br />
<br />
fgui is an R package to automatically generate a graphical interface for function arguments.<br />
You just have to create your function and pass it to fgui. The interface will be automatically created by fgui library! <br />
<br />
<!-- START HTML -->
<div style="clear:both;"></div>
<!-- END HTML --><br />
<h3 class="formatter-title">install fgui package</h3><br />
<br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&amp;nbsp;
<span style="color: #0000FF; font-weight: bold;">install.<span style="">packages</span></span><span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">'fgui'</span><span style="color: #080;">&amp;#41;</span>
&amp;nbsp;</pre></pre></div></div><br />
<br />
<br />
<h3 class="formatter-title">xamples of using fgui</h3><br />
<br />
<br /><h4 class="formatter-title">Quick example: create a GUI for a function that adds or multiplies two numbers x and y</h4><br /><br />
<br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&amp;nbsp;
<span style="color: #228B22;">#1-Loading the package</span>
<span style="color: #0000FF; font-weight: bold;">require</span><span style="color: #080;">&amp;#40;</span>fgui<span style="color: #080;">&amp;#41;</span>
&amp;nbsp;
<span style="color: #228B22;">#2- add or multiplie (if multiplie =TRUE) two numbers and return the value</span>
add <span style="color: #080;"><-</span> <span style="color: #0000FF; font-weight: bold;">function</span><span style="color: #080;">&amp;#40;</span>x,  y, multiply<span style="color: #080;">&amp;#41;</span> <span style="color: #080;">&amp;#123;</span>
 <span style="color: #0000FF; font-weight: bold;">if</span><span style="color: #080;">&amp;#40;</span>multiply<span style="color: #080;">&amp;#41;</span> <span style="color: #0000FF; font-weight: bold;">return</span><span style="color: #080;">&amp;#40;</span>x<span style="color: #080;">*</span>y<span style="color: #080;">&amp;#41;</span>  <span style="color: #0000FF; font-weight: bold;">else</span> <span style="color: #0000FF; font-weight: bold;">return</span><span style="color: #080;">&amp;#40;</span>x <span style="color: #080;">+</span> y<span style="color: #080;">&amp;#41;</span>
<span style="color: #080;">&amp;#125;</span>
&amp;nbsp;
<span style="color: #228B22;"># Executing the function with a GUI</span>
y <span style="color: #080;"><-</span> gui<span style="color: #080;">&amp;#40;</span>add,argOption<span style="color: #080;">=</span><span style="color: #0000FF; font-weight: bold;">list</span><span style="color: #080;">&amp;#40;</span>multiply<span style="color: #080;">=</span><span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">"TRUE"</span>,<span style="color: #ff0000;">"FALSE"</span><span style="color: #080;">&amp;#41;</span><span style="color: #080;">&amp;#41;</span><span style="color: #080;">&amp;#41;</span>
&amp;nbsp;</pre></pre></div></div><br />
<br />
<strong><span style="color:blue;">The generated image is as follows: </span></strong><br />
<img src="https://www.sthda.com/english/upload/fgui_add.png" alt="" class="valign_" /><br />
<br />
<span class="success">The codes in this tutorial have been tested and validated on MAC OSX /R.2.13 and R.2.15.1</span><br />
<br />
Source :<br />
http://www.r-bloggers.com/fgui-automatically-creating-widgets-for-arguments-of-a-function-%E2%80%93-a-quick-example/]]></description>
			<pubDate>Wed, 25 Jul 2012 21:36:01 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[Install samr package]]></title>
			<link>https://www.sthda.com/english/articles/2-r/1-install-samr-package/</link>
			<guid>https://www.sthda.com/english/articles/2-r/1-install-samr-package/</guid>
			<description><![CDATA[SAM (Significance Analysis of Microarrays) is a statistical method to identify differentially expressed genes using microarray experiment.<br />
<br />
To see the official website <a href="http://www-stat.stanford.edu/~tibs/SAM/">click here</a><br />
<br />
To use SAM in R, install the package samr : <br />
<br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&amp;nbsp;
<span style="color: #0000FF; font-weight: bold;">install.<span style="">packages</span></span><span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">'samr'</span><span style="color: #080;">&amp;#41;</span>
&amp;nbsp;</pre></pre></div></div><br />
<br />
<span class="warning"> <a href="http://cran.r-project.org/web/packages/samr/index.html">samr</a> package depends on the <strong>'inpute' </strong> package which can not be installed directly from R terminal (R 2.15.1 version).</span><br />
<br />
inpute package is available from <a href="http://www.bioconductor.org/packages/release/bioc/html/impute.html">Bioconductor</a> web site<br />
<br />
To install the package inpute, use the following code in R : <br />
<br />
<div class="formatter-container formatter-code code-R"><span class="formatter-title">Code R :</span><div class="formatter-content"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&amp;nbsp;
<span style="color: #0000FF; font-weight: bold;">source</span><span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">"http://bioconductor.org/biocLite.R"</span><span style="color: #080;">&amp;#41;</span>
biocLite<span style="color: #080;">&amp;#40;</span><span style="color: #ff0000;">"impute"</span><span style="color: #080;">&amp;#41;</span>
&amp;nbsp;</pre></pre></div></div>]]></description>
			<pubDate>Wed, 25 Jul 2012 12:15:01 +0200</pubDate>
			
		</item>
		
	</channel>
</rss>
