<?xml version="1.0" encoding="UTF-8" ?>
<!-- RSS generated by PHPBoost on Sat, 25 Apr 2026 01:38:17 +0200 -->

<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Derniers articles - STHDA : R]]></title>
		<atom:link href="https://www.sthda.com/french/syndication/rss/articles/7" rel="self" type="application/rss+xml"/>
		<link>https://www.sthda.com</link>
		<description><![CDATA[Derniers articles - STHDA : R]]></description>
		<copyright>(C) 2005-2026 PHPBoost</copyright>
		<language>fr</language>
		<generator>PHPBoost</generator>
		
		
		<item>
			<title><![CDATA[R2XLSX : lire, ?crire et formater un document Excel dans R]]></title>
			<link>https://www.sthda.com/french/articles/7-r/60-r2xlsx-lire-ecrire-et-formater-un-document-excel-dans-r/</link>
			<guid>https://www.sthda.com/french/articles/7-r/60-r2xlsx-lire-ecrire-et-formater-un-document-excel-dans-r/</guid>
			<description><![CDATA[<!-- START HTML -->
<ul id="toc"></ul>
<!-- END HTML --><br />
<br />
R2XLSX est un fichier  contenant un ensemble de fonctions R, que j'ai ?crite, permettant de lire et ?crire un fichier Excel dans R de mani?re simple et rapide. Il offre ?galement la possibilit? d'ajouter des graphiques et de formater les donn?es. <br />
<br />
<br />
<h3 class="formatter-title">Installation</h3><br />
<br />
Pour pouvoir utiliser les fonctions contenues dans le fichier R2XLSX, vous devez ex?cuter le code suivant ? chaque session R. Les fonctions d?pendent du package <strong>xlsx</strong>. Le package xlsx est automatiquement install? par le script dans le cas o? il n'existe pas.<br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #0000FF; font-weight: bold;">source</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"https://www.sthda.com/french/upload/r2xlsx.r"</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<h3 class="formatter-title">Les fonctions disponibles</h3><br />
<ul class="formatter-ul">
	<li class="formatter-li"><strong>xlsx.addPlot</strong> pour ajouter un graphique.
	</li><li class="formatter-li"><strong>xlsx.addParagraph</strong> pour ajouter un paragraphe de textes
	</li><li class="formatter-li"><strong>xlsx.addTable</strong> pour ajouter des tables.
	</li><li class="formatter-li"><strong>xlsx.addHeader</strong> pour ajouter des titres.
	</li><li class="formatter-li"><strong>xlsx.addLineBreak</strong> pour ajouter un saut de ligne.
	</li><li class="formatter-li"><strong>xlsx.addHyperlink</strong> pour ajouter un lien hypertext.
	</li><li class="formatter-li"><strong>xlsx.readFile</strong> pour lire un fichier excel.
	</li><li class="formatter-li"><strong>xlsx.writeFile</strong> pour ?crire un fichier excel.
        </li><li class="formatter-li"><strong>xlsx.openFile</strong> pour ouvrir le fichier excel.<br />
<br />
</li></ul><br />
<br />
<h3 class="formatter-title">Votre premier document Excel</h3><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #0000FF; font-weight: bold;">source</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"https://www.sthda.com/french/upload/r2xlsx.r"</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;">#create an Excel workbook. Both .xls and .xlsx file formats can be used.</span>
filename <span style="color: #080;"><-</span> <span style="color: #ff0000;">"Example1.xlsx"</span>
wb <span style="color: #080;"><-</span> createWorkbook<span style="color: #080;">&#40;</span>type<span style="color: #080;">=</span><span style="color: #ff0000;">"xlsx"</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">#Create a sheet in that workbook to contain the table</span>
sheet <span style="color: #080;"><-</span> createSheet<span style="color: #080;">&#40;</span>wb, sheetName <span style="color: #080;">=</span> <span style="color: #ff0000;">"example1"</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;">#Add header</span>
<span style="color: #228B22;">#+++++++++++++++++++++++++++++++</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Add table"</span>,level<span style="color: #080;">=</span><span style="color: #ff0000;">1</span>, color<span style="color: #080;">=</span><span style="color: #ff0000;">"black"</span>, underline<span style="color: #080;">=</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;">#Add Text :Author</span>
<span style="color: #228B22;">#+++++++++++++++++++++++++++++++</span>
xlsx.<span style="">addText</span><span style="color: #080;">&#40;</span>wb, sheet, 
             value<span style="color: #080;">=</span><span style="color: #ff0000;">"Author : Alboukadel KASSAMBARA. <span style="color: #000099; font-weight: bold;">\n</span>@:alboukadel.kassambara@gmail.com.<span style="color: #000099; font-weight: bold;">\n</span> Website : http://ww.sthda.com"</span>,
             isItalic<span style="color: #080;">=</span>TRUE, colSpan<span style="color: #080;">=</span><span style="color: #ff0000;">5</span>, rowSpan<span style="color: #080;">=</span><span style="color: #ff0000;">3</span>, fontColor<span style="color: #080;">=</span><span style="color: #ff0000;">"darkgray"</span>, fontSize<span style="color: #080;">=</span><span style="color: #ff0000;">14</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">3</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;">#Add table</span>
<span style="color: #228B22;">#+++++++++++++++++++++++++++++++</span>
xlsx.<span style="">addTable</span><span style="color: #080;">&#40;</span>wb, sheet, <span style="color: #0000FF; font-weight: bold;">head</span><span style="color: #080;">&#40;</span><span style="color: #CC9900; font-weight: bold;">iris</span><span style="color: #080;">&#41;</span>, startCol<span style="color: #080;">=</span><span style="color: #ff0000;">2</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">2</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;">#saving a workbook to an Excel file and writes the file to disk.</span>
saveWorkbook<span style="color: #080;">&#40;</span>wb, filename<span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;">#View the file</span>
xlsx.<span style="">openFile</span><span style="color: #080;">&#40;</span>filename<span style="color: #080;">&#41;</span>
&nbsp;
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:521px; height:258px"><img src="https://www.sthda.com/french/french/upload/r2xlsx_first_document.png"/></div></center>
<!-- END HTML --><br />
<br />
<h3 class="formatter-title">Ajout de titre</h3><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Don't forget to create a workbook and a sheet as previously</span>
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Header</span>
<span style="color: #228B22;">#**************************************</span>
<span style="color: #228B22;">#header level 1</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Header 1"</span>,level<span style="color: #080;">=</span><span style="color: #ff0000;">1</span>, color<span style="color: #080;">=</span><span style="color: #ff0000;">"black"</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">#header level 2</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Header 2"</span>,level<span style="color: #080;">=</span><span style="color: #ff0000;">2</span>, color<span style="color: #080;">=</span><span style="color: #ff0000;">"black"</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">#header level 3</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Header 3"</span>,level<span style="color: #080;">=</span><span style="color: #ff0000;">3</span>, color<span style="color: #080;">=</span><span style="color: #ff0000;">"black"</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">#header level 4</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Header 4"</span>,level<span style="color: #080;">=</span><span style="color: #ff0000;">4</span>, color<span style="color: #080;">=</span><span style="color: #ff0000;">"black"</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">#header level 5</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Header 5"</span>,level<span style="color: #080;">=</span><span style="color: #ff0000;">5</span>, color<span style="color: #080;">=</span><span style="color: #ff0000;">"black"</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">#header level 6</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Header 6"</span>,level<span style="color: #080;">=</span><span style="color: #ff0000;">6</span>, color<span style="color: #080;">=</span><span style="color: #ff0000;">"black"</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Don't forget to save the workbook</span>
<span style="color: #228B22;">#......</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:266px; height:133px"><img src="https://www.sthda.com/french/french/upload/r2xlsx_header.png"/></div></center>
<!-- END HTML --><br />
<br />
<br />
<h3 class="formatter-title">Ajout de textes </h3><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Don't forget to create a workbook and a sheet as previously</span>
<span style="color: #228B22;">#......</span>
&nbsp;
<span style="color: #228B22;"># Add texts</span>
<span style="color: #228B22;">#**************************************</span>
<span style="color: #228B22;">#Add Text :Author</span>
<span style="color: #228B22;">#+++++++++++++++++++++++++++++++</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Author"</span>,level<span style="color: #080;">=</span><span style="color: #ff0000;">2</span>, color<span style="color: #080;">=</span><span style="color: #ff0000;">"black"</span>, underline<span style="color: #080;">=</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addText</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Author : Alboukadel KASSAMBARA. <span style="color: #000099; font-weight: bold;">\n</span>@:alboukadel.kassambara@gmail.com.<span style="color: #000099; font-weight: bold;">\n</span> Website : http://ww.sthda.com"</span>,
             isItalic<span style="color: #080;">=</span>TRUE, colSpan<span style="color: #080;">=</span><span style="color: #ff0000;">5</span>, rowSpan<span style="color: #080;">=</span><span style="color: #ff0000;">3</span>, fontColor<span style="color: #080;">=</span><span style="color: #ff0000;">"darkgray"</span>, fontSize<span style="color: #080;">=</span><span style="color: #ff0000;">14</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">3</span><span style="color: #080;">&#41;</span><span style="color: #228B22;"># Three line breaks</span>
&nbsp;
<span style="color: #228B22;">#Add paragraph</span>
<span style="color: #228B22;">#+++++++++++++++++++++++++++++</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, <span style="color: #ff0000;">" Add paragraph"</span>, level<span style="color: #080;">=</span><span style="color: #ff0000;">2</span>, underline<span style="color: #080;">=</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">2</span><span style="color: #080;">&#41;</span>
paragraph<span style="color: #080;">=</span><span style="color: #ff0000;">"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged."</span>
<span style="color: #228B22;">#customized</span>
xlsx.<span style="">addParagraph</span><span style="color: #080;">&#40;</span>wb, sheet, paragraph, fontSize<span style="color: #080;">=</span><span style="color: #ff0000;">14</span>, isItalic<span style="color: #080;">=</span>TRUE, 
                  fontColor<span style="color: #080;">=</span><span style="color: #ff0000;">"darkred"</span>, backGroundColor<span style="color: #080;">=</span><span style="color: #ff0000;">"gray"</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">2</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Don't forget to save the workbook</span>
<span style="color: #228B22;">#......</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:437px; height:263px"><img src="https://www.sthda.com/french/french/upload/r2xlsx_text.png"/></div></center>
<!-- END HTML --><br />
<br />
<h3 class="formatter-title">Ajouter un hyperlien</h3><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Don't forget to create a workbook and a sheet as previously</span>
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Header</span>
<span style="color: #228B22;">#**************************************</span>
&nbsp;
<span style="color: #228B22;">#Add Hyperlink</span>
<span style="color: #228B22;">#+++++++++++++++++++++++++++++</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, <span style="color: #ff0000;">" Add Hyperlink"</span>, level<span style="color: #080;">=</span><span style="color: #ff0000;">2</span>, underline<span style="color: #080;">=</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addHyperlink</span><span style="color: #080;">&#40;</span>wb, sheet, <span style="color: #ff0000;">"https://www.sthda.com"</span>, <span style="color: #ff0000;">"Click-me!!"</span>, fontSize<span style="color: #080;">=</span><span style="color: #ff0000;">12</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">2</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Don't forget to save the workbook</span>
<span style="color: #228B22;">#......</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:231px; height:74px"><img src="https://www.sthda.com/french/french/upload/r2xlsx_hyperlink.png"/></div></center>
<!-- END HTML --><br />
<br />
<br />
<h3 class="formatter-title">Ajouter une table</h3><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Don't forget to create a workbook and a sheet as previously</span>
<span style="color: #228B22;">#......</span>
&nbsp;
<span style="color: #228B22;">#Add table</span>
<span style="color: #228B22;">#+++++++++++++++++++++++++++++</span>
<span style="color: #228B22;">#add iris data using default settings</span>
<span style="color: #0000FF; font-weight: bold;">data</span><span style="color: #080;">&#40;</span><span style="color: #CC9900; font-weight: bold;">iris</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">#header</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Add table"</span>,level<span style="color: #080;">=</span><span style="color: #ff0000;">2</span>, color<span style="color: #080;">=</span><span style="color: #ff0000;">"black"</span>, underline<span style="color: #080;">=</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;">#header</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Simple Table"</span>,level<span style="color: #080;">=</span><span style="color: #ff0000;">3</span>, color<span style="color: #080;">=</span><span style="color: #ff0000;">"black"</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addTable</span><span style="color: #080;">&#40;</span>wb, sheet, <span style="color: #0000FF; font-weight: bold;">head</span><span style="color: #080;">&#40;</span><span style="color: #CC9900; font-weight: bold;">iris</span><span style="color: #080;">&#41;</span>, startCol<span style="color: #080;">=</span><span style="color: #ff0000;">2</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">2</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;">#Customized table : column data format</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Customized table : font color and size"</span>,
               level<span style="color: #080;">=</span><span style="color: #ff0000;">3</span>, color<span style="color: #080;">=</span><span style="color: #ff0000;">"black"</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addTable</span><span style="color: #080;">&#40;</span>wb, sheet, <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;">&#40;</span><span style="color: #CC9900; font-weight: bold;">iris</span><span style="color: #080;">&#41;</span>,
              fontColor<span style="color: #080;">=</span><span style="color: #ff0000;">"darkblue"</span>, fontSize<span style="color: #080;">=</span><span style="color: #ff0000;">"16"</span>             
<span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">2</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Don't forget to save the workbook</span>
<span style="color: #228B22;">#......</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:519px; height:421px"><img src="https://www.sthda.com/french/french/upload/r2xlsx_table.png"/></div></center>
<!-- END HTML --><br />
<br />
<br />
<h3 class="formatter-title">Ajouter un graphique</h3><br />
<br />
<h4 class="formatter-title">Boxplot basic</h4><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Don't forget to create a workbook and a sheet as previously</span>
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Add Plot</span>
<span style="color: #228B22;">#+++++++++++++++++++++++++++++</span>
<span style="color: #228B22;">#boxplot</span>
<span style="color: #0000FF; font-weight: bold;">data</span><span style="color: #080;">&#40;</span><span style="color: #CC9900; font-weight: bold;">ToothGrowth</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, <span style="color: #ff0000;">" Add Plot"</span>, level<span style="color: #080;">=</span><span style="color: #ff0000;">2</span>, underline<span style="color: #080;">=</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
plotFunction<span style="color: #080;"><-</span><span style="color: #0000FF; font-weight: bold;">function</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#123;</span><span style="color: #0000FF; font-weight: bold;">boxplot</span><span style="color: #080;">&#40;</span>len ~ dose, <span style="color: #0000FF; font-weight: bold;">data</span> <span style="color: #080;">=</span> <span style="color: #CC9900; font-weight: bold;">ToothGrowth</span>,
                                 <span style="color: #0000FF; font-weight: bold;">subset</span> <span style="color: #080;">=</span> supp <span style="color: #080;">==</span> <span style="color: #ff0000;">"VC"</span>, <span style="color: #0000FF; font-weight: bold;">col</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"yellow"</span>,
                                 main <span style="color: #080;">=</span> <span style="color: #ff0000;">"Guinea Pigs' Tooth Growth"</span>,
                                 xlab <span style="color: #080;">=</span> <span style="color: #ff0000;">"Vitamin C dose mg"</span>, ylab <span style="color: #080;">=</span> <span style="color: #ff0000;">"tooth length"</span>,
                                 xlim <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">0.5</span>, <span style="color: #ff0000;">3.5</span><span style="color: #080;">&#41;</span>, ylim <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">0</span>, <span style="color: #ff0000;">35</span><span style="color: #080;">&#41;</span>, yaxs <span style="color: #080;">=</span> <span style="color: #ff0000;">"i"</span><span style="color: #080;">&#41;</span>
<span style="color: #080;">&#125;</span>
xlsx.<span style="">addPlot</span><span style="color: #080;">&#40;</span>wb, sheet, plotFunction<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Don't forget to save the workbook</span>
<span style="color: #228B22;">#......</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:442px; height:397px"><img src="https://www.sthda.com/french/french/upload/r2xlsx_boxplot.png"/></div></center>
<!-- END HTML --><br />
<br />
<h4 class="formatter-title">GGPLOT2 : Courbe de densit?</h4><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Don't forget to create workbook and sheet as previously</span>
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Add Plot</span>
<span style="color: #228B22;">#+++++++++++++++++++++++++++++</span>
<span style="color: #228B22;">#ggplot2</span>
rquery.<span style="">loadPackages</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"ggplot2"</span><span style="color: #080;">&#41;</span><span style="color: #228B22;">#for plot</span>
<span style="color: #0000FF; font-weight: bold;">set.<span style="">seed</span></span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">1234</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF; font-weight: bold;">df</span> <span style="color: #080;"><-</span> <span style="color: #0000FF; font-weight: bold;">data.<span style="">frame</span></span><span style="color: #080;">&#40;</span>cond <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">factor</span><span style="color: #080;">&#40;</span> <span style="color: #0000FF; font-weight: bold;">rep</span><span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"A"</span>,<span style="color: #ff0000;">"B"</span><span style="color: #080;">&#41;</span>, each<span style="color: #080;">=</span><span style="color: #ff0000;">200</span><span style="color: #080;">&#41;</span> <span style="color: #080;">&#41;</span>, 
                 rating <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">rnorm</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">200</span><span style="color: #080;">&#41;</span>,<span style="color: #0000FF; font-weight: bold;">rnorm</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">200</span>, <span style="color: #0000FF; font-weight: bold;">mean</span><span style="color: #080;">=</span>.8<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;"># Density plots with semi-transparent fill</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, <span style="color: #ff0000;">"Density plots with semi-transparent fill"</span>, level<span style="color: #080;">=</span><span style="color: #ff0000;">2</span>, underline<span style="color: #080;">=</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
&nbsp;
gg.<span style="">p</span><span style="color: #080;"><-</span>ggplot<span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">df</span>, aes<span style="color: #080;">&#40;</span>x<span style="color: #080;">=</span>rating, fill<span style="color: #080;">=</span>cond<span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span> <span style="color: #080;">+</span> geom_density<span style="color: #080;">&#40;</span>alpha<span style="color: #080;">=</span>.3<span style="color: #080;">&#41;</span>
xlsx.<span style="">addPlot</span><span style="color: #080;">&#40;</span>wb, sheet, <span style="color: #0000FF; font-weight: bold;">function</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#123;</span><span style="color: #0000FF; font-weight: bold;">print</span><span style="color: #080;">&#40;</span>gg.<span style="">p</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#125;</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">#......</span>
<span style="color: #228B22;">#Don't forget to save the workbook</span>
<span style="color: #228B22;">#......</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:436px; height:395px"><img src="https://www.sthda.com/french/french/upload/r2xlsx_ggplot2.png"/></div></center>
<!-- END HTML --><br />
<br />
<br />
<h3 class="formatter-title">Lire un fichier Excel</h3><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #0000FF; font-weight: bold;">file</span> <span style="color: #080;"><-</span> <span style="color: #0000FF; font-weight: bold;">system.<span style="">file</span></span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"tests"</span>, <span style="color: #ff0000;">"test_import.xlsx"</span>, package <span style="color: #080;">=</span> <span style="color: #ff0000;">"xlsx"</span><span style="color: #080;">&#41;</span>
res <span style="color: #080;"><-</span> xlsx.<span style="">readFile</span><span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">file</span>, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>  <span style="color: #228B22;"># read first sheet</span>
<span style="color: #0000FF; font-weight: bold;">head</span><span style="color: #080;">&#40;</span>res<span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<h3 class="formatter-title">Ecrire un fichier Excel</h3><br />
<br />
LA fonction suivante permet d'?crire une table de donn?es dans un fichier excel.<br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
res <span style="color: #080;"><-</span> xlsx.<span style="">writeFile</span><span style="color: #080;">&#40;</span><span style="color: #CC9900; font-weight: bold;">USArrests</span>, <span style="color: #0000FF; font-weight: bold;">file</span><span style="color: #080;">=</span><span style="color: #ff0000;">"USArrests.xlsx"</span>, sheetName<span style="color: #080;">=</span><span style="color: #ff0000;">"USArrests"</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<h3 class="formatter-title">Un document Excel complet</h3><br />
<br />
<span class="success">Le script complet utilis? pour cr?e le document word suivant est t?l?chargeable ici : <a href="https://www.sthda.com/french/french/upload/howtouse_r2xlsx.r">howToUse_R2XLSX.R</a></span><br />
<br />
Le fichier Excel est t?l?chargeable en cliquant sur le lien suivant:<a href="https://www.sthda.com/french/french/upload/r2xlsx_example1.xlsx">R2XLSX_Example1.xlsx</a><br />
<br />
<!-- START HTML -->
<a href="https://www.sthda.com/french/french/upload/r2xlsx_example1.pdf" class="embed" >Document Excel complet</a>
<!-- END HTML --><br />
<br />
<br />
<h3 class="formatter-title">Utilisation avanc?e - prototype des fonctions</h3><br />
<br />
Les prototypes des fonctions sont montr?es ci-dessous pour une utilisation avanc?e.<br />
<br />
<h4 class="formatter-title">xlsx.addHeader</h4><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#Add header :sheet title and subtitle</span>
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#wb :workbook object</span>
<span style="color: #228B22;">#sheet : sheet object</span>
<span style="color: #228B22;">#value : your header value</span>
<span style="color: #228B22;">#level : header level; possible value (1 to 6)</span>
<span style="color: #228B22;">#startRow : row index to start to write</span>
<span style="color: #228B22;">#startCol : col index to start to write</span>
<span style="color: #228B22;">#rowBreak : number of rows to jump before appending the data</span>
<span style="color: #228B22;">#underline : a numeric value specifying the thickness of the underline.</span>
<span style="color: #228B22;">#Allowed values are 0, 1, 2.</span>
xlsx.<span style="">addHeader</span><span style="color: #080;">&#40;</span>wb, sheet, value<span style="color: #080;">=</span><span style="color: #ff0000;">"Header"</span>, level<span style="color: #080;">=</span><span style="color: #ff0000;">1</span>, color<span style="color: #080;">=</span><span style="color: #ff0000;">"#FFFFFF"</span>,
                         startRow<span style="color: #080;">=</span>NULL, startCol<span style="color: #080;">=</span><span style="color: #ff0000;">2</span>, underline<span style="color: #080;">=</span><span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">0</span>,<span style="color: #ff0000;">1</span>,<span style="color: #ff0000;">2</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<h4 class="formatter-title">xlsx.addText</h4><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#Add Text : add a simple line text</span>
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#the function is similar to xlsx.addParagraph</span>
<span style="color: #228B22;">#wb :workbook object</span>
<span style="color: #228B22;">#sheet : sheet object</span>
<span style="color: #228B22;">#value : paragraph text</span>
<span style="color: #228B22;">#fontColor: text color. default is black. value : all colors returned by colors() can be used</span>
<span style="color: #228B22;">#backGroundColor : fill color of the cell</span>
<span style="color: #228B22;">#fontSize : text size</span>
<span style="color: #228B22;">#isBold : if TRUE, the text is written in bold format</span>
<span style="color: #228B22;">#isItalic : if TRUE, the text is written in italic format</span>
<span style="color: #228B22;">#startRow : row index to start to write</span>
<span style="color: #228B22;">#startCol : col index to start to write</span>
<span style="color: #228B22;">#colSpan : number of column to be merged (paragraph : width)</span>
<span style="color: #228B22;">#rowSpan : number of rows to be merged corresponding to paragrath height</span>
xlsx.<span style="">addText</span><span style="color: #080;">&#40;</span>wb,sheet, value, fontColor<span style="color: #080;">=</span><span style="color: #ff0000;">"#FFFFFF"</span>, fontSize<span style="color: #080;">=</span><span style="color: #ff0000;">12</span>, backGroundColor<span style="color: #080;">=</span><span style="color: #ff0000;">"#FFFFFF"</span>,
                            isBold<span style="color: #080;">=</span>FALSE, isItalic<span style="color: #080;">=</span>FALSE,
                            startRow<span style="color: #080;">=</span>NULL, startCol<span style="color: #080;">=</span><span style="color: #ff0000;">2</span>, colSpan<span style="color: #080;">=</span><span style="color: #ff0000;">1</span>, rowSpan<span style="color: #080;">=</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<h4 class="formatter-title">xlsx.addParagraph</h4><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#Add paragraph</span>
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#wb :workbook object</span>
<span style="color: #228B22;">#sheet : sheet object</span>
<span style="color: #228B22;">#value : paragraph text</span>
<span style="color: #228B22;">#fontColor: text color. default is black. value : all colors returned by colors() can be used</span>
<span style="color: #228B22;">#fontSize : text size</span>
<span style="color: #228B22;">#backGroundColor : fill color of the cell</span>
<span style="color: #228B22;">#isBold : if TRUE, the text is written in bold format</span>
<span style="color: #228B22;">#isItalic : if TRUE, the text is written in italic format</span>
<span style="color: #228B22;">#startRow : row index to start to write</span>
<span style="color: #228B22;">#startCol : col index to start to write</span>
<span style="color: #228B22;">#colSpan : number of column to be merged (paragraph : width)</span>
<span style="color: #228B22;">#rowSapn : number of rows to be merged corresponding to paragrath height</span>
xlsx.<span style="">addParagraph</span><span style="color: #080;">&#40;</span>wb,sheet, value, fontColor<span style="color: #080;">=</span><span style="color: #ff0000;">"#FFFFFF"</span>, fontSize<span style="color: #080;">=</span><span style="color: #ff0000;">12</span>, backGroundColor<span style="color: #080;">=</span><span style="color: #ff0000;">"#FFFFFF"</span>,
                            isBold<span style="color: #080;">=</span>FALSE, isItalic<span style="color: #080;">=</span>FALSE,
                            startRow<span style="color: #080;">=</span>NULL, startCol<span style="color: #080;">=</span><span style="color: #ff0000;">2</span>, colSpan<span style="color: #080;">=</span><span style="color: #ff0000;">10</span>, rowSpan<span style="color: #080;">=</span><span style="color: #ff0000;">5</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<h4 class="formatter-title">xlsx.addHyperlink</h4><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#Add Hyperlink</span>
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#wb :workbook object</span>
<span style="color: #228B22;">#sheet : sheet object</span>
<span style="color: #228B22;">#value : paragraph text</span>
<span style="color: #228B22;">#fontColor: text color. default is black. value : all colors returned by colors() can be used</span>
<span style="color: #228B22;">#fontSize : text size</span>
<span style="color: #228B22;">#isBold : if TRUE, the text is written in bold format</span>
<span style="color: #228B22;">#isItalic : if TRUE, the text is written in italic format</span>
<span style="color: #228B22;">#startRow : row index to start to write</span>
<span style="color: #228B22;">#startCol : col index to start to write</span>
xlsx.<span style="">addHyperlink</span><span style="color: #080;">&#40;</span>wb,sheet, address, friendlyName, 
                            fontColor<span style="color: #080;">=</span><span style="color: #ff0000;">"blue"</span>, fontSize<span style="color: #080;">=</span><span style="color: #ff0000;">12</span>,
                            isBold<span style="color: #080;">=</span>FALSE, isItalic<span style="color: #080;">=</span>FALSE, startRow<span style="color: #080;">=</span>NULL, startCol<span style="color: #080;">=</span><span style="color: #ff0000;">2</span><span style="color: #080;">&#41;</span> 
&nbsp;</pre></pre></div><br />
<br />
<br />
<h4 class="formatter-title">xlsx.addLineBreak</h4><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#Add Line break to the sheet</span>
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#wb :workbook object</span>
<span style="color: #228B22;">#sheet : sheet object</span>
<span style="color: #228B22;">#value : your header value</span>
<span style="color: #228B22;">#level : header level; possible value (1 to 6)</span>
<span style="color: #228B22;">#startRow : row index to start to write</span>
<span style="color: #228B22;">#startCol : col index to start to write</span>
<span style="color: #228B22;">#numberOfLine : number of rows to jump before appending the data</span>
xlsx.<span style="">addLineBreak</span><span style="color: #080;">&#40;</span>sheet, numberOfLine<span style="color: #080;">=</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<h4 class="formatter-title">xlsx.addTable</h4><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#add table </span>
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#wb :workbook object</span>
<span style="color: #228B22;">#sheet : sheet object</span>
<span style="color: #228B22;">#data : data frame</span>
<span style="color: #228B22;">#level : header level; possible value (1 to 6)</span>
<span style="color: #228B22;">#startRow : row index to start to write</span>
<span style="color: #228B22;">#startCol : col index to start to write</span>
<span style="color: #228B22;">#rowBreak : nimber of rows to jum before appending the data</span>
<span style="color: #228B22;">#if col.names and row.names : column and row names  are written</span>
<span style="color: #228B22;">#fontColor : color of text</span>
<span style="color: #228B22;">#fontSize : text size</span>
<span style="color: #228B22;">#rownamesFill: background color of table row names</span>
<span style="color: #228B22;">#colnamesFill : background color of table column names</span>
<span style="color: #228B22;">#rowFill : background color of pair rows (i.e : 2, 4, 6). For table styling.</span>
<span style="color: #228B22;">#mergedColumnForRownames : number of column to merge for rownames. </span>
<span style="color: #228B22;">#Be carrefull : using mergedColumnForRownames is a  very slow process</span>
xlsx.<span style="">addTable</span><span style="color: #080;">&#40;</span>wb, sheet, <span style="color: #0000FF; font-weight: bold;">data</span>, startRow<span style="color: #080;">=</span>NULL,startCol<span style="color: #080;">=</span><span style="color: #ff0000;">2</span>,
                        col.<span style="">names</span><span style="color: #080;">=</span>TRUE, <span style="color: #0000FF; font-weight: bold;">row.<span style="">names</span></span><span style="color: #080;">=</span>TRUE, columnWidth<span style="color: #080;">=</span><span style="color: #ff0000;">14</span>,
                        fontColor<span style="color: #080;">=</span><span style="color: #ff0000;">"#FFFFFF"</span>, fontSize<span style="color: #080;">=</span><span style="color: #ff0000;">12</span>, rownamesFill<span style="color: #080;">=</span><span style="color: #ff0000;">"white"</span>, colnamesFill<span style="color: #080;">=</span><span style="color: #ff0000;">"white"</span>, rowFill<span style="color: #080;">=</span><span style="color: #ff0000;">"white"</span>,
                        mergedColumnForRownames<span style="color: #080;">=</span><span style="color: #ff0000;">1</span>,   ...<span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<h4 class="formatter-title">xlsx.addPlot</h4><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#add Plot </span>
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#wb :workbook object</span>
<span style="color: #228B22;">#sheet : sheet object</span>
<span style="color: #228B22;">#startRow : row index to start to write</span>
<span style="color: #228B22;">#startCol : col index to start to write</span>
<span style="color: #228B22;">#plotFunction: plot function</span>
xlsx.<span style="">addPlot</span><span style="color: #080;">&#40;</span> wb, sheet, plotFunction, startRow<span style="color: #080;">=</span>NULL,startCol<span style="color: #080;">=</span><span style="color: #ff0000;">2</span>,
               width<span style="color: #080;">=</span><span style="color: #ff0000;">480</span>, height<span style="color: #080;">=</span><span style="color: #ff0000;">480</span>,... <span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<h4 class="formatter-title">xlsx.writeFile</h4><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#Write a data.frame to an Excel workbook</span>
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#data : data frame</span>
<span style="color: #228B22;">#file : output file name</span>
<span style="color: #228B22;">#if col.names and row.names : column and row names  are written</span>
<span style="color: #228B22;">#append :if TRUE data should be appended to an existing file. </span>
<span style="color: #228B22;">#usage : res <- xlsx.writeFile(USArrests, file="USArrests.xlsx", sheetName="USArrests")</span>
xlsx.<span style="">writeFile</span><span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">data</span>, <span style="color: #0000FF; font-weight: bold;">file</span>, sheetName<span style="color: #080;">=</span><span style="color: #ff0000;">"Sheet1"</span>,
               col.<span style="">names</span><span style="color: #080;">=</span>TRUE, <span style="color: #0000FF; font-weight: bold;">row.<span style="">names</span></span><span style="color: #080;">=</span>TRUE, <span style="color: #0000FF; font-weight: bold;">append</span><span style="color: #080;">=</span>FALSE, ...<span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<h4 class="formatter-title">xlsx.readFile</h4><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#Read a data.frame from an Excel workbook</span>
<span style="color: #228B22;">#****************************************</span>
<span style="color: #228B22;">#file :the path to the file to read</span>
<span style="color: #228B22;">#sheetIndex: a number representing the sheet index in the workbook.</span>
<span style="color: #228B22;">#startRow : index of starting row</span>
<span style="color: #228B22;">#colIndex: a numeric vector indicating the cols you want to extract. If NULL, all columns found will be extracted</span>
<span style="color: #228B22;">#endRow: The index of the last row to pull. If NULL, read all the rows in the sheet.</span>
<span style="color: #228B22;">#header : if TRUE, the first row is considered as row names</span>
<span style="color: #228B22;">#usage : </span>
<span style="color: #228B22;">#file <- system.file("tests", "test_import.xlsx", package = "xlsx")</span>
<span style="color: #228B22;">#res <- xlsx.readFile(file, 1)  # read first sheet</span>
<span style="color: #228B22;">#head(res)</span>
xlsx.<span style="">readFile</span><span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">file</span>, sheetIndex<span style="color: #080;">=</span><span style="color: #ff0000;">1</span>, startRow<span style="color: #080;">=</span><span style="color: #ff0000;">1</span>, colIndex<span style="color: #080;">=</span>NULL, endRow<span style="color: #080;">=</span>NULL, header<span style="color: #080;">=</span>TRUE,...<span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<h4 class="formatter-title">xlsx.openFile</h4><br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#++++++++++++++++++++++++++++</span>
<span style="color: #228B22;">#Open file</span>
<span style="color: #228B22;">#++++++++++++++++++++++++++++</span>
xlsx.<span style="">openFile</span><span style="color: #080;">&#40;</span>filename<span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<br />
<h3 class="formatter-title">Voir aussi</h3><br />
<a href="https://www.sthda.com/french/french/articles/articles-7-36+xlconnect-lire-ecrire-et-manipuler-des-fichiers-microsoft-excel-a-partir-de-r.php">XLConnect: lire, ?crire et manipuler des fichiers Microsoft Excel ? partir de R</a>]]></description>
			<pubDate>Sun, 28 Jul 2013 07:35:00 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[R2DOCX : Cr?er un document word avec R]]></title>
			<link>https://www.sthda.com/french/articles/7-r/57-r2docx-creer-un-document-word-avec-r/</link>
			<guid>https://www.sthda.com/french/articles/7-r/57-r2docx-creer-un-document-word-avec-r/</guid>
			<description><![CDATA[<!-- START HTML -->
<ul id="toc"></ul>
<!-- END HTML --><br />
<br />
Deux possibilit?s pour g?n?rer un document word. Soit avec <a href="http://yihui.name/knitr/demo/pandoc/">Knitr et pandoc</a> ou avec <a href="https://github.com/davidgohel/R2DOCX">R2DOCX</a>.<br />
<br />
<h3 class="formatter-title">Pandoc : Convertir un document Markdown vers d'autres formats</h3><br />
<br />
Pour plus de d?tails <a href="http://yihui.name/knitr/demo/pandoc/">cliquez-ici</a><br />
<br />
La fonction pandoc() est incluse dans le package knitr (version 1.2) permettant de convertir des documents Markdown ? d'autres formats tels que Latex/PDF, HTML et word (.doc, .docx).<br />
<br />
Cette fonction permet juste d?ex?cuter de mani?re simple la ligne de commande suivante:<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
FILE <span style="color: #080;"><-</span> <span style="color: #ff0000;">"example"</span>
<span style="color: #0000FF; font-weight: bold;">system</span><span style="color: #080;">&#40;</span>paste0<span style="color: #080;">&#40;</span><span style="color: #ff0000;">"pandoc -o "</span>, FILE, <span style="color: #ff0000;">".docx "</span>, FILE, <span style="color: #ff0000;">".md"</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<span class="warning"><br />
Pour le fichier.md, le chemin absolu est necessaire. <br />
Utilisez donc la commande :<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
commande<span style="color: #080;"><-</span><span style="color: #0000FF; font-weight: bold;">paste</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"pandoc -o "</span>,  <span style="color: #ff0000;">"myfile.docx "</span>, <span style="color: #0000FF; font-weight: bold;">getwd</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>, <span style="color: #ff0000;">"/myfile.md "</span>, sep<span style="color: #080;">=</span><span style="color: #ff0000;">""</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF; font-weight: bold;">system</span><span style="color: #080;">&#40;</span>commande<span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
</span><br />
<br />
Pour installer pandoc <a href="http://johnmacfarlane.net/pandoc/index.html">suivre ce lien</a><br />
<br />
<strong><span style="color:blue;">Utilisation simple</span></strong><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #0000FF; font-weight: bold;">library</span><span style="color: #080;">&#40;</span>knitr<span style="color: #080;">&#41;</span>
pandoc<span style="color: #080;">&#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;">&#41;</span>  <span style="color: #228B22;"># HTML</span>
pandoc<span style="color: #080;">&#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;">&#41;</span> <span style="color: #228B22;"># LaTeX/PDF</span>
pandoc<span style="color: #080;">&#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;">&#41;</span>  <span style="color: #228B22;"># MS Word</span>
pandoc<span style="color: #080;">&#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;">&#41;</span>   <span style="color: #228B22;"># OpenDocument</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<h3 class="formatter-title">Cr?er un document word avec R2DOCX</h3><br />
<br />
R2DOCX permet de cr?er, de mani?re simple, un document word ? partir d'un template ou pas, d'ins?rer des graphiques et des tables.<br />
<br />
Une documentation est compl?te est fournie <a href="https://github.com/davidgohel/R2DOCX">ici</a><br />
Un exemple est montr? <a href="http://blog.revolutionanalytics.com/2013/06/create-word-documents-from-r-with-r2docx.html">ici</a><br />
<br />
 <h4 class="formatter-title">Installation</h4> <br />
<br />
<strong>Compatibilit? R >= 3.0</strong><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #0000FF; font-weight: bold;">install.<span style="">packages</span></span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"devtools"</span><span style="color: #080;">&#41;</span>
devtools<span style="color: #080;">::</span><span style="">install_github</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">'R2DOC'</span>, <span style="color: #ff0000;">'davidgohel'</span><span style="color: #080;">&#41;</span>
devtools<span style="color: #080;">::</span><span style="">install_github</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">'R2DOCX'</span>, <span style="color: #ff0000;">'davidgohel'</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<strong><span style="color:blue;">Pour les utilisateurs de Mac :</span></strong><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #0000FF; font-weight: bold;">Sys.<span style="">setenv</span></span><span style="color: #080;">&#40;</span>NOAWT<span style="color: #080;">=</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#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;">&#40;</span><span style="color: #ff0000;">"devtools"</span><span style="color: #080;">&#41;</span>
devtools<span style="color: #080;">::</span><span style="">install_github</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">'R2DOC'</span>, <span style="color: #ff0000;">'davidgohel'</span><span style="color: #080;">&#41;</span>
devtools<span style="color: #080;">::</span><span style="">install_github</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">'R2DOCX'</span>, <span style="color: #ff0000;">'davidgohel'</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
 <h4 class="formatter-title">Les fonctions disponibles</h4> <br />
<ul class="formatter-ul">
<li class="formatter-li"><strong>addPlot</strong> pour ajouter un graphique.
</li><li class="formatter-li"><strong>addParagraph</strong> pour ajouter un paragraphe de textes
</li><li class="formatter-li"><strong>addTable</strong> pour ajouter des tables.
</li><li class="formatter-li"><strong>addHeader</strong> pour ajouter des titres.
</li><li class="formatter-li"><strong>addTOC</strong> pour ajouter une table des mati?res.
</li><li class="formatter-li"><strong>addPageBreak</strong> pour ajouter un saut de page.
</li><li class="formatter-li"><strong>addLineBreak</strong> pour ajouter un saut de ligne.
</li><li class="formatter-li"><strong>replaceText</strong> pour remplacer du texte.<br />
</li></ul><br />
<br />
 <h4 class="formatter-title">Votre premier document</h4> <br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #0000FF; font-weight: bold;">Sys.<span style="">setenv</span></span><span style="color: #080;">&#40;</span>NOAWT<span style="color: #080;">=</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#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;">&#40;</span>R2DOCX<span style="color: #080;">&#41;</span>
<span style="color: #228B22;"># Nom du fichier ? cr?er</span>
docx.<span style="">file</span> <span style="color: #080;"><-</span> <span style="color: #ff0000;">"document.docx"</span>
<span style="color: #228B22;"># Objet Docx ? manipuler</span>
doc <span style="color: #080;"><-</span> <span style="color: #0000FF; font-weight: bold;">new</span> <span style="color: #080;">&#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;">&#41;</span>
<span style="color: #228B22;">#ajouter une table</span>
doc <span style="color: #080;">=</span> addTable<span style="color: #080;">&#40;</span> doc, <span style="color: #CC9900; font-weight: bold;">iris</span><span style="color: #080;">&#91;</span><span style="color: #ff0000;">1</span><span style="color: #080;">:</span><span style="color: #ff0000;">10</span>,<span style="color: #080;">&#93;</span> <span style="color: #080;">&#41;</span>
<span style="color: #228B22;"># Ajouter du texte</span>
doc <span style="color: #080;"><-</span> addParagraph<span style="color: #080;">&#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;">&#41;</span>
<span style="color: #228B22;"># ajouter un graphique</span>
doc <span style="color: #080;">=</span> addPlot<span style="color: #080;">&#40;</span> doc, <span style="color: #0000FF; font-weight: bold;">function</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span> <span style="color: #0000FF; font-weight: bold;">plot</span><span style="color: #080;">&#40;</span> <span style="color: #0000FF; font-weight: bold;">rnorm</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">10</span><span style="color: #080;">&#41;</span>, <span style="color: #0000FF; font-weight: bold;">rnorm</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">10</span><span style="color: #080;">&#41;</span> <span style="color: #080;">&#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;">&#41;</span>
<span style="color: #228B22;"># Ecriture du fichier </span>
writeDoc<span style="color: #080;">&#40;</span> doc, docx.<span style="">file</span> <span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
 <h4 class="formatter-title">Cr?er un document word ? partir d'un template</h4> <br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;"># document word ? cr?er</span>
docx.<span style="">file</span> <span style="color: #080;">=</span> <span style="color: #ff0000;">"document.docx"</span>
<span style="color: #228B22;"># Document word ? utiliser comme 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;">&#40;</span> find.<span style="">package</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"R2DOCX"</span><span style="color: #080;">&#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;">&#41;</span>
<span style="color: #228B22;"># Cr?er un nouveau objet</span>
doc <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">new</span><span style="color: #080;">&#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;">&#41;</span>
<span style="color: #228B22;"># Dans le document de base, 2 mots cl?s existent- Rempla?ons les</span>
doc <span style="color: #080;">=</span> replaceText<span style="color: #080;">&#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;">&#41;</span>
doc <span style="color: #080;">=</span> replaceText<span style="color: #080;">&#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;">&#40;</span><span style="color: #080;">&#41;</span> <span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
 <h4 class="formatter-title">Titre principal</h4> <br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#Titre principale</span>
<span style="color: #228B22;">#**************************************</span>
doc <span style="color: #080;">=</span> addParagraph<span style="color: #080;">&#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;">&#41;</span>
doc <span style="color: #080;">=</span> addPageBreak<span style="color: #080;">&#40;</span> doc <span style="color: #080;">&#41;</span> <span style="color: #228B22;">#saut de page</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:500px; height:70px"><img src="https://www.sthda.com/french/french/upload/r2docx_titre.png"/></div></center>
<!-- END HTML --><br />
<br />
 <h4 class="formatter-title">Table des mati?res</h4> <br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#Table des mati?re (table of content : TOC)</span>
<span style="color: #228B22;">#**************************************</span>
<span style="color: #228B22;">#On vous demandera de mettre ? jour la table de mati?res</span>
<span style="color: #228B22;">#la pr?mi?re fois que le document sera ouvert</span>
doc <span style="color: #080;">=</span> addHeader<span style="color: #080;">&#40;</span>doc, <span style="color: #ff0000;">"Table des mati?res"</span>, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span><span style="color: #080;">;</span>
doc <span style="color: #080;">=</span> addTOC<span style="color: #080;">&#40;</span>doc<span style="color: #080;">&#41;</span>
doc <span style="color: #080;">=</span> addPageBreak<span style="color: #080;">&#40;</span> doc <span style="color: #080;">&#41;</span><span style="color: #228B22;">#saut de page</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:520px; height:185px"><img src="https://www.sthda.com/french/french/upload/r2docx_toc.png"/></div></center>
<!-- END HTML --><br />
<br />
 <h4 class="formatter-title">Ajout de textes (Normal et liste)</h4> <br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;"># Ajout de textes (normal and liste)</span>
<span style="color: #228B22;">#**************************************</span>
doc <span style="color: #080;">=</span> addHeader<span style="color: #080;">&#40;</span>doc, <span style="color: #ff0000;">"Dataset presentation"</span>, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span><span style="color: #080;">;</span>
<span style="color: #228B22;">#texte normal</span>
doc <span style="color: #080;">=</span> addParagraph<span style="color: #080;">&#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;">&#41;</span>
<span style="color: #228B22;">#liste non ordonn?e</span>
texts <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#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;">&#41;</span>
doc <span style="color: #080;">=</span> addParagraph<span style="color: #080;">&#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;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:515px; height:220px"><img src="https://www.sthda.com/french/french/upload/r2docx_texte.png"/></div></center>
<!-- END HTML --><br />
<br />
 <h4 class="formatter-title">Formatage conditionnel du texte</h4> <br />
<br />
La fonction <strong>addParagraph</strong> permet d'ajouter simplement du texte comme montr? ci-dessus. Elle peut ?galement ?tre utilis?e pour faire du remplacement de textes et du formatage conditionnel.<br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&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;">&#40;</span> color <span style="color: #080;">=</span> <span style="color: #ff0000;">"blue"</span> <span style="color: #080;">&#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;">&#40;</span> animal<span style="color: #080;">=</span> textProp, food<span style="color: #080;">=</span> textProp <span style="color: #080;">&#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;">&#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;">&#41;</span>
doc <span style="color: #080;"><-</span> addParagraph<span style="color: #080;">&#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;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:218px; height:45px"><img src="https://www.sthda.com/french/french/upload/r2docx_replacement.png"/></div></center>
<!-- END HTML --><br />
<br />
<span class="notice"><strong>La fonction textProperties</strong><br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">textProperties<span style="color: #080;">&#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;">&#41;</span></pre></pre></div><br />
<br />
<strong>color</strong>: couleur de la police; <strong>font.size</strong>: taille en pixel; <strong>font.weight</strong> : "normal" ou "bold"; <strong>font.style</strong>: "normal" ou "italic"; <strong>font.family</strong>: police.<br />
</span><br />
 <h4 class="formatter-title">Ajouter une table</h4> <br />
<br />
<strong><span style="color:blue;">Table simple: </span></strong><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;"># Ajouter une table</span>
<span style="color: #228B22;">#**************************************</span>
<span style="color: #228B22;"># Table utilisee</span>
<span style="color: #0000FF; font-weight: bold;">data</span><span style="color: #080;">&#40;</span> measured.<span style="">weights</span> <span style="color: #080;">&#41;</span>
doc <span style="color: #080;">=</span> addHeader<span style="color: #080;">&#40;</span>doc, <span style="color: #ff0000;">"Dataset"</span>, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span><span style="color: #080;">;</span>
doc <span style="color: #080;">=</span> addHeader<span style="color: #080;">&#40;</span>doc, <span style="color: #ff0000;">"Dataset first lines"</span>, <span style="color: #ff0000;">2</span><span style="color: #080;">&#41;</span><span style="color: #080;">;</span>
<span style="color: #228B22;">#Table simple</span>
doc <span style="color: #080;">=</span> addTable<span style="color: #080;">&#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;">&#40;</span> measured.<span style="">weights</span>, n <span style="color: #080;">=</span> <span style="color: #ff0000;">10</span> <span style="color: #080;">&#41;</span>
                , formats <span style="color: #080;">=</span> get.<span style="">light</span>.<span style="">formats</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>
<span style="color: #080;">&#41;</span>
doc <span style="color: #080;">=</span> addLineBreak<span style="color: #080;">&#40;</span> doc <span style="color: #080;">&#41;</span><span style="color: #228B22;">#saut de ligne</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:511px; height:278px"><img src="https://www.sthda.com/french/french/upload/r2docx_table.png"/></div></center>
<!-- END HTML --><br />
<br />
<strong><span style="color:blue;">Renommer les ent?tes de la table:</span></strong><br />
<br />
<strong>Avant</strong> d'avoir renomm? :<br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
doc <span style="color: #080;">=</span> addTable<span style="color: #080;">&#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;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:312px; height:147px"><img src="https://www.sthda.com/french/french/upload/r2docx_table2.png"/></div></center>
<!-- END HTML --><br />
<br />
<strong>Apr?s</strong> avoir renomm? :<br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
doc <span style="color: #080;">=</span> addTable<span style="color: #080;">&#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;">&#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;">&#41;</span> <span style="color: #228B22;"># columns labels to display</span>
<span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:462px; height:182px"><img src="https://www.sthda.com/french/french/upload/r2docx_table_header_label.png"/></div></center>
<!-- END HTML --><br />
<br />
<strong><span style="color:blue;">Table simple personnalis?e avec fusion des lignes :</span></strong><br />
<br />
Dans la table ci-dessous, les lignes sont fusionn?es sur la colonne 'day'. La colonne 'gender' est color?e en fonction du genre.<br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&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;">&#40;</span>doc, <span style="color: #ff0000;">"Dataset last lines"</span>, <span style="color: #ff0000;">2</span><span style="color: #080;">&#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;">&#40;</span> measured.<span style="">weights</span><span style="color: #080;">&#91;</span> <span style="color: #0000FF; font-weight: bold;">order</span><span style="color: #080;">&#40;</span>measured.<span style="">weights</span>$day<span style="color: #080;">&#41;</span>, <span style="color: #080;">&#93;</span>, n <span style="color: #080;">=</span> <span style="color: #ff0000;">20</span> <span style="color: #080;">&#41;</span>
doc <span style="color: #080;">=</span> addTable<span style="color: #080;">&#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;">&#40;</span><span style="color: #ff0000;">"day"</span><span style="color: #080;">&#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;">&#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;">&#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;">&#41;</span> <span style="color: #080;">&#41;</span>
<span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:311px; height:453px"><img src="https://www.sthda.com/french/french/upload/r2docx_table_merge_row.png"/></div></center>
<!-- END HTML --><br />
<br />
<strong><span style="color:blue;">Table personnalis?e avec ent?tes group?es:</span></strong><br />
<br />
Dans cette table les ent?tes ont ?t? renomm?es, des ent?tes group?es sont cr?es, le type des colonnes est pr?cis? (%, entier, caract?re, nombre d?cimal, date). Les valeurs de la colonne "Regularity" ont ?t? color?es en fonction de la valeur (couleur grise si < 0.5 et bleu si >= 0.5).<br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;"># customized table</span>
doc <span style="color: #080;">=</span> addHeader<span style="color: #080;">&#40;</span>doc, <span style="color: #ff0000;">"Dataset summary"</span>, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span><span style="color: #080;">;</span>
doc <span style="color: #080;">=</span> addTable<span style="color: #080;">&#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;">&#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;">&#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;">&#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;">&#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;">&#41;</span> 
<span style="color: #080;">&#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;">&#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;">&#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;">&#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;">&#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;">&#41;</span> <span style="color: #080;">&#41;</span> <span style="color: #228B22;"># customized font colors for column "regularity"</span>
<span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:530px; height:266px"><img src="https://www.sthda.com/french/french/upload/r2docx_table_customized.png"/></div></center>
<!-- END HTML --><br />
<br />
 <h4 class="formatter-title">Ajouter un graphique</h4> <br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;"># Ajouter un grahique</span>
<span style="color: #228B22;">#**************************************</span>
doc <span style="color: #080;">=</span> addPageBreak<span style="color: #080;">&#40;</span> doc <span style="color: #080;">&#41;</span>
doc <span style="color: #080;">=</span> addHeader<span style="color: #080;">&#40;</span>doc, <span style="color: #ff0000;">"Graphics"</span>, <span style="color: #ff0000;">1</span><span style="color: #080;">&#41;</span><span style="color: #080;">;</span>
doc <span style="color: #080;">=</span> addPlot<span style="color: #080;">&#40;</span> doc,
               <span style="color: #0000FF; font-weight: bold;">function</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span> <span style="color: #0000FF; font-weight: bold;">boxplot</span><span style="color: #080;">&#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;">&#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;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:516px; height:534px"><img src="https://www.sthda.com/french/french/upload/r2docx_plot.png"/></div></center>
<!-- END HTML --><br />
<br />
 <h4 class="formatter-title">Remplacement de texte</h4> <br />
<br />
Pour remplacer le mot cl? "AUTHOR", dans le document word, avec "Pearson" :<br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
doc <span style="color: #080;">=</span> replaceText<span style="color: #080;">&#40;</span> doc, <span style="color: #ff0000;">"AUTHOR"</span>, <span style="color: #ff0000;">"Pearson"</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
 <h4 class="formatter-title">Les styles de titres disponibles dans votre document</h4> <br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
doc <span style="color: #080;"><-</span> <span style="color: #0000FF; font-weight: bold;">new</span><span style="color: #080;">&#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;">&#41;</span>
styles<span style="color: #080;">&#40;</span> doc <span style="color: #080;">&#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;">&#40;</span>doc, stylenames <span style="color: #080;">=</span> <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#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;">&#41;</span> <span style="color: #080;">&#41;</span> 
doc <span style="color: #080;">=</span> addHeader<span style="color: #080;">&#40;</span> doc, <span style="color: #ff0000;">"title 1"</span>, <span style="color: #ff0000;">1</span> <span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
 <h4 class="formatter-title">Un document word complet</h4> <br />
<br />
<span class="success">Le script complet utilis? pour cr?e le document word suivant est t?l?chargeable ici : <a href="https://www.sthda.com/french/french/upload/r2docx.r">R2DOCX.r</a></span><br />
<br />
<!-- START HTML -->
<a href="https://www.sthda.com/french/french/upload/r2docx_word.pdf" class="embed" >Document word complet</a>
<!-- END HTML --><br />
<br />
 <h4 class="formatter-title">Voir Aussi</h4> <br />
<br />
<a href="https://www.sthda.com/french/french/articles/articles-7-60+r2xlsx-lire-ecrire-et-formater-un-document.php">R2XLSX : lire, ?crire et formater un document Excel dans R </a>]]></description>
			<pubDate>Sat, 06 Jul 2013 08:26:00 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[R et LaTeX: Sweave avec Rstudio]]></title>
			<link>https://www.sthda.com/french/articles/7-r/52-r-et-latex-sweave-avec-rstudio/</link>
			<guid>https://www.sthda.com/french/articles/7-r/52-r-et-latex-sweave-avec-rstudio/</guid>
			<description><![CDATA[<!-- START HTML -->
<ul id="toc"></ul>
<!-- END HTML --><br />
Sweave, un m?lange de R et du code LATEX,  permet de g?n?rer automatiquement un document contenant du code R, les r?sultats de ces codes et des commentaires. Ceci permet un gain de temps tr?s important permettant de g?n?rer des analyses reproductibles en cas d??ventuel changement des donn?es.<br />
<br />
<span class="warning"><br />
Un article sur LaTeX est disponible en suivant ce lien : <a href="https://www.sthda.com/french/french/articles/articles-19-53+latex.php">https://www.sthda.com/articles/articles-19-53+latex.php</a><br />
</span><br />
<br />
<h3 class="formatter-title">Logiciels r?quis</h3><br />
<br />
Il faudrait installer <a href="http://www.r-project.org/">R</a>, <a href="http://www.rstudio.com/">RStudio</a> et les outils Latex ( <a href="http://latex-project.org/ftp.html">http://latex-project.org/ftp.html</a>).<br />
<br />
<h3 class="formatter-title">Proc?dure</h3><br />
<br />
<strong>1- A partir de Rstudio, cr?er un fichier .Rnw en cliquant sur Fichier -> Nouveau -> R Sweave -> ?crire et enregistrez votre document </strong> : myfile.Rnw<br />
<strong>2- Compiler votre fichier en .pdf</strong><br />
<br />
<span class="notice">Lors de la compilation le fichier myfile.Rnw est tout d'abord converti en fichier LaTeX myfile.tex</span><br />
<br />
<h3 class="formatter-title">Squelette du fichier *.Rnw</h3><br />
<br />
Les codes R sont inclus entre les balises <<>>= et @ qui d?finissent ce que l'on appelle "chunk" :<br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cdocumentclass"><span style="color: #800000;">documentclass</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">a4paper</span><span style="color: #E02020; ">]{</span><span style="color: #2020C0; font-weight: normal;">article<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Ctitle"><span style="color: #800000;">title</span></a><span style="color: #E02020; ">{</span>Titre de mon document<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cauthor"><span style="color: #800000;">author</span></a><span style="color: #E02020; ">{</span>A Kass<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">latin1</span>]{inputenc</span><span style="color: #E02020; ">}</span> <span style="color: #2C922C; font-style: italic;">% Encodage pour ?criture de document en fran?ais</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">document</span></span><span style="color: #E02020; ">}</span> <span style="color: #2C922C; font-style: italic;">%D?but du document</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cmaketitle"><span style="color: #800000;">maketitle</span></a> <span style="color: #2C922C; font-style: italic;">%Permet la cr?ation d'une page de garde (Autheur, Titre, Date)</span>
.
.
<<>>=
VOTRE CODE R ICI
@
.
.
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">document</span></span><span style="color: #E02020; ">}</span> <span style="color: #2C922C; font-style: italic;">%Fin du document</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<h3 class="formatter-title">Les options basiques du chunk (morceaux de codes R) </h3><br />
<br />
<strong><span style="color:blue;">label :</span></strong> nom du chunk<br />
<strong><span style="color:blue;">echo :</span></strong> TRUE/FALSE. Affichage des commandes. Si TRUE, le code est affich?.  Valeur par d?faut : TRUE.<br />
<strong><span style="color:blue;">fig :</span></strong> TRUE/FALSE. Cr?ation d'un figure. Si TRUE, le graphique cr?? par le code est inclus. Valeur par d?faut : FALSE.<br />
<strong><span style="color:blue;">eval:</span></strong> TRUE/FALSE. Si FALSE, le morceau de code n'est pas ex?cut?. Valeur par d?faut : TRUE.<br />
<strong><span style="color:blue;">results:</span></strong> verbatim/hide/tex. Affichage des r?sultats des commandes. Si <strong>verbatim</strong>, le r?sultat est affich? comme dans l'environnement R. Si <strong>tex</strong>, le r?sultat du code est consid?r? comme du Latex et il est inclus comme tel. Si <strong>hide</strong>, le code est ex?cut? mais le r?sultat est non affich?. Valeur par defaut : verbatim. <br />
<strong><span style="color:blue;">prefix:</span></strong>TRUE/FALSE. If TRUE, les figures g?n?r?es et l'output ont le m?me prefix. Valeur par d?faut : TRUE.<br />
<strong><span style="color:blue;">prefix.string:</span></strong> prefix des fichiers g?n?r?s. La valeur par d?faut est le nom du fichier .Rnw.<br />
<strong><span style="color:blue;">include:</span></strong> TRUE/FALSE. Indique si le r?sultat text ou figure doit ?tre int?gr? automatiquement. <span style="color:red;">Utilisez include=FALSE, si le r?sultat doit appara?tre ? un endroit diff?rent du morceau de code (en pla?ant le r?sulat manuellement</span>).<br />
<strong><span style="color:blue;">eps:</span></strong> TRUE/FALSE. G?n?re des figures EPS.<br />
<strong><span style="color:blue;">width:</span></strong> Largeur des figures en inch (6).<br />
<strong><span style="color:blue;">height:</span></strong>Hauteur des figures en inch (6).<br />
<br />
<span class="notice"><br />
<br />
Les options peuvent ?tre configur?es globalement au d?but du fichier (et peuvent ?tre chang?es ailleurs au cas par cas) en utilisant la commande :<br />
<strong><span style="color:red;">\SweaveOpts(option1=value1,option2=value2,...)</span></strong><br />
<br />
Les options <strong><span style="color:red;">width</span></strong> et <strong><span style="color:red;">height</span></strong> correspondent ? la taille du graphique g?n?r? par R. Elles ne correspondent pas ? la taille du graphique inclus dans le document Latex.<br />
<br />
Pour changer la taille de la figure incluse dans le Latex, utiliser la commande :<br />
<strong><span style="color:red;">\setkeys{Gin}{width=0.8\textwidth}</span></strong> et changer 0.8 avec une autre valeur.<br />
On peut ?galement changer la taille manuellement en utilisant la commande d'inclusion manuelle: \includegraphics<br />
<br />
</span><br />
<br />
<br />
<br />
<h3 class="formatter-title">Exemple 1: Test statistique et graphique</h3><br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cdocumentclass"><span style="color: #800000;">documentclass</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">a4paper</span><span style="color: #E02020; ">]{</span><span style="color: #2020C0; font-weight: normal;">article<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Ctitle"><span style="color: #800000;">title</span></a><span style="color: #E02020; ">{</span>Sweave Example 1<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cauthor"><span style="color: #800000;">author</span></a><span style="color: #E02020; ">{</span>Alboukadel Kassambara<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">document</span><span style="color: #E02020; ">}</span>
<span style="color: #800000; font-weight: normal;">\SweaveOpts</span><span style="color: #E02020; ">{</span>concordance=TRUE<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cmaketitle"><span style="color: #800000;">maketitle</span></a>
Dans cet exemple, nous allons inclure un exemple du test kuskal wallis et un boxplot analysant le param?tre ozone en fonction du mois:
&nbsp;
<<>>=
data(airquality)
kruskal.test(Ozone ~ Month, data = airquality)
@
La table contient <span style="color: #800000; font-weight: normal;">\Sexpr</span><span style="color: #E02020; ">{</span>nrow(airquality)<span style="color: #E02020; ">}</span> lignes et <span style="color: #800000; font-weight: normal;">\Sexpr</span><span style="color: #E02020; ">{</span>ncol(airquality)<span style="color: #E02020; ">}</span> colonnes.
Le test montre que la distribution du param?tre Ozone varie significativement de mois en mois. 
Enfin, nous incluons le boxplot des donn?es :
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">center</span><span style="color: #E02020; ">}</span>
<<label=figure1, fig=TRUE,echo=FALSE>>=
boxplot(Ozone ~ Month, data = airquality)
@
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">center</span><span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">document</span></span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<br />
<span class="warning">\Sexpr{} (comme dans l'exemple 1) permet d?ex?cuter du code R dans la documentation.</span><br />
<br />
<!-- START HTML -->
<a href="https://www.sthda.com/french/french/upload/sweave_example_1_7e475.pdf" class="embed" >Resultat-Sweave-example-1</a>
<!-- END HTML --><br />
<br />
<br />
<h3 class="formatter-title">Exemples 2 : Positionnement manuel d'une figure</h3><br />
<br />
Dans cet exemple la figure n'est pas positionn?e ? l'endroit du code ex?cut?. Elle est plac?e manuellement, un peu plus bas, dans le document LaTeX.<br />
<br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cdocumentclass"><span style="color: #800000;">documentclass</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">a4paper</span><span style="color: #E02020; ">]{</span><span style="color: #2020C0; font-weight: normal;">article<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Ctitle"><span style="color: #800000;">title</span></a><span style="color: #E02020; ">{</span>Sweave Exemple 2<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">document</span><span style="color: #E02020; ">}</span>
<span style="color: #800000; font-weight: normal;">\SweaveOpts</span><span style="color: #E02020; ">{</span>concordance=TRUE, prefix.string=sthda<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cmaketitle"><span style="color: #800000;">maketitle</span></a>
<<label=histx,fig=TRUE,include=FALSE>>=
x<-rnorm(1000)
hist(x, col="lightblue", border="darkblue")
@
Dans cet exemple la figure n'est pas positionn?e ? l'endroit du code ex?cut?. Elle est plac?e manuellement, un peu plus bas, dans le document Latex.
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">figure</span><span style="color: #E02020; ">}[</span><span style="color: #C08020; font-weight: normal;">h!</span><span style="color: #E02020; ">]</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cincludegraphics"><span style="color: #800000;">includegraphics</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">width=5in</span><span style="color: #E02020; ">]{</span>sthda-histx<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Ccaption"><span style="color: #800000;">caption</span></a><span style="color: #E02020; ">{</span>Histogram of x.<span style="color: #E02020; ">}</span> <span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Clabel"><span style="color: #800000;">label</span></a><span style="color: #E02020; ">{</span>histogram-x<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">figure</span><span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">document</span></span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<br />
<span class="warning"><br />
Lorsqu'on utilise <strong>\begin{figure}</strong>, la figure commence sur une nouvelle page. Pour ?viter cela, utilisez <strong><span style="color:blue;">\begin{figure}[h!]</span></strong><br />
</span><br />
<br />
<span class="success"><br />
<!-- START HTML -->
<a href="https://www.sthda.com/french/french/upload/sweave_example_2bis.pdf"><img src="https://www.sthda.com/french/french/sthda/images/pdf.png" class="valign_middle"/>Cliquez ici pour voir le PDF</a>
<!-- END HTML --><br />
</span><br />
<br />
<br />
<h3 class="formatter-title">Plusieurs graphiques dans un chunk</h3><br />
<br />
Il faudrait utiliser pdf() ou postscript () pour les cr?er et puis les ajouter dans le Latex.<br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">center</span><span style="color: #E02020; ">}</span>
<<results=tex, echo=FALSE>>=
set.seed(672)
for(i in 1:4)<span style="color: #E02020; ">{</span>
file=paste("myfile", i, ".pdf", sep="")
pdf(file=file, paper="special", width=6, height=6)
plot(rnorm(100)+i)
dev.off()
cat("<span style="color: #E02020; ">\\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cincludegraphics"><span style="color: #800000;">includegraphics</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">height=2in, width=2in</span><span style="color: #E02020; ">]{</span>"
, file, "<span style="color: #E02020; ">}</span><span style="color: #800000; font-weight: normal;">\n</span>", sep="")
<span style="color: #E02020; ">}</span>
@
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">center</span></span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<h3 class="formatter-title">Rappeler un morceau de code R par son nom</h3><br />
<span class="formatter-code">Code LATEXT :</span><div class="code"><pre style="display:inline;"><pre class="latext" style="font-family:monospace;">&nbsp;
<<a>>=
x <- 10
@
<<b>>=
x+y
@
<<c>>=
<<a>>
y <- 20
<<b>>
@</pre></pre></div><br />
<br />
<br />
<h3 class="formatter-title">Les figures </h3><br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">figure</span><span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">center</span><span style="color: #E02020; ">}</span>
<<label=fig1,fig=TRUE,echo=FALSE>>=
hist(rnorm(1000,0,1)
@
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">center</span><span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Ccaption"><span style="color: #800000;">caption</span></a><span style="color: #E02020; ">{</span>Scatter Plot with Regression Line<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Clabel"><span style="color: #800000;">label</span></a><span style="color: #E02020; ">{</span>fig:one<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">figure</span></span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<br />
<h3 class="formatter-title">Les tables</h3><br />
<br />
Installer le package xtable :<br />
<span class="formatter-code">Code R :</span><div class="code"><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;">&#40;</span><span style="color: #ff0000;">"xtable"</span><span style="color: #080;">&#41;</span></pre></pre></div><br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<<results=tex>>=
library(xtable)
x <- rnorm(100)
y <- 4 + 3 * x + rnorm(100, 0, 2)
lmodel <- lm(y ~ x)
lan <- anova(lmodel)
xtable(lmodel, caption = "La legende.",
label = "tab:coef" )
@
&nbsp;</pre></pre></div><br />
<br />
<span class="notice">Il est possible de faire reference a la table en utilisant le code :<br />
\ref{tab:coef} dans le code LATEX.</span><br />
<br />
<!-- START HTML -->
<center><div class="highlight_3d" style="width:520px; height:290px"><img src="https://www.sthda.com/french/french/upload/sweave_table.png"/></div></center>
<!-- END HTML --><br />
<br />
<br />
<h3 class="formatter-title">Exemple 3 : R?f?rencement des Tables et Figures dans la documentation</h3><br />
<br />
<span class="formatter-code">Code LATEX :</span><div class="code"><pre style="display:inline;"><pre class="latex" style="font-family:monospace;">&nbsp;
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cdocumentclass"><span style="color: #800000;">documentclass</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">a4paper</span><span style="color: #E02020; ">]{</span><span style="color: #2020C0; font-weight: normal;">article<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">document</span><span style="color: #E02020; ">}</span>
<span style="color: #800000; font-weight: normal;">\SweaveOpts</span><span style="color: #E02020; ">{</span>concordance=TRUE<span style="color: #E02020; ">}</span>
<<echo=false,results=hide>>=
library(lattice)
library(xtable)
data(cats, package="MASS")
@
A linear regression model of heart weight by sex and gender can be
fitted in R using the command
<<>>=
lm1 = lm(Hwt~Bwt*Sex, data=cats)
lm1
@
Tests for significance of the coefficients are shown in
Table~<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cref"><span style="color: #800000;">ref</span></a><span style="color: #E02020; ">{</span>tab:coef<span style="color: #E02020; ">}</span>, a scatter plot including the regression lines is
shown in Figure~<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cref"><span style="color: #800000;">ref</span></a><span style="color: #E02020; ">{</span>fig:cats<span style="color: #E02020; ">}</span>.
<span style="color: #800000; font-weight: normal;">\SweaveOpts</span><span style="color: #E02020; ">{</span>echo=false<span style="color: #E02020; ">}</span>
<<results=tex>>=
xtable(lm1, caption="Linear regression model for cats data.",
label="tab:coef")
@
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">figure</span><span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Ccentering"><span style="color: #800000;">centering</span></a>
<<fig=TRUE,width=12,height=6>>=
trellis.par.set(col.whitebg())
print(xyplot(Hwt~Bwt|Sex, data=cats, type=c("p", "r")))
@
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Ccaption"><span style="color: #800000;">caption</span></a><span style="color: #E02020; ">{</span>The cats data from package MASS.<span style="color: #E02020; ">}</span>
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Clabel"><span style="color: #800000;">label</span></a><span style="color: #E02020; ">{</span>fig:cats<span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">figure</span><span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">center</span><span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">center</span><span style="color: #E02020; ">}</span>
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #0000D0; font-weight: normal;">document</span></span><span style="color: #E02020; ">}</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<span class="success"><br />
<!-- START HTML -->
<a href="https://www.sthda.com/french/french/upload/sweave_example_3.pdf"><img src="https://www.sthda.com/french/french/sthda/images/pdf.png" class="valign_middle"/>Cliquez ici pour voir le PDF</a>
<!-- END HTML --><br />
</span><br />
<br />
<br />
<h3 class="formatter-title">Extraction du code R ? partir d'un document Latex</h3><br />
<br />
La commande suivante permet d'extraire tous les codes R d'un fichier Latex :<br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;"><span style="color: #0000FF; font-weight: bold;">Stangle</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"myfile.Rnw"</span><span style="color: #080;">&#41;</span></pre></pre></div><br />
Un fichier .R est cr??.<br />
<br />
<br />
<h3 class="formatter-title">Une fonction R pour compiler du Sweave en pdf</h3><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#usage :  ezSweave("sweave-example-4", preview=T)</span>
ezSweave<span style="color: #080;"><-</span><span style="color: #0000FF; font-weight: bold;">function</span><span style="color: #080;">&#40;</span>filename, extension<span style="color: #080;">=</span><span style="color: #ff0000;">'Rnw'</span>, preview<span style="color: #080;">=</span>TRUE, encoding<span style="color: #080;">=</span><span style="color: #ff0000;">"ISO-8859-1"</span><span style="color: #080;">&#41;</span>
<span style="color: #080;">&#123;</span>
  <span style="color: #0000FF; font-weight: bold;">Sweave</span><span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">paste</span><span style="color: #080;">&#40;</span>filename,<span style="color: #ff0000;">"."</span>, extension,sep<span style="color: #080;">=</span><span style="color: #ff0000;">''</span><span style="color: #080;">&#41;</span>, encoding<span style="color: #080;">=</span>encoding<span style="color: #080;">&#41;</span>
  <span style="color: #0000FF; font-weight: bold;">library</span><span style="color: #080;">&#40;</span>tools<span style="color: #080;">&#41;</span>
  texi2dvi<span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">paste</span><span style="color: #080;">&#40;</span>filename,<span style="color: #ff0000;">".tex"</span>,sep<span style="color: #080;">=</span><span style="color: #ff0000;">''</span><span style="color: #080;">&#41;</span>, <span style="color: #0000FF; font-weight: bold;">pdf</span><span style="color: #080;">=</span>TRUE<span style="color: #080;">&#41;</span>
  <span style="color: #0000FF; font-weight: bold;">if</span> <span style="color: #080;">&#40;</span>preview<span style="color: #080;">&#41;</span>
  <span style="color: #080;">&#123;</span>
    <span style="color: #0000FF; font-weight: bold;">system</span><span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">paste</span><span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">options</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">'pdfviewer'</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#91;</span><span style="color: #080;">&#91;</span><span style="color: #ff0000;">1</span><span style="color: #080;">&#93;</span><span style="color: #080;">&#93;</span>,<span style="color: #ff0000;">' '</span>,filename,<span style="color: #ff0000;">'.pdf'</span>,sep<span style="color: #080;">=</span><span style="color: #ff0000;">''</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>
  <span style="color: #080;">&#125;</span>
<span style="color: #080;">&#125;</span>
&nbsp;</pre></pre></div><br />
<br />
<h3 class="formatter-title">Divers</h3><br />
<strong><span style="color:blue;"><br />
Sweaveinput{AnotherFile.Rnw} </span></strong>: Inclusion d'un autre fichier . Analogue ? la commande Latex \input ou \include<br />
<strong><span style="color:blue;">SweaveOpts{keep.source=TRUE}</span></strong> : Permet de garder les commentaires dans le code<br />
<strong><span style="color:blue;">SweaveOpts{}</span></strong> : Permet de changer les options par d?faut]]></description>
			<pubDate>Sat, 08 Jun 2013 10:09:00 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[RCMDR GGPLOT2]]></title>
			<link>https://www.sthda.com/french/articles/7-r/47-rcmdr-ggplot2/</link>
			<guid>https://www.sthda.com/french/articles/7-r/47-rcmdr-ggplot2/</guid>
			<description><![CDATA[<a href="http://www.r-bloggers.com/rggplot2r-bloggersrcmdrplugin-kmggplot2_0-0-3-is-on-cran-now/">http://www.r-bloggers.com/rggplot2r-bloggersrcmdrplugin-kmggplot2_0-0-3-is-on-cran-now/</a>]]></description>
			<pubDate>Sun, 09 Dec 2012 12:33:06 +0100</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[Importing Data Into R from Different Sources]]></title>
			<link>https://www.sthda.com/french/articles/7-r/46-importing-data-into-r-from-different-sources/</link>
			<guid>https://www.sthda.com/french/articles/7-r/46-importing-data-into-r-from-different-sources/</guid>
			<description><![CDATA[<a href="http://www.r-bloggers.com/importing-data-into-r-from-different-sources/">http://www.r-bloggers.com/importing-data-into-r-from-different-sources/</a>]]></description>
			<pubDate>Fri, 07 Dec 2012 15:41:17 +0100</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[Qgraph]]></title>
			<link>https://www.sthda.com/french/articles/7-r/45-qgraph/</link>
			<guid>https://www.sthda.com/french/articles/7-r/45-qgraph/</guid>
			<description><![CDATA[<a href="http://www.r-bloggers.com/qgraph-version-1-1-0-and-how-to-simply-make-a-gui-using-rpanel/">http://www.r-bloggers.com/qgraph-version-1-1-0-and-how-to-simply-make-a-gui-using-rpanel/</a><br />
<br />
<!-- START HTML -->

<img src="http://sachaepskamp.com/wp-content/uploads/2012/09/qgraphGUI1-1024x726.png"  style="width:50% "/>

<!-- END HTML -->]]></description>
			<pubDate>Sat, 29 Sep 2012 13:40:01 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[Lecture de donn?es de cytometrie (format FCS) avec R]]></title>
			<link>https://www.sthda.com/french/articles/7-r/44-lecture-de-donnees-de-cytometrie-format-fcs-avec-r/</link>
			<guid>https://www.sthda.com/french/articles/7-r/44-lecture-de-donnees-de-cytometrie-format-fcs-avec-r/</guid>
			<description><![CDATA[<h3 class="formatter-title"> Installation du package prada</h3><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #0000FF; font-weight: bold;">source</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"http://bioconductor.org/biocLite.R"</span><span style="color: #080;">&#41;</span>
biocLite<span style="color: #080;">&#40;</span><span style="color: #ff0000;">"prada"</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
La fonction readFCS peut ?tre utilis?e pour lire les fichiers au format FCS.<br />
<br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #0000FF; font-weight: bold;">library</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">'prada'</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;">#selection d'un fichier</span>
<span style="color: #0000FF; font-weight: bold;">file</span><span style="color: #080;">=</span><span style="color: #0000FF; font-weight: bold;">system.<span style="">file</span></span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"extdata"</span>, <span style="color: #ff0000;">"fas-Bcl2-plate323-04-04.A01"</span>, package<span style="color: #080;">=</span><span style="color: #ff0000;">"prada"</span><span style="color: #080;">&#41;</span><span style="color: #080;">;</span>
&nbsp;
<span style="color: #228B22;">#lecture du fichier</span>
<span style="color: #0000FF; font-weight: bold;">data</span> <span style="color: #080;"><-</span> readFCS<span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">file</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<span class="notice"> La fonction readFCS retourne un objet de type cytoFrame.</span><br />
<br />
A ce stade deux fonctions peuvent ?tre appliqu?es sur l'objet de type cytoFrame. Ce sont les fonctions <em>description</em> et  <em>exprs</em><br />
<br />
La fonction <em><span style="color:blue;">description</span></em> donne la description de l'exp?rience :<br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#description de data</span>
description<span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">data</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
La fonction <span style="color:blue;"><em>exprs</em></span> renvoie une matrice contenant les intensit?s de fluorescence. Les lignes correspondent aux cellules et les colonnes correspondent aux diff?rents canaux de fluorescence.<br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
exprs<span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">data</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#91;</span><span style="color: #ff0000;">1</span><span style="color: #080;">:</span><span style="color: #ff0000;">6</span>,<span style="color: #080;">&#93;</span>
&nbsp;</pre></pre></div><br />
<br />
<!-- START HTML -->
<pre>
     FSC-H SSC-H FL1-H FL2-H FL3-H FL2-A FL4-H Time
[1,]   467   532    87   146    14     0   449    2
[2,]   437   431    28   145    16     0   478    2
[3,]   410   214     0    30     7     0   358    2
[4,]   433   204     7    92     0     0   440    2
[5,]   436   413    58   143     0     0   460    2
[6,]   450   230    11    53     0     0   474    2

</pre>
<!-- END HTML --><br />
<br />
<span class="notice"><br />
Les donn?es pr?sent?es ci-dessus ont ?t? acquises par "CellQuest Pro  4.0.2" <br />
</span><br />
<br />
<br />
<h3 class="formatter-title">Visualisation des donn?es : FSC/SSC</h3><br />
<br />
<span class="success"><br />
FSC (Forward light scatter) : Mesure de la taille des cellules<br />
SSC(Sideward light scatter) : Mesure de la granulosit? des cellules<br />
</span><br />
<br />
Faire un nuage de points SSC-H en fonction de FSC-H :<br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#1- SSC en fonction de FSC</span>
x<span style="color: #080;"><-</span>exprs<span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">data</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#91;</span>, <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"FSC-H"</span>, <span style="color: #ff0000;">"SSC-H"</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#93;</span>
<span style="color: #0000FF; font-weight: bold;">plot</span><span style="color: #080;">&#40;</span>x, pch<span style="color: #080;">=</span><span style="color: #ff0000;">20</span>, <span style="color: #0000FF; font-weight: bold;">col</span><span style="color: #080;">=</span><span style="color: #0000FF; font-weight: bold;">densCols</span><span style="color: #080;">&#40;</span>x<span style="color: #080;">&#41;</span>, cex<span style="color: #080;">=</span><span style="color: #ff0000;">0.5</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
Pour ajouter un 'gate' automatiquement (?liminant les d?bris cellulaire sur le coin du graphique au niveau de l'origine 0) :<br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#2- Gate scalefac=2</span>
nfit<span style="color: #080;"><-</span>fitNorm2<span style="color: #080;">&#40;</span>x, scalefac<span style="color: #080;">=</span><span style="color: #ff0000;">2</span><span style="color: #080;">&#41;</span>
plotNorm2<span style="color: #080;">&#40;</span>nfit, ellipse<span style="color: #080;">=</span>TRUE, cex<span style="color: #080;">=</span><span style="color: #ff0000;">0.5</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;">#3-Gate scalefac=3</span>
nfit<span style="color: #080;"><-</span>fitNorm2<span style="color: #080;">&#40;</span>x, scalefac<span style="color: #080;">=</span><span style="color: #ff0000;">3</span><span style="color: #080;">&#41;</span>
plotNorm2<span style="color: #080;">&#40;</span>nfit, ellipse<span style="color: #080;">=</span>TRUE, cex<span style="color: #080;">=</span><span style="color: #ff0000;">0.5</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<span class="warning">Le param?tre scalefac permet de contr?ler la largeur de l'ellipse.</span><br />
<br />
<br />
<p class="float-left"> 1-<img src="https://www.sthda.com/french/french/upload/fsc_ssc.png" alt="" class="valign_" /></p><p class="float-left"> 2-<img src="https://www.sthda.com/french/french/upload/fsc_scc_scalefac2.png" alt="" class="valign_" /> </p><p class="float-left"> 3-<img src="https://www.sthda.com/french/french/upload/fsc_ssc_scalefac3.png" alt="" class="valign_" /> </p><br />
<br />
<!-- START HTML -->
<div style="clear:both;"></div>
<!-- END HTML --><br />
<br />
<br />
<span class="notice"><br />
La fonction <em>densCols</em> permet de colorer les points en fonction de leur densit? locale.<br />
</span><br />
<br />
<span class="success"><br />
La valeur nfit retourn?e par la fonction fitNorm2 est une liste. Un des ?l?ments de la liste est un vecteur logic nfit$sel. Il a la m?me longueur que le nombre de points et une valeur TRUE indique que le point est compris dans l'ellipse.<br />
</span><br />
<br />
<br />
Pour s?lectionner les points contenus dans l'ellipse :<br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
data.<span style="">selected</span><span style="color: #080;"><-</span><span style="color: #0000FF; font-weight: bold;">data</span><span style="color: #080;">&#91;</span>nfit$sel,<span style="color: #080;">&#93;</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
Le code R suivant permet de faire le graphique du canal FL4-H en fonction de FL1-H en utilisant les donn?es d'origines (data)  et les donn?es gat?es (data.selected)<br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
&nbsp;
myplot<span style="color: #080;"><-</span><span style="color: #0000FF; font-weight: bold;">function</span><span style="color: #080;">&#40;</span>x<span style="color: #080;">&#41;</span><span style="color: #080;">&#123;</span>
ex<span style="color: #080;"><-</span>exprs<span style="color: #080;">&#40;</span>x<span style="color: #080;">&#41;</span><span style="color: #080;">&#91;</span>, <span style="color: #0000FF; font-weight: bold;">c</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"FL1-H"</span>, <span style="color: #ff0000;">"FL4-H"</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#93;</span>
<span style="color: #0000FF; font-weight: bold;">plot</span><span style="color: #080;">&#40;</span>ex, pch<span style="color: #080;">=</span><span style="color: #ff0000;">20</span>, <span style="color: #0000FF; font-weight: bold;">col</span><span style="color: #080;">=</span><span style="color: #0000FF; font-weight: bold;">densCols</span><span style="color: #080;">&#40;</span>ex<span style="color: #080;">&#41;</span>, cex<span style="color: #080;">=</span><span style="color: #ff0000;">0.5</span><span style="color: #080;">&#41;</span>
<span style="color: #080;">&#125;</span>
&nbsp;
myplot<span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">data</span><span style="color: #080;">&#41;</span>
myplot<span style="color: #080;">&#40;</span>data.<span style="">selected</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<p class="float-left"> <img src="https://www.sthda.com/french/french/upload/fl4_fl1.png" alt="" class="valign_" /></p>  <p class="float-left"><img src="https://www.sthda.com/french/french/upload/fl4_fl1_gate.png" alt="" class="valign_" /></p> <br />
<!-- START HTML -->
<div style="clear:both;"></div>
<!-- END HTML -->]]></description>
			<pubDate>Thu, 30 Aug 2012 19:59:01 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[Exploration des matrices de corr?lation]]></title>
			<link>https://www.sthda.com/french/articles/7-r/43-exploration-des-matrices-de-correlation/</link>
			<guid>https://www.sthda.com/french/articles/7-r/43-exploration-des-matrices-de-correlation/</guid>
			<description><![CDATA[<a href="http://www.r-bloggers.com/more-on-exploring-correlations-in-r/">http://www.r-bloggers.com/more-on-exploring-correlations-in-r/</a>]]></description>
			<pubDate>Wed, 29 Aug 2012 18:40:29 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[Cr?er une image .gif anim?e avec R et ImageMagick]]></title>
			<link>https://www.sthda.com/french/articles/7-r/42-creer-une-image-gif-animee-avec-r-et-imagemagick/</link>
			<guid>https://www.sthda.com/french/articles/7-r/42-creer-une-image-gif-animee-avec-r-et-imagemagick/</guid>
			<description><![CDATA[<p class="float-left"><img src="https://www.sthda.com/french/french/upload/animated_image_with_r_and_imagemagick2.gif" alt="" class="valign_" /></p><br />
Le but de ce tutoriel est de vous montrer les ?tapes ? suivre pour cr?er une image gif anim?e avec R et ImageMagick. Il vous faut d'abord installer <a href="http://www.imagemagick.org/">ImageMagick</a> si vous ne l'avez pas d?j?.<br />
<br />
<!-- START HTML -->
<div style="clear:both"></div>
<!-- END HTML --><br />
<br />
<span class="notice"><br />
Il est aussi possible de cr?er des images .gif anim?es en utilisant uniquement R, gr?ce ? la fonction write.gif() du package <a href="http://cran.r-project.org/web/packages/caTools/index.html">caTools </a><br />
</span><br />
<br />
<span class="warning"><br />
Les fonctions d?crites dans ce tutotriel ont ?t? test?es sur Mac OS X 10.6.8 avec R 2.13<br />
</span><br />
<br />
<br />
<br />
<br />
<h3 class="formatter-title">Exemple 1 : Cr?er un compte ? rebours </h3><br />
<br />
<br /><h4 class="formatter-title">code R </h4><br /><br />
<br />
Le compte ? rebours d?compte de 10 ? 1.  Nous allons le cr?er en 4 ?tapes.<br />
<br />
1 - Cr?ation d'un r?pertoire de travail propre que l'on va appeler 'examples'.<br />
2 - Cr?ation des images png, chacune contenant un chiffre ( de 10 ? 1).<br />
3 - Cr?ation d'une seule image .gif en utilisant ImageMagick<br />
4- suppression des fichiers png dont on n'a plus besoin<br />
<br />
<strong>Ci-dessous  le code R correspondant :</strong><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #228B22;">#cr?ation d'un r?pertoire de travail</span>
<span style="color: #0000FF; font-weight: bold;">dir.<span style="">create</span></span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"examples"</span><span style="color: #080;">&#41;</span> <span style="color: #228B22;">#cr?ation du r?pertoire</span>
<span style="color: #0000FF; font-weight: bold;">setwd</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"examples"</span><span style="color: #080;">&#41;</span> <span style="color: #228B22;"># on se place dans le repertoire </span>
&nbsp;
<span style="color: #228B22;"># Cr?ation des fichiers .png  du compte ? rebours de 10 ? "GO!"</span>
<span style="color: #0000FF; font-weight: bold;">png</span><span style="color: #080;">&#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;">&#41;</span>
  <span style="color: #0000FF; font-weight: bold;">for</span> <span style="color: #080;">&#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;">&#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;">&#41;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#123;</span>
    <span style="color: #0000FF; font-weight: bold;">plot.<span style="">new</span></span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>
    <span style="color: #0000FF; font-weight: bold;">text</span><span style="color: #080;">&#40;</span>.5, .5, i, cex <span style="color: #080;">=</span> <span style="color: #ff0000;">6</span><span style="color: #080;">&#41;</span>
  <span style="color: #080;">&#125;</span>
<span style="color: #0000FF; font-weight: bold;">dev.<span style="">off</span></span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;"># Conversion des fichiers .png en un seul fichier .gif avec ImageMagick</span>
<span style="color: #0000FF; font-weight: bold;">system</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"/opt/local/bin/convert -delay 80 *.png example_1.gif"</span><span style="color: #080;">&#41;</span>
<span style="color: #228B22;"># On supprime les fichiers .png</span>
<span style="color: #0000FF; font-weight: bold;">file.<span style="">remove</span></span><span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">list.<span style="">files</span></span><span style="color: #080;">&#40;</span>pattern<span style="color: #080;">=</span><span style="color: #ff0000;">".png"</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
<span class="success"><br />
1- La fonction system() ex?cute la commande de conversion comme dans un Terminal (console shell). J'ai mis le chemin absolu vers la commande <strong>convert.</strong> Dans mon cas c'est : <strong>/opt/local/bin/convert</strong>.  Dans certains cas la commande system("convert -delay 80 *.png example_1.gif") marche.<br />
<br />
2- le flag -delay correspond au temps d'affichage entre deux images ( c'est la vitesse de l'animation).<br />
3-La partie "%02d" du nom de fichier permet d'incr?menter automatiquement le nom des fichiers .png gener?s<br />
</span><br />
<br />
<br /><h4 class="formatter-title">R?sultat</h4><br /><br />
<br />
<strong><span style="color:blue;">Le r?sulat est le suivant :</span></strong><br />
<br />
 <img src="https://www.sthda.com/french/french/upload/animated_gif_with_r_and_imagemagick.gif" alt="" class="valign_" /><br />
<br />
<br />
<br />
<h3 class="formatter-title">Exemple 2 : cr?ation d'un graphique 3D</h3><br />
<br />
Nous allons cr?er une surface 3D pour visualiser un mod?le lin?aire en utilisant le package<strong> lattice</strong>. Des graphiques 3D peuvent ?tre cr??s ?galement avec le package <strong>rgl</strong>.<br />
<br />
<br />
<br /><h4 class="formatter-title">Code R</h4><br /><br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #0000FF; font-weight: bold;">library</span><span style="color: #080;">&#40;</span>lattice<span style="color: #080;">&#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;">&#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;">&#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
&nbsp;
<span style="color: #0000FF; font-weight: bold;">png</span><span style="color: #080;">&#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;">&#41;</span>
  <span style="color: #0000FF; font-weight: bold;">for</span> <span style="color: #080;">&#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;">&#40;</span><span style="color: #ff0000;">0</span>, <span style="color: #ff0000;">350</span> , <span style="color: #ff0000;">10</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#123;</span>
    <span style="color: #0000FF; font-weight: bold;">print</span><span style="color: #080;">&#40;</span>wireframe<span style="color: #080;">&#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;">&#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;">&#41;</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>
  <span style="color: #080;">&#125;</span>
<span style="color: #0000FF; font-weight: bold;">dev.<span style="">off</span></span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;"># conversion du pdf en gif, en utilisant ImageMagick</span>
<span style="color: #0000FF; font-weight: bold;">system</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">"/opt/local/bin/convert -delay 40 *.png example_2_reduced.gif"</span><span style="color: #080;">&#41;</span>
&nbsp;
<span style="color: #228B22;"># On efface les fichiers png</span>
<span style="color: #0000FF; font-weight: bold;">file.<span style="">remove</span></span><span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">list.<span style="">files</span></span><span style="color: #080;">&#40;</span>pattern<span style="color: #080;">=</span><span style="color: #ff0000;">".png"</span><span style="color: #080;">&#41;</span><span style="color: #080;">&#41;</span>
&nbsp;
&nbsp;</pre></pre></div><br />
<br />
<br />
<br /><h4 class="formatter-title">R?sultat</h4><br /><br />
<br />
<img src="https://www.sthda.com/french/french/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 17:40:01 +0200</pubDate>
			
		</item>
		
		<item>
			<title><![CDATA[Importation des donn?es dans R ? partir d'internet]]></title>
			<link>https://www.sthda.com/french/articles/7-r/41-importation-des-donnees-dans-r-a-partir-d-internet/</link>
			<guid>https://www.sthda.com/french/articles/7-r/41-importation-des-donnees-dans-r-a-partir-d-internet/</guid>
			<description><![CDATA[<h3 class="formatter-title">Importer un fichier *.txt ? partir d'internet</h3><br />
<br />
Importation du fichier decathlon.txt ? partir du site STHDA :<br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&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;">&#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;">&#41;</span> <span style="color: #228B22;">#Importation des donn?es</span>
<span style="color: #0000FF; font-weight: bold;">print</span><span style="color: #080;">&#40;</span><span style="color: #0000FF; font-weight: bold;">data</span><span style="color: #080;">&#41;</span> <span style="color: #228B22;"># Affichage des donn?es</span>
&nbsp;</pre></pre></div><br />
<br />
<br />
<h3 class="formatter-title">Importer un fichier .Rdata ? partir d'internet</h3><br />
<br />
Pour cela, il faut d'abord cr?er une connexion avec la fonction <strong><span style="color:blue;">url</span></strong> de R. On importe ensuite la connexion.<br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
con<span style="color: #080;"><-</span><span style="color: #0000FF; font-weight: bold;">url</span><span style="color: #080;">&#40;</span><span style="color: #ff0000;">'https://www.sthda.com/upload/decathlon.rdata'</span><span style="color: #080;">&#41;</span> <span style="color: #228B22;"># cr?ation d'une connexion</span>
<span style="color: #0000FF; font-weight: bold;">load</span><span style="color: #080;">&#40;</span>con<span style="color: #080;">&#41;</span> <span style="color: #228B22;">#importation des donn?es</span>
<span style="color: #0000FF; font-weight: bold;">close</span><span style="color: #080;">&#40;</span>con<span style="color: #080;">&#41;</span> <span style="color: #228B22;">#fermeture de la connexion</span>
<span style="color: #0000FF; font-weight: bold;">print</span><span style="color: #080;">&#40;</span>d<span style="color: #080;">&#41;</span> <span style="color: #228B22;"># Affichage des donn?es</span>
&nbsp;</pre></pre></div><br />
<br />
<h3 class="formatter-title">T?l?chargement d'un fichier avec R</h3><br />
<br />
Pour t?l?charger un fichier ? partir d'internet avec R, on utilise la fonction <span style="color:blue;">download.file</span> :<br />
<br />
<span class="formatter-code">Code R :</span><div class="code"><pre style="display:inline;"><pre class="r" style="font-family:monospace;">&nbsp;
<span style="color: #0000FF; font-weight: bold;">download.<span style="">file</span></span><span style="color: #080;">&#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;">&#41;</span>
&nbsp;</pre></pre></div><br />
<br />
Le fichier sera t?l?charg? et enregistr? dans le r?pertoire courant avec le nom decathlon.rdata]]></description>
			<pubDate>Sat, 04 Aug 2012 18:16:01 +0200</pubDate>
			
		</item>
		
	</channel>
</rss>
