<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>ProgrammingR</title>
	
	<link>http://www.programmingr.com</link>
	<description>Beginner to advanced resources for the R programming language</description>
	<lastBuildDate>Wed, 12 Jun 2013 16:58:37 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/ProgrammingR" /><feedburner:info uri="programmingr" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>ProgrammingR</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>Global Indicator Analyses with R</title>
		<link>http://feedproxy.google.com/~r/ProgrammingR/~3/jHlH2R7G4s4/</link>
		<comments>http://www.programmingr.com/content/global-indicator-analyses-with-r/#comments</comments>
		<pubDate>Mon, 13 May 2013 12:45:24 +0000</pubDate>
		<dc:creator>bryan</dc:creator>
				<category><![CDATA[Articles]]></category>

		<guid isPermaLink="false">http://www.programmingr.com/?p=927</guid>
		<description><![CDATA[<p>I was recently asked by a client to create a large number of &#8220;proof of concept&#8221; visualizations that illustrated the power of R for compiling and analyzing disparate datasets. The client was specifically interested in automated analyses of global data. A little research led me to the WDI package. The WDI package is a tool [...]</p><p>The post <a href="http://www.programmingr.com/content/global-indicator-analyses-with-r/">Global Indicator Analyses with R</a> appeared first on <a href="http://www.programmingr.com">ProgrammingR</a>.</p><div class='yarpp-related-rss'>

More like this:<ol>
<li><a href='http://www.programmingr.com/content/helpful-statistical-references/' rel='bookmark' title='Helpful statistical references'>Helpful statistical references</a></li>
<li><a href='http://www.programmingr.com/content/online-r-programming-resources/' rel='bookmark' title='Online R programming resources'>Online R programming resources</a></li>
<li><a href='http://www.programmingr.com/content/controlling-margins-and-axes-oma-and-mgp/' rel='bookmark' title='Controlling margins and axes with oma and mgp'>Controlling margins and axes with oma and mgp</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>I was recently asked by a client to create a large number of &#8220;proof of concept&#8221; visualizations that illustrated the power of R for compiling and analyzing disparate datasets. The client was specifically interested in automated analyses of global data. A little research led me to the <code>WDI</code> package.</p>
<p>The WDI package is a tool to &#8220;search, extract and format data from the World Bank&#8217;s World Development Indicators&#8221; (<a title="WDI Help" href="http://cran.r-project.org/web/packages/WDI/index.html">WDI help</a>). In essence, it is an R-based wrapper for the World Bank Economic Indicators Data API. When used in combination with the information on the <a title="World Bank data portal" href="http://data.worldbank.org/data-catalog/world-development-indicators">World Bank data portal</a> it provides easy access to thousands of global datapoints. </p>
<p>Here is an example use case that illustrates how simple and easy it is to use, especially with a little help from the <code>countrycode</code> and <code>ggplot2</code> packages:</p>
<pre class="brush: r; title: ; notranslate">
library(WDI)
library(ggplot2)
library(countrycode)

# Use the WDIsearch function to get a list of fertility rate indicators
indicatorMetaData &lt;- WDIsearch(&quot;Fertility rate&quot;, field=&quot;name&quot;, short=FALSE)

# Define a list of countries for which to pull data
countries &lt;- c(&quot;United States&quot;, &quot;Britain&quot;, &quot;Sweden&quot;, &quot;Germany&quot;)

# Convert the country names to iso2c format used in the World Bank data
iso2cNames &lt;- countrycode(countries, &quot;country.name&quot;, &quot;iso2c&quot;)

# Pull data for each countries for the first two fertility rate indicators, for the years 2001 to 2011
wdiData &lt;- WDI(iso2cNames, indicatorMetaData[1:2,1], start=2001, end=2011)

# Pull out indicator names
indicatorNames &lt;- indicatorMetaData[1:2, 1]

# Create trend charts for the first two indicators
for (indicatorName in indicatorNames) { 
  pl &lt;- ggplot(wdiData, aes(x=year, y=wdiData[,indicatorName], group=country, color=country))+
    geom_line(size=1)+
    scale_x_continuous(name=&quot;Year&quot;, breaks=c(unique(wdiData[,&quot;year&quot;])))+
    scale_y_continuous(name=indicatorName)+
    scale_linetype_discrete(name=&quot;Country&quot;)+
    theme(legend.title=element_blank())+
    ggtitle(paste(indicatorMetaData[indicatorMetaData[,1]==indicatorName, &quot;name&quot;], &quot;\n&quot;))
  ggsave(paste(indicatorName, &quot;.jpg&quot;, sep=&quot;&quot;), pl)
}
</pre>
<p><a href="http://www.programmingr.com/wp-content/uploads/2013/05/SP.DYN_.TFRT_.IN_-e1368447690806.jpg"><img src="http://www.programmingr.com/wp-content/uploads/2013/05/SP.DYN_.TFRT_.IN_-300x251.jpg" alt="WDI package visualization 1" width="300" height="251" class="aligncenter size-medium wp-image-928" /></a><a href="http://www.programmingr.com/wp-content/uploads/2013/05/SP.ADO_.TFRT_-e1368447750359.jpg"><img src="http://www.programmingr.com/wp-content/uploads/2013/05/SP.ADO_.TFRT_-300x251.jpg" alt="WDI package visualization 2" width="300" height="251" class="aligncenter size-medium wp-image-929" /></a></p>
<p>This code can be adapted to quickly pull and visualize many pieces of data. Even if you don&#8217;t have an analytic need for the WDI data, the ease of access and depth of information available via the <code>WDI</code> package make them perfect for creating toy examples for classes, presentations or blogs, or conveying the power and depth of available R packages.</p>
<div class="shr-publisher-927"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic --><div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 0px;padding: 0px;font-style:italic"><br />
<strong>Looking for an R programmer or statistical programming consultant? ProgrammingR offers consulting services. For more information contact us at info@programmingr.com.</strong>
<br />
<br />
ProgrammingR offers two ways for you to stay up to date. To be notified when new articles and book reviews are posted, subscribe to the <a href="http://feeds.feedburner.com/ProgrammingR" title="ProgrammingR articles and book reviews feed">ProgrammingR articles feed</a>. To be notified when new R-based job listings are posted, subscribe to the <a href="http://feeds.feedburner.com/ProgrammingRjobs" title="ProgrammingR jobs feed">ProgrammingR jobs feed</a>. You may also want to <a href="http://www.programmingr.com/contact" title="Post an R consultant listing">post an R consultant listing</a>, <a href="http://www.programmingr.com/category/stype/r-consultants" title="ProgrammingR consultant listings">hire an R consultant</a>, or ask a question in the <a href="http://www.programmingr.com/forum/" title="ProgrammingR forums">forums</a>.
<br />
<br />
</div><p>The post <a href="http://www.programmingr.com/content/global-indicator-analyses-with-r/">Global Indicator Analyses with R</a> appeared first on <a href="http://www.programmingr.com">ProgrammingR</a>.</p><div class='yarpp-related-rss'>
<p>More like this:</p><ol>
<li><a href='http://www.programmingr.com/content/helpful-statistical-references/' rel='bookmark' title='Helpful statistical references'>Helpful statistical references</a></li>
<li><a href='http://www.programmingr.com/content/online-r-programming-resources/' rel='bookmark' title='Online R programming resources'>Online R programming resources</a></li>
<li><a href='http://www.programmingr.com/content/controlling-margins-and-axes-oma-and-mgp/' rel='bookmark' title='Controlling margins and axes with oma and mgp'>Controlling margins and axes with oma and mgp</a></li>
</ol>
</div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/ProgrammingR?a=jHlH2R7G4s4:5IeSsjfAmck:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/ProgrammingR?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ProgrammingR?a=jHlH2R7G4s4:5IeSsjfAmck:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/ProgrammingR?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ProgrammingR/~4/jHlH2R7G4s4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.programmingr.com/content/global-indicator-analyses-with-r/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.programmingr.com/content/global-indicator-analyses-with-r/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=global-indicator-analyses-with-r</feedburner:origLink></item>
		<item>
		<title>SPARQL with R in less than 5 minutes</title>
		<link>http://feedproxy.google.com/~r/ProgrammingR/~3/CDuxujjMT3U/</link>
		<comments>http://www.programmingr.com/content/sparql-with-r/#comments</comments>
		<pubDate>Wed, 23 Jan 2013 18:13:07 +0000</pubDate>
		<dc:creator>bryan</dc:creator>
				<category><![CDATA[Articles]]></category>

		<guid isPermaLink="false">http://www.programmingr.com/?p=857</guid>
		<description><![CDATA[<p>In this article we&#8217;ll get up and running on the Semantic Web in less than 5 minutes using SPARQL with R. We&#8217;ll begin with a brief introduction to the Semantic Web then cover some simple steps for downloading and analyzing government data via a SPARQL query with the SPARQL R package. What is the Semantic [...]</p><p>The post <a href="http://www.programmingr.com/content/sparql-with-r/">SPARQL with R in less than 5 minutes</a> appeared first on <a href="http://www.programmingr.com">ProgrammingR</a>.</p><div class='yarpp-related-rss'>

More like this:<ol>
<li><a href='http://www.programmingr.com/content/helpful-statistical-references/' rel='bookmark' title='Helpful statistical references'>Helpful statistical references</a></li>
<li><a href='http://www.programmingr.com/content/online-r-programming-resources/' rel='bookmark' title='Online R programming resources'>Online R programming resources</a></li>
<li><a href='http://www.programmingr.com/content/positioning-charts-fig-and-fin/' rel='bookmark' title='Positioning charts with fig and fin'>Positioning charts with fig and fin</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>In this article we&#8217;ll get up and running on the Semantic Web in less than 5 minutes using SPARQL with R. We&#8217;ll begin with a brief introduction to the Semantic Web then cover some simple steps for downloading and analyzing government data via a SPARQL query with the SPARQL R package.</p>
<h3>What is the Semantic Web?</h3>
<p>To newcomers, the Semantic Web can sound mysterious and ominous. By most accounts, it&#8217;s the wave of the future, but it&#8217;s hard to pin down exactly what it is. This is in part because the Semantic Web has been evolving for some time but is just now beginning to take a  recognizable shape (DuCharme 2011).  Detailed definitions of the Semantic Web abound, but simply put, it is an attempt to structure the unstructured data on the Web and to formalize the standards that make that structure possible. In other words, it&#8217;s an attempt to create a data definition for the Web.</p>
<p>The primary method for accessing data made available on the Semantic Web is via SPARQL queries to a data provider&#8217;s endpoint. Endpoints are portals to data that a provider has made available for querying. This data is often published in <a title="RDF description" href="http://en.wikipedia.org/wiki/Resource_Description_Framework">RDF</a> format. If you&#8217;re familiar with using SQL to query a database, then the idea of using a query language (SPARQL) to access a structured database or data repository (the endpoint) should be common ground. The practice is also similar to webscraping an XML document with a known structure.</p>
<h3>The Semantic Web and R</h3>
<p>A primary goal of the Semantic Web movement is to enable machines and applications to interface using standardized data definitions. As the Semantic Web grows, it will be ripe for mining with statistical programs that already lend themselves to automation &#8211; such as R. To that end, let&#8217;s dive into a simple query that will illustrate 75% of what you&#8217;ll be doing on the Semantic Web.</p>
<h3>Accessing Data.gov datasets with SPARQL</h3>
<p>We&#8217;ll use data at the Data.gov endpoint for this example. Data.gov has a wide array of public data available, making this example generalizable to many other datasets. One of the key challenges of querying a Semantic Web resource is knowing what data is accessible. Sometimes the best way to find this out is to run a simple query with no filters that returns only a few results or to directly view the RDF. Fortunately, information on the data available via Data.gov has been cataloged on a <a title="Data.gov catalog" href="http://data-gov.tw.rpi.edu/wiki/Data.gov_Catalog">wiki hosted by Rensselaer.</a> We&#8217;ll use Dataset 1187 for this example. It&#8217;s simple and has interesting data &#8211; the total number of wildfires and acres burned per year, 1960-2008.</p>
<h3>R code</h3>
<p>Data.gov provides a <a title="Virtuoso" href="http://www.w3.org/2001/sw/wiki/OpenLink_Virtuoso">Virtuoso</a> endpoint <a title="Data.gov Virtuoso endpoint" href="http://services.data.gov/sparql">here</a>, which we could use to submit manual queries. But we want to automate this process, so we&#8217;ll use <a title="SPARQL R package on LinkedScience.prg" href="http://www.programmingr.com/topic/importing-famos-format/">Willem Robert van Hage and Tomi Kauppinen&#8217;s</a> <a title="SPARQL R package" href="http://cran.r-project.org/web/packages/SPARQL/index.html">SPARQL package</a> to access the endpoint.</p>
<pre class="brush: r; title: ; notranslate">
library(SPARQL) # SPARQL querying package
library(ggplot2)

# Step 1 - Set up preliminaries and define query
# Define the data.gov endpoint
endpoint &lt;- &quot;http://services.data.gov/sparql&quot;

# create query statement
query &lt;-
&quot;PREFIX  dgp1187: &lt;http://data-gov.tw.rpi.edu/vocab/p/1187/&gt;
SELECT ?ye ?fi ?ac
WHERE {
?s dgp1187:year ?ye .
?s dgp1187:fires ?fi .
?s dgp1187:acres ?ac .
}&quot;

# Step 2 - Use SPARQL package to submit query and save results to a data frame
qd &lt;- SPARQL(endpoint,query)
df &lt;- qd$results

# Step 3 - Prep for graphing

# Numbers are usually returned as characters, so convert to numeric and create a
# variable for &quot;average acres burned per fire&quot;
str(df)
df &lt;- as.data.frame(apply(df, 2, as.numeric))
str(df)

df$avgperfire &lt;- df$ac/df$fi

# Step 4 - Plot some data
ggplot(df, aes(x=ye, y=avgperfire, group=1)) +
geom_point() +
stat_smooth() +
scale_x_continuous(breaks=seq(1960, 2008, 5)) +
xlab(&quot;Year&quot;) +
ylab(&quot;Average acres burned per fire&quot;)

ggplot(df, aes(x=ye, y=fi, group=1)) +
geom_point() +
stat_smooth() +
scale_x_continuous(breaks=seq(1960, 2008, 5)) +
xlab(&quot;Year&quot;) +
ylab(&quot;Number of fires&quot;)

ggplot(df, aes(x=ye, y=ac, group=1)) +
geom_point() +
stat_smooth() +
scale_x_continuous(breaks=seq(1960, 2008, 5)) +
xlab(&quot;Year&quot;) +
ylab(&quot;Acres burned&quot;)

# In less than 5 mins we have written code to download just
# the data we need and have an interesting result to explore!
</pre>
<p>If you&#8217;re familiar with R, the only foreign code is that in Steps 1 and 2. There we define the location of the endpoint and write the SPARQL query. If you have experience with SQL, you&#8217;ll notice that SPARQL syntax is very similar. The most notable exception is that Semantic Web data is structured around chunks of data that contain three pieces of information. In Semantic Web terminology these three pieces of information as referred to as subjects, predicates and objects and together they are called &#8220;triples&#8221;. A SPARQL query returns pieces of these chunks of data; exactly which pieces are returned depends on the query. We have defined a prefix which establishes that everywhere we say &#8220;dgp1187:&#8221; we want it to know that we mean &#8220;&lt;http://data-gov.tw.rpi.edu/vocab/p/1187/&gt;&#8221;. This saves us from having to retype long URIs every time we need to reference them. URIs are used extensively on the Semantic Web, so this is a very helpful feature.</p>
<p>In English, our query says, &#8220;Give me the values for the attributes &#8220;fires&#8221;, &#8220;acres&#8221; and &#8220;year&#8221; wherever they are defined, and assign them to variables named &#8220;fi&#8221;, &#8220;ac&#8221; and &#8220;ye&#8221; respectively. Also fetch the location of the value in the data as a variable called ?s and merge the other data values by that variable.&#8221;</p>
<p>The last bit of the query is the closest we get to SPARQL magic. Because the variable ?s is present in each clause of the query, our fire, acres burned, and year data will be merged by that variable. This is somewhat analogous to saying, &#8220;Once you&#8217;ve found a row of data that contains information on the number of fires, also return the acres burned and year data from that row and list them on the same row in the new dataset.&#8221; (If the logic behind the query isn&#8217;t yet clear, or you&#8217;re ready to see how you can make this query more advanced or parsimonious, the text and web pages in the &#8220;References&#8221; and &#8220;Additional Information&#8221; sections at the end of this article are good resources for learning SPARQL.)</p>
<p>Once defined, we pass this query and endpoint information to the SPARQL function which returns an object with two values &#8211; a data frame of the new data and a list of namespaces. At this point, we&#8217;re concerned with the data frame, so we pull it out in the last line of Step 2.<a href="http://www.programmingr.com/wp-content/uploads/2013/01/AvgFiresPerYear.png"><img class="alignright size-full wp-image-864" title="AvgFiresPerYear" src="http://www.programmingr.com/wp-content/uploads/2013/01/AvgFiresPerYear.png" alt="Data.gov SPARQL example" width="428" height="256" /></a></p>
<p>From that point on we treat the data just like any other dataset. Running some quick graphs, we see that although the number of fires per year have decreased, the number of acres burned per fire and the number of acres burned per year increased considerably between 1975 and 2008. (Despite being born in 1975, I disavow any responsibility for this trend.)</p>
<h3>Summary</h3>
<p>In a few short minutes, using R and SPARQL, we wrote code to pull and do initial analyses on an interesting government dataset. Hopefully, the power of R for mining the Semantic Web is evident from this simple example. As more data becomes available in RDF format, automated solutions for mining and analyzing the Semantic Web will become more and more useful.</p>
<p>Reference:</p>
<p>DuCharme, Bob (2011-07-14). Learning SPARQL . OReilly Media.</p>
<p>Additional Information:</p>
<p><a title="Basic Data.gov query tutorial" href="http://data-gov.tw.rpi.edu/wiki/A_crash_course_in_SPARQL">Basic tutorial on querying Data.gov</a></p>
<p><a title="Data.gov query tutorial" href="http://data-gov.tw.rpi.edu/wiki/How_to_build_a_data-gov_demo">More detailed tutorial on querying Data.gov</a></p>
<div class="shr-publisher-857"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic --><div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 0px;padding: 0px;font-style:italic"><br />
<strong>Looking for an R programmer or statistical programming consultant? ProgrammingR offers consulting services. For more information contact us at info@programmingr.com.</strong>
<br />
<br />
ProgrammingR offers two ways for you to stay up to date. To be notified when new articles and book reviews are posted, subscribe to the <a href="http://feeds.feedburner.com/ProgrammingR" title="ProgrammingR articles and book reviews feed">ProgrammingR articles feed</a>. To be notified when new R-based job listings are posted, subscribe to the <a href="http://feeds.feedburner.com/ProgrammingRjobs" title="ProgrammingR jobs feed">ProgrammingR jobs feed</a>. You may also want to <a href="http://www.programmingr.com/contact" title="Post an R consultant listing">post an R consultant listing</a>, <a href="http://www.programmingr.com/category/stype/r-consultants" title="ProgrammingR consultant listings">hire an R consultant</a>, or ask a question in the <a href="http://www.programmingr.com/forum/" title="ProgrammingR forums">forums</a>.
<br />
<br />
</div><p>The post <a href="http://www.programmingr.com/content/sparql-with-r/">SPARQL with R in less than 5 minutes</a> appeared first on <a href="http://www.programmingr.com">ProgrammingR</a>.</p><div class='yarpp-related-rss'>
<p>More like this:</p><ol>
<li><a href='http://www.programmingr.com/content/helpful-statistical-references/' rel='bookmark' title='Helpful statistical references'>Helpful statistical references</a></li>
<li><a href='http://www.programmingr.com/content/online-r-programming-resources/' rel='bookmark' title='Online R programming resources'>Online R programming resources</a></li>
<li><a href='http://www.programmingr.com/content/positioning-charts-fig-and-fin/' rel='bookmark' title='Positioning charts with fig and fin'>Positioning charts with fig and fin</a></li>
</ol>
</div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/ProgrammingR?a=CDuxujjMT3U:ElMlFAcE6QE:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/ProgrammingR?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ProgrammingR?a=CDuxujjMT3U:ElMlFAcE6QE:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/ProgrammingR?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ProgrammingR/~4/CDuxujjMT3U" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.programmingr.com/content/sparql-with-r/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.programmingr.com/content/sparql-with-r/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=sparql-with-r</feedburner:origLink></item>
		<item>
		<title>R for Dummies – De Vries and Meys (2012)</title>
		<link>http://feedproxy.google.com/~r/ProgrammingR/~3/vhDdgyX5xpw/</link>
		<comments>http://www.programmingr.com/content/r-for-dummies-de-vries-and-meys-2012/#comments</comments>
		<pubDate>Sun, 23 Dec 2012 02:34:42 +0000</pubDate>
		<dc:creator>bryan</dc:creator>
				<category><![CDATA[Book reviews]]></category>

		<guid isPermaLink="false">http://www.programmingr.com/?p=823</guid>
		<description><![CDATA[<p>The for Dummies series has been around since 1991. (A bit of trivia, DOS for Dummies was the first title.) I&#8217;ve owned a few books in the series and have been adequately impressed with most of them, but when I learned there was an R for Dummies I was immediately skeptical. Possibly I was skeptical [...]</p><p>The post <a href="http://www.programmingr.com/content/r-for-dummies-de-vries-and-meys-2012/">R for Dummies &#8211; De Vries and Meys (2012)</a> appeared first on <a href="http://www.programmingr.com">ProgrammingR</a>.</p><div class='yarpp-related-rss'>

More like this:<ol>
<li><a href='http://www.programmingr.com/content/data-manipulation-r-spector-2008/' rel='bookmark' title='Data Manipulation with R &#8211; Spector (2008)'>Data Manipulation with R &#8211; Spector (2008)</a></li>
<li><a href='http://www.programmingr.com/content/bayesian-computation-r-albert-2009/' rel='bookmark' title='Bayesian Computation with R &#8211; Albert (2009)'>Bayesian Computation with R &#8211; Albert (2009)</a></li>
<li><a href='http://www.programmingr.com/content/the-art-of-r-programming-matloff-2011/' rel='bookmark' title='The Art of R Programming &#8211; Matloff (2011)'>The Art of R Programming &#8211; Matloff (2011)</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>The <em>for Dummies</em> series has been around since 1991. (A bit of trivia, <em>DOS for Dummies</em> was the first title.) I&#8217;ve owned a few books in the series and have been adequately impressed with most of them, but when I learned there was an <em>R for Dummies</em> I was immediately skeptical. Possibly I was skeptical because R has a steep learning curve and many idiosyncrasies, so the idea of an <em>R for Dummies</em> text seemed oxymoronic &#8211; it&#8217;s difficult to imagine a (successfully) dumbed-down version of an introductory R text. But if you&#8217;re familiar with the <em>for Dummies</em> series, you already know that the moniker is just for marketing. In reality, these books usually do a good job of distilling a topic down to the important components a new user needs to know. This edition is no exception.</p>
<div style="float:right; background-color: lightblue; border: 1px solid darkblue; padding:5px; margin: 2px; width: 325px;"><strong>Title:</strong> R for Dummies<br /><strong>Author(s):</strong> Andrie de Vries and Joris Meys<br /><strong>Publisher/Date:</strong> Wiley and Sons/2012<br /><strong>Statistics level:</strong> Not Applicable <br /><strong>Programming level:</strong> Beginner <br /><strong>Overall recommendation:</strong>  Highly Recommended</div>
<p>The core topic areas that <em>R for Dummies </em>covers should come as no surprise: A basic overview of R and its capabilities, importing data into R, writing and debugging functions, summarizing data and graphing. In addition, there are sections covering potentially frustrating tasks for beginners such as working with dates and multidimensional arrays.</p>
<p>I am a big fan of periodically reviewing the fundamentals. I pick up introductory texts every once and a while to make sure I haven&#8217;t forgotten anything important and <em>R for Dummies</em> is a nice edition to my library for that reason.</p>
<p>One thing that sets this book apart from other currently available introductory R texts is that it covers a couple of recent and important developments in R coding &#8211; namely the RStudio development environment and ggplot2 graphics.</p>
<p>If you&#8217;re not familiar with the <em>for Dummies</em> series, it is important to note that they are written in a specific informal style, which is in stark contrast to most R texts. (For reference, the style is more similar to The R Inferno than the ggplot2 manual.) You can get a sense of this style by <a href="http://www.amazon.com/gp/product/1119962846/ref=as_li_ss_tl?ie=UTF8&#038;tag=booktast-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=1119962846">browsing a few pages on Amazon</a><img src="http://www.assoc-amazon.com/e/ir?t=booktast-20&#038;l=as2&#038;o=1&#038;a=1119962846" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> to see if you find it helpful or distracting. On the other hand, <em>R for Dummies</em> has a more polished feel than many R texts I&#8217;ve read. I didn&#8217;t encounter any of the frustrating and distracting editing errors that are common in some R texts. </p>
<p><a href="http://www.programmingr.com/wp-content/uploads/2013/01/RforDummiesImg.jpg"><img src="http://www.programmingr.com/wp-content/uploads/2013/01/RforDummiesImg-238x300.jpg" alt="" title="RforDummiesImage" width="238" height="300" class="alignright size-medium wp-image-851" /></a><em>R for Dummies</em> is primarily focused on R as a programming language, so for the most part, statistical analyses are presented only as a means of illustrating programming techniques. Given its focus on programming and fundamentals, this book is highly recommended for someone with little to no experience in R who wants to learn R programming. Intermediate to advanced R programmers like myself who want a current review of the fundamentals, might also find it useful. </p>
<p>I might also recommend <em>R for Dummies</em> to experienced users of other programming languages who are new to R. The discussion of basic programming concepts, such as control flow, is minimal and focused primarily on details specific to R. It is not recommended for those looking to learn statistics in conjunction with R. </p>
<p>The current price of $20 USD puts it in the middle price range for texts of its kind. It is available as a paperback or Kindle text.</p>
<div class="shr-publisher-823"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic --><div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 0px;padding: 0px;font-style:italic"><br />
<strong>Looking for an R programmer or statistical programming consultant? ProgrammingR offers consulting services. For more information contact us at info@programmingr.com.</strong>
<br />
<br />
ProgrammingR offers two ways for you to stay up to date. To be notified when new articles and book reviews are posted, subscribe to the <a href="http://feeds.feedburner.com/ProgrammingR" title="ProgrammingR articles and book reviews feed">ProgrammingR articles feed</a>. To be notified when new R-based job listings are posted, subscribe to the <a href="http://feeds.feedburner.com/ProgrammingRjobs" title="ProgrammingR jobs feed">ProgrammingR jobs feed</a>. You may also want to <a href="http://www.programmingr.com/contact" title="Post an R consultant listing">post an R consultant listing</a>, <a href="http://www.programmingr.com/category/stype/r-consultants" title="ProgrammingR consultant listings">hire an R consultant</a>, or ask a question in the <a href="http://www.programmingr.com/forum/" title="ProgrammingR forums">forums</a>.
<br />
<br />
</div><p>The post <a href="http://www.programmingr.com/content/r-for-dummies-de-vries-and-meys-2012/">R for Dummies &#8211; De Vries and Meys (2012)</a> appeared first on <a href="http://www.programmingr.com">ProgrammingR</a>.</p><div class='yarpp-related-rss'>
<p>More like this:</p><ol>
<li><a href='http://www.programmingr.com/content/data-manipulation-r-spector-2008/' rel='bookmark' title='Data Manipulation with R &#8211; Spector (2008)'>Data Manipulation with R &#8211; Spector (2008)</a></li>
<li><a href='http://www.programmingr.com/content/bayesian-computation-r-albert-2009/' rel='bookmark' title='Bayesian Computation with R &#8211; Albert (2009)'>Bayesian Computation with R &#8211; Albert (2009)</a></li>
<li><a href='http://www.programmingr.com/content/the-art-of-r-programming-matloff-2011/' rel='bookmark' title='The Art of R Programming &#8211; Matloff (2011)'>The Art of R Programming &#8211; Matloff (2011)</a></li>
</ol>
</div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/ProgrammingR?a=vhDdgyX5xpw:lBPNcFcyzQ8:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/ProgrammingR?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ProgrammingR?a=vhDdgyX5xpw:lBPNcFcyzQ8:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/ProgrammingR?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ProgrammingR/~4/vhDdgyX5xpw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.programmingr.com/content/r-for-dummies-de-vries-and-meys-2012/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.programmingr.com/content/r-for-dummies-de-vries-and-meys-2012/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=r-for-dummies-de-vries-and-meys-2012</feedburner:origLink></item>
		<item>
		<title>Helper Function Contest</title>
		<link>http://feedproxy.google.com/~r/ProgrammingR/~3/cXvA3CLe7qY/</link>
		<comments>http://www.programmingr.com/content/helper-function-contest/#comments</comments>
		<pubDate>Sun, 02 Dec 2012 20:28:57 +0000</pubDate>
		<dc:creator>bryan</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Site news]]></category>

		<guid isPermaLink="false">http://www.programmingr.com/?p=783</guid>
		<description><![CDATA[<p>Just in time for the holidays, ProgrammingR is giving you the opportunity to win a gift for yourself or someone who loves R. And in the spirit of the holidays, you&#8217;ll also be giving back to the R community. In the last article I presented two helper functions I use often. I also teased an [...]</p><p>The post <a href="http://www.programmingr.com/content/helper-function-contest/">Helper Function Contest</a> appeared first on <a href="http://www.programmingr.com">ProgrammingR</a>.</p><div class='yarpp-related-rss'>

More like this:<ol>
<li><a href='http://www.programmingr.com/content/helpful-statistical-references/' rel='bookmark' title='Helpful statistical references'>Helpful statistical references</a></li>
<li><a href='http://www.programmingr.com/content/online-r-programming-resources/' rel='bookmark' title='Online R programming resources'>Online R programming resources</a></li>
<li><a href='http://www.programmingr.com/content/r-helper-functions/' rel='bookmark' title='R Helper Functions'>R Helper Functions</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Just in time for the holidays, ProgrammingR is giving you the opportunity to win a gift for yourself or someone who loves R. And in the spirit of the holidays, you&#8217;ll also be giving back to the R community.</p>
<p>In <a href="http://www.programmingr.com/content/r-helper-functions/" title="R helper functions">the last article</a> I presented two helper functions I use often. I also teased an upcoming, related event. This is that event. </p>
<p>The premise is simple. Post your favorite (original) R helper function(s). We&#8217;ll select 3-5 of the top candidates and put those to a popular vote. The author of the function with the most votes at the end of the contest will receive their choice of one of the three books below.  </p>
<div style="float:left;padding:0px 0px 0px 150px;"><a href="http://www.amazon.com/gp/product/1593273843/ref=as_li_ss_il?ie=UTF8&#038;camp=1789&#038;creative=390957&#038;creativeASIN=1593273843&#038;linkCode=as2&#038;tag=booktast-20"><img border="0" src="http://ws.assoc-amazon.com/widgets/q?_encoding=UTF8&#038;ASIN=1593273843&#038;Format=_SL110_&#038;ID=AsinImage&#038;MarketPlace=US&#038;ServiceVersion=20070822&#038;WS=1&#038;tag=booktast-20" ></a><img src="http://www.assoc-amazon.com/e/ir?t=booktast-20&#038;l=as2&#038;o=1&#038;a=1593273843" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></div>
<div style="float:left;padding:0px 150px 0px 150px;"><a href="http://www.amazon.com/gp/product/0596809158/ref=as_li_ss_il?ie=UTF8&#038;camp=1789&#038;creative=390957&#038;creativeASIN=0596809158&#038;linkCode=as2&#038;tag=booktast-20"><img border="0" src="http://ws.assoc-amazon.com/widgets/q?_encoding=UTF8&#038;ASIN=0596809158&#038;Format=_SL110_&#038;ID=AsinImage&#038;MarketPlace=US&#038;ServiceVersion=20070822&#038;WS=1&#038;tag=booktast-20"></a><img src="http://www.assoc-amazon.com/e/ir?t=booktast-20&#038;l=as2&#038;o=1&#038;a=0596809158" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></div>
<div style="padding:0px 0px 0px 0px;"><a href="http://www.amazon.com/gp/product/1449309925/ref=as_li_ss_il?ie=UTF8&#038;camp=1789&#038;creative=390957&#038;creativeASIN=1449309925&#038;linkCode=as2&#038;tag=booktast-20"><img border="0" src="http://ws.assoc-amazon.com/widgets/q?_encoding=UTF8&#038;ASIN=1449309925&#038;Format=_SL110_&#038;ID=AsinImage&#038;MarketPlace=US&#038;ServiceVersion=20070822&#038;WS=1&#038;tag=booktast-20" style="border:solid gray 1px;"></a><img src="http://www.assoc-amazon.com/e/ir?t=booktast-20&#038;l=as2&#038;o=1&#038;a=1449309925" width="1" height="1" border="0" alt="" style="border:none; !important; margin:0px !important;" /></div>
<p>The contest begins now. Post your submissions to <a href="http://www.programmingr.com/topic/useful-R-helper-functions/" title="Useful R helper functions">this forum</a> or use the comments below to point us to a post on your site written specifically for this contest. You can enter as many of your helper functions as you like between now and midnight 12/14/12 Eastern Standard Time. We&#8217;ll choose the finalists and allow approximately a week of voting for them starting soon after 12/14. The author of the function with the most votes at the end of the popular voting will be the winner.  </p>
<p>I look forward to seeing what the ProgrammingR community has to offer!</p>
<p><strong>Some Important Guidelines:</strong><br />
<em>By participating, you agree to be bound by the decisions of the ProgrammingR staff in all contest-related aspects, but especially in regard to who the finalists are and the winner is. We will do our best to run a fair and impartial contest, but we can&#8217;t guarantee the originality of every submission, for example. You also certify that you have the right to publicly post any code you submit and that we can repost it on the site. If you point us to a submission on your site and your code is selected as a finalist, we&#8217;ll need to verify that it actually is your site. </em></p>
<div class="shr-publisher-783"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic --><div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 0px;padding: 0px;font-style:italic"><br />
<strong>Looking for an R programmer or statistical programming consultant? ProgrammingR offers consulting services. For more information contact us at info@programmingr.com.</strong>
<br />
<br />
ProgrammingR offers two ways for you to stay up to date. To be notified when new articles and book reviews are posted, subscribe to the <a href="http://feeds.feedburner.com/ProgrammingR" title="ProgrammingR articles and book reviews feed">ProgrammingR articles feed</a>. To be notified when new R-based job listings are posted, subscribe to the <a href="http://feeds.feedburner.com/ProgrammingRjobs" title="ProgrammingR jobs feed">ProgrammingR jobs feed</a>. You may also want to <a href="http://www.programmingr.com/contact" title="Post an R consultant listing">post an R consultant listing</a>, <a href="http://www.programmingr.com/category/stype/r-consultants" title="ProgrammingR consultant listings">hire an R consultant</a>, or ask a question in the <a href="http://www.programmingr.com/forum/" title="ProgrammingR forums">forums</a>.
<br />
<br />
</div><p>The post <a href="http://www.programmingr.com/content/helper-function-contest/">Helper Function Contest</a> appeared first on <a href="http://www.programmingr.com">ProgrammingR</a>.</p><div class='yarpp-related-rss'>
<p>More like this:</p><ol>
<li><a href='http://www.programmingr.com/content/helpful-statistical-references/' rel='bookmark' title='Helpful statistical references'>Helpful statistical references</a></li>
<li><a href='http://www.programmingr.com/content/online-r-programming-resources/' rel='bookmark' title='Online R programming resources'>Online R programming resources</a></li>
<li><a href='http://www.programmingr.com/content/r-helper-functions/' rel='bookmark' title='R Helper Functions'>R Helper Functions</a></li>
</ol>
</div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/ProgrammingR?a=cXvA3CLe7qY:-iQfOrigzKM:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/ProgrammingR?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ProgrammingR?a=cXvA3CLe7qY:-iQfOrigzKM:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/ProgrammingR?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ProgrammingR/~4/cXvA3CLe7qY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.programmingr.com/content/helper-function-contest/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.programmingr.com/content/helper-function-contest/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=helper-function-contest</feedburner:origLink></item>
		<item>
		<title>R Helper Functions</title>
		<link>http://feedproxy.google.com/~r/ProgrammingR/~3/815wvg3H4lQ/</link>
		<comments>http://www.programmingr.com/content/r-helper-functions/#comments</comments>
		<pubDate>Tue, 25 Sep 2012 23:55:06 +0000</pubDate>
		<dc:creator>bryan</dc:creator>
				<category><![CDATA[Articles]]></category>

		<guid isPermaLink="false">http://www.programmingr.com/?p=724</guid>
		<description><![CDATA[<p>If you do a lot of R programming, you probably have a list of R helper functions set aside in a script that you include on R startup or at the top of your code. In some cases helper functions add capabilities that aren&#8217;t otherwise available. In other cases, they replicate functionality that is available [...]</p><p>The post <a href="http://www.programmingr.com/content/r-helper-functions/">R Helper Functions</a> appeared first on <a href="http://www.programmingr.com">ProgrammingR</a>.</p><div class='yarpp-related-rss'>

More like this:<ol>
<li><a href='http://www.programmingr.com/content/building-scoring-and-ranking-systems-r/' rel='bookmark' title='Building Scoring and Ranking Systems in R'>Building Scoring and Ranking Systems in R</a></li>
<li><a href='http://www.programmingr.com/content/webscraping-using-readlines-and-rcurl/' rel='bookmark' title='Webscraping using readLines and RCurl'>Webscraping using readLines and RCurl</a></li>
<li><a href='http://www.programmingr.com/content/positioning-charts-fig-and-fin/' rel='bookmark' title='Positioning charts with fig and fin'>Positioning charts with fig and fin</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>If you do a lot of R programming, you probably have a list of R helper functions set aside in a script that you include on R startup or at the top of your code. In some cases helper functions add capabilities that aren&#8217;t otherwise available. In other cases, they replicate functionality that is available elsewhere without loading unnecessary components. Below I present two of my most frequently used data manipulation helper functions as examples. </p>
<h3>Descriptives R Helpler Function</h3>
<pre class="brush: r; title: ; notranslate">
# Display some basic descriptives
descs &lt;- function (x) {
  if(!hidetables) {
    if(length(unique(x))&gt;30) {
      print(&quot;Summary results:&quot;)
      print(summary(x))
      print(&quot;&quot;)
      print(&quot;Number of categories is greater than 30, table not produced&quot;)
    } else {
      print(&quot;Summary results:&quot;)
      print(summary(x))
      print(&quot;&quot;)
      print(&quot;Table results:&quot;)
      print(table(x, useNA=&quot;always&quot;))
    }
   
  } else {
    print(&quot;Tables are hidden&quot;)
  }
}


# Set hide tables to true to hide tables
hidetables &lt;- FALSE
</pre>
<h3>Dummy Variable R Helper Function</h3>
<pre class="brush: r; title: ; notranslate">
# Create dummy variables for each level of a categorical variable
createDummies &lt;- function(x, df, keepNAs = TRUE) {
  for (i in seq(1, length(unique(df[, x])))) {
    if(keepNAs) {
      df[, paste(x,&quot;.&quot;, i, sep = &quot;&quot;)] &lt;- ifelse(df[, x] != i, 0, 1)
    } else {
      df[, paste(x,&quot;.&quot;, i, sep = &quot;&quot;)] &lt;- ifelse(df[, x] != i | is.na(df[, x]) , 0, 1)     
    }
  }
  df
}
</pre>
<p>The Descriptives R Helper Function produces a summary or table of the passed variable/object; it uses the number of unique values to determine whether to call just the <code>summary()</code> or <code>summary()</code> and <code>table()</code> functions. It also includes NAs by default in the tables (one of <code>table()</code>&#8216;s biggest annoyances). Once the exploratory and data manipulation work is done, all output from this function can be suppressed by setting the <code>hidetables</code> object to TRUE. </p>
<p>The Dummy Variable R Helper Function creates indicator variables from all values of a variable. Based on experience, I avoid the factor object as much as possible and this approach allows me to quickly create indicators that can be used in any way I want. </p>
<p>If you don&#8217;t have a programming background or are just beginning with R, you might not have had time to realize the benefit of helper functions or identify the tasks you do repetitively, but it&#8217;s worthwhile to give the issue some consideration. Helper functions can be exceptionally useful for saving time on repetitive tasks or facilitating your work. They&#8217;re so useful in fact, that there is a special ProgrammingR event planned around helper functions coming soon. For the more experienced R programmers out there, make a mental note of the most useful helper functions you&#8217;ve written in the past. That list will come in handy in the near future!</p>
<div class="shr-publisher-724"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic --><div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 0px;padding: 0px;font-style:italic"><br />
<strong>Looking for an R programmer or statistical programming consultant? ProgrammingR offers consulting services. For more information contact us at info@programmingr.com.</strong>
<br />
<br />
ProgrammingR offers two ways for you to stay up to date. To be notified when new articles and book reviews are posted, subscribe to the <a href="http://feeds.feedburner.com/ProgrammingR" title="ProgrammingR articles and book reviews feed">ProgrammingR articles feed</a>. To be notified when new R-based job listings are posted, subscribe to the <a href="http://feeds.feedburner.com/ProgrammingRjobs" title="ProgrammingR jobs feed">ProgrammingR jobs feed</a>. You may also want to <a href="http://www.programmingr.com/contact" title="Post an R consultant listing">post an R consultant listing</a>, <a href="http://www.programmingr.com/category/stype/r-consultants" title="ProgrammingR consultant listings">hire an R consultant</a>, or ask a question in the <a href="http://www.programmingr.com/forum/" title="ProgrammingR forums">forums</a>.
<br />
<br />
</div><p>The post <a href="http://www.programmingr.com/content/r-helper-functions/">R Helper Functions</a> appeared first on <a href="http://www.programmingr.com">ProgrammingR</a>.</p><div class='yarpp-related-rss'>
<p>More like this:</p><ol>
<li><a href='http://www.programmingr.com/content/building-scoring-and-ranking-systems-r/' rel='bookmark' title='Building Scoring and Ranking Systems in R'>Building Scoring and Ranking Systems in R</a></li>
<li><a href='http://www.programmingr.com/content/webscraping-using-readlines-and-rcurl/' rel='bookmark' title='Webscraping using readLines and RCurl'>Webscraping using readLines and RCurl</a></li>
<li><a href='http://www.programmingr.com/content/positioning-charts-fig-and-fin/' rel='bookmark' title='Positioning charts with fig and fin'>Positioning charts with fig and fin</a></li>
</ol>
</div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/ProgrammingR?a=815wvg3H4lQ:gWJgi7MJu0E:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/ProgrammingR?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ProgrammingR?a=815wvg3H4lQ:gWJgi7MJu0E:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/ProgrammingR?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ProgrammingR/~4/815wvg3H4lQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.programmingr.com/content/r-helper-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.programmingr.com/content/r-helper-functions/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=r-helper-functions</feedburner:origLink></item>
		<item>
		<title>Progress bars in R using winProgressBar</title>
		<link>http://feedproxy.google.com/~r/ProgrammingR/~3/XMJn4sI-6eg/</link>
		<comments>http://www.programmingr.com/content/progress-bars-in-r-using-winprogressbar/#comments</comments>
		<pubDate>Mon, 10 Sep 2012 12:11:34 +0000</pubDate>
		<dc:creator>bryan</dc:creator>
				<category><![CDATA[Articles]]></category>

		<guid isPermaLink="false">http://www.programmingr.com/?p=566</guid>
		<description><![CDATA[<p>Using progress bars in R scripts can provide valuable timing feedback during development and additional polish to final products. winProgressBar and setWinProgressBar are the primary functions for creating progress bars in R. Progress bars, and progress indicators in general, are relatively uncommon in R programming. This makes sense, as they can add bloat and, being [...]</p><p>The post <a href="http://www.programmingr.com/content/progress-bars-in-r-using-winprogressbar/">Progress bars in R using winProgressBar</a> appeared first on <a href="http://www.programmingr.com">ProgrammingR</a>.</p><div class='yarpp-related-rss'>

More like this:<ol>
<li><a href='http://www.programmingr.com/content/animations-r/' rel='bookmark' title='Animations in R'>Animations in R</a></li>
<li><a href='http://www.programmingr.com/content/r-helper-functions/' rel='bookmark' title='R Helper Functions'>R Helper Functions</a></li>
<li><a href='http://www.programmingr.com/content/rstudio-development-environment/' rel='bookmark' title='RStudio Development Environment'>RStudio Development Environment</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Using progress bars in R scripts can provide valuable timing feedback during development and additional polish to final products. <code>winProgressBar</code> and <code>setWinProgressBar</code> are the primary functions for creating progress bars in R.</p>
<p>Progress bars, and progress indicators in general, are relatively uncommon in R programming. This makes sense, as they can add bloat and, being design elements, they generally fall into the classification of &#8220;nice but not necessary&#8221;. However, during development, especially when using loops, progress bars can a cleaner way of tracking loop progress than, for example, printing iteration numbers. And for programmers who prepare scripts or packages for non-programmers, they add feedback that users have come to expect from other software.</p>
<p>To add progress bars in R scripts use the <code>winProgressBar</code> and <code>setWinProgressBar</code> functions. For non-Windows users there&#8217;s also a very similar Tcl/Tk version (<code>tkProgressBar</code> and <code>settkProgressbar</code>); depending on your current set up, you may need to install the <a href="http://cran.r-project.org/web/packages/tcltk2/index.html" title="Tck/tk R library">tcltk</a> library to use it.</p>
<p>Setting up a progress indicator to track the progress of a loop is very straightforward. First, initialize the display:</p>
<p><code>pb <- winProgressBar(title="Example progress bar", label="0% done", min=0, max=100, initial=0)</code></p>
<p>Use the <code>title</code> and <code>label</code> options to set the style of the display. The <code>min</code> and <code>max</code> options should use whatever values are most applicable to your task, but in most cases this will be displaying a percentage so a range of 0 to 100, starting at 0, makes sense.</p>
<p>After initializing the progress indicator, add your loop code and update the progress bar by calling the <code>setWinProgressBar</code> function at the end of each loop:</p>
<p><code>for(i in 1:100) {<br />
  Sys.sleep(0.1) # slow down the code for illustration purposes<br />
  info <- sprintf("%d%% done", round((i/100)*100))<br />
  setWinProgressBar(pb, i/(100)*100, label=info)<br />
}</p>
<p>Once the loop is exited, close the progress bar window:</p>
<p>close(pb)</code></p>
<p>Here is a snapshot of the progress indicator in action:</p>
<p><a href="http://www.programmingr.com/wp-content/uploads/2012/09/winProgressBar.png"><img class="aligncenter size-full wp-image-615" title="winProgressBar" src="http://www.programmingr.com/wp-content/uploads/2012/09/winProgressBar.png" alt="Windows Progress Bar Example" width="400" height="178" /></a></p>
<p>To track the progress of an entire script or program, you just need to place the initializing function (<code>winProgressBar</code>) at the beginning of the code and do updates via <code>setWinProgressBar</code> at key points within the flow of your program. For example, if the first task your code performs usually takes about 10% of the total time required, set the value to 10% after that task completes.</p>
<p>If a popup progress bar doesn't work for your task, there is a minimalist option, <code>txtProgressBar</code>, that by default draws a line in the console. It also allows for some fun customizations:</p>
<p style="text-align: center;"><a href="http://www.programmingr.com/wp-content/uploads/2012/09/txtProgressBar1.png"><img class="size-full wp-image-620 aligncenter" title="txtProgressBar" src="http://www.programmingr.com/wp-content/uploads/2012/09/txtProgressBar1.png" alt="Text Progress Bar Example" width="670" height="78" /></a></p>
<div class="shr-publisher-566"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic --><div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 0px;padding: 0px;font-style:italic"><br />
<strong>Looking for an R programmer or statistical programming consultant? ProgrammingR offers consulting services. For more information contact us at info@programmingr.com.</strong>
<br />
<br />
ProgrammingR offers two ways for you to stay up to date. To be notified when new articles and book reviews are posted, subscribe to the <a href="http://feeds.feedburner.com/ProgrammingR" title="ProgrammingR articles and book reviews feed">ProgrammingR articles feed</a>. To be notified when new R-based job listings are posted, subscribe to the <a href="http://feeds.feedburner.com/ProgrammingRjobs" title="ProgrammingR jobs feed">ProgrammingR jobs feed</a>. You may also want to <a href="http://www.programmingr.com/contact" title="Post an R consultant listing">post an R consultant listing</a>, <a href="http://www.programmingr.com/category/stype/r-consultants" title="ProgrammingR consultant listings">hire an R consultant</a>, or ask a question in the <a href="http://www.programmingr.com/forum/" title="ProgrammingR forums">forums</a>.
<br />
<br />
</div><p>The post <a href="http://www.programmingr.com/content/progress-bars-in-r-using-winprogressbar/">Progress bars in R using winProgressBar</a> appeared first on <a href="http://www.programmingr.com">ProgrammingR</a>.</p><div class='yarpp-related-rss'>
<p>More like this:</p><ol>
<li><a href='http://www.programmingr.com/content/animations-r/' rel='bookmark' title='Animations in R'>Animations in R</a></li>
<li><a href='http://www.programmingr.com/content/r-helper-functions/' rel='bookmark' title='R Helper Functions'>R Helper Functions</a></li>
<li><a href='http://www.programmingr.com/content/rstudio-development-environment/' rel='bookmark' title='RStudio Development Environment'>RStudio Development Environment</a></li>
</ol>
</div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/ProgrammingR?a=XMJn4sI-6eg:FSfrnWzpZR0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/ProgrammingR?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ProgrammingR?a=XMJn4sI-6eg:FSfrnWzpZR0:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/ProgrammingR?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ProgrammingR/~4/XMJn4sI-6eg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.programmingr.com/content/progress-bars-in-r-using-winprogressbar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.programmingr.com/content/progress-bars-in-r-using-winprogressbar/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=progress-bars-in-r-using-winprogressbar</feedburner:origLink></item>
		<item>
		<title>The Art of R Programming – Matloff (2011)</title>
		<link>http://feedproxy.google.com/~r/ProgrammingR/~3/gCcxbtnZFxU/</link>
		<comments>http://www.programmingr.com/content/the-art-of-r-programming-matloff-2011/#comments</comments>
		<pubDate>Mon, 27 Aug 2012 13:06:07 +0000</pubDate>
		<dc:creator>bryan</dc:creator>
				<category><![CDATA[Book reviews]]></category>

		<guid isPermaLink="false">http://www.programmingr.com/?p=540</guid>
		<description><![CDATA[<p>It&#8217;s difficult to write a book on an entire programming language and keep it manageable and concise, but The Art of R Programming does it as well as any text I&#8217;ve seen. Matloff covers, in detail and among other things, R data structures, programming idioms, performance enhancements, interfaces with other languages, debugging and graphing. Title:The [...]</p><p>The post <a href="http://www.programmingr.com/content/the-art-of-r-programming-matloff-2011/">The Art of R Programming &#8211; Matloff (2011)</a> appeared first on <a href="http://www.programmingr.com">ProgrammingR</a>.</p><div class='yarpp-related-rss'>

More like this:<ol>
<li><a href='http://www.programmingr.com/content/data-manipulation-r-spector-2008/' rel='bookmark' title='Data Manipulation with R &#8211; Spector (2008)'>Data Manipulation with R &#8211; Spector (2008)</a></li>
<li><a href='http://www.programmingr.com/content/bayesian-computation-r-albert-2009/' rel='bookmark' title='Bayesian Computation with R &#8211; Albert (2009)'>Bayesian Computation with R &#8211; Albert (2009)</a></li>
<li><a href='http://www.programmingr.com/content/handbook-statistical-analyses-using-r-everitt-and-hothorn-2006/' rel='bookmark' title='A Handbook of Statistical Analyses Using R &#8211; Everitt and Hothorn (2006)'>A Handbook of Statistical Analyses Using R &#8211; Everitt and Hothorn (2006)</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>It&#8217;s difficult to write a book on an entire programming language and keep it manageable and concise, but <em>The Art of R Programming</em> does it as well as any text I&#8217;ve seen. Matloff covers, in detail and among other things, R data structures, programming idioms, performance enhancements, interfaces with other languages, debugging and graphing.</p>
<div style="float:right; background-color: lightblue; border: 1px solid darkblue; padding:5px; margin: 2px; width: 325px;"><strong>Title:</strong>The Art of R Programming<br /><strong>Author(s):</strong> Norman Matloff<br /><strong>Publisher/Date:</strong> No Starch Press/2011<br /><strong>Statistics level:</strong> Very Low <br /><strong>Programming level:</strong> Intermediate <br /><strong>Overall recommendation:</strong>  Highly Recommended</div>
<p>There is the requisite &#8220;Introduction to R&#8221; section that is present in almost all R texts, but any beginners who benefit from this chapter may benefit from re-reading <em>ARP</em> after some additional practical experience with R. The issues that Matloff addresses and the solutions he provides are more salient after you&#8217;ve spent hours trying to resolve them.</p>
<p>The section on graphing is a good overview, but the average programmer may find it less useful than the other sections. Anyone looking for graphic optimization tips will be better served by a book focused specifically on graphing. </p>
<p>With that minor critique in mind, put simply, <em>The Art of R Programming</em> is a must read for all intermediate level R programmers. It covers nearly every method of performance enhancement available and provides a review of key fundamentals that may have been forgotten or missed.</p>
<p><a href="http://www.programmingr.com/wp-content/uploads/2012/08/ARP1.png"><img src="http://www.programmingr.com/wp-content/uploads/2012/08/ARP1.png" alt="The Art of R Programming" title="Art of R Programming" width="170" height="225" class="alignright size-full wp-image-554" /></a>One point of note, this text focuses almost solely on programming &#8211; the statistical examples are a means to an end, not an end themselves. For that reason, this book is recommended for those seeking to improve the efficiency of their programming rather than their statistical acumen. </p>
<p>At around ~$25 USD from Amazon, <em>The Art of R Programming </em> is one of the best R text values available. I highly recommend it for almost all R users. (You can also purchase this book directly from the <a href="http://nostarch.com/artofr.htm" title="No Starch Press - The Art of R Programming">publisher</a> and get both the print and e-book version for ~$40.) </p>
<div class="shr-publisher-540"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic --><div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 0px;padding: 0px;font-style:italic"><br />
<strong>Looking for an R programmer or statistical programming consultant? ProgrammingR offers consulting services. For more information contact us at info@programmingr.com.</strong>
<br />
<br />
ProgrammingR offers two ways for you to stay up to date. To be notified when new articles and book reviews are posted, subscribe to the <a href="http://feeds.feedburner.com/ProgrammingR" title="ProgrammingR articles and book reviews feed">ProgrammingR articles feed</a>. To be notified when new R-based job listings are posted, subscribe to the <a href="http://feeds.feedburner.com/ProgrammingRjobs" title="ProgrammingR jobs feed">ProgrammingR jobs feed</a>. You may also want to <a href="http://www.programmingr.com/contact" title="Post an R consultant listing">post an R consultant listing</a>, <a href="http://www.programmingr.com/category/stype/r-consultants" title="ProgrammingR consultant listings">hire an R consultant</a>, or ask a question in the <a href="http://www.programmingr.com/forum/" title="ProgrammingR forums">forums</a>.
<br />
<br />
</div><p>The post <a href="http://www.programmingr.com/content/the-art-of-r-programming-matloff-2011/">The Art of R Programming &#8211; Matloff (2011)</a> appeared first on <a href="http://www.programmingr.com">ProgrammingR</a>.</p><div class='yarpp-related-rss'>
<p>More like this:</p><ol>
<li><a href='http://www.programmingr.com/content/data-manipulation-r-spector-2008/' rel='bookmark' title='Data Manipulation with R &#8211; Spector (2008)'>Data Manipulation with R &#8211; Spector (2008)</a></li>
<li><a href='http://www.programmingr.com/content/bayesian-computation-r-albert-2009/' rel='bookmark' title='Bayesian Computation with R &#8211; Albert (2009)'>Bayesian Computation with R &#8211; Albert (2009)</a></li>
<li><a href='http://www.programmingr.com/content/handbook-statistical-analyses-using-r-everitt-and-hothorn-2006/' rel='bookmark' title='A Handbook of Statistical Analyses Using R &#8211; Everitt and Hothorn (2006)'>A Handbook of Statistical Analyses Using R &#8211; Everitt and Hothorn (2006)</a></li>
</ol>
</div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/ProgrammingR?a=gCcxbtnZFxU:v3kErmkHKLY:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/ProgrammingR?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ProgrammingR?a=gCcxbtnZFxU:v3kErmkHKLY:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/ProgrammingR?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ProgrammingR/~4/gCcxbtnZFxU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.programmingr.com/content/the-art-of-r-programming-matloff-2011/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.programmingr.com/content/the-art-of-r-programming-matloff-2011/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=the-art-of-r-programming-matloff-2011</feedburner:origLink></item>
		<item>
		<title>Animations in R</title>
		<link>http://feedproxy.google.com/~r/ProgrammingR/~3/D1xBcIkxF54/</link>
		<comments>http://www.programmingr.com/content/animations-r/#comments</comments>
		<pubDate>Tue, 24 Apr 2012 15:02:14 +0000</pubDate>
		<dc:creator>bryan</dc:creator>
				<category><![CDATA[Articles]]></category>

		<guid isPermaLink="false">http://127.0.0.1/wordpress78/?p=159</guid>
		<description><![CDATA[<p>Animated charts can be very helpful in illustrating concepts or discovering relationships, which makes them very helpful in teaching and exploratory research. Fortunately, creating animated graphs in R is fairly straightforward, once you have the right tools and understand a few basic principles about how the animations are created. In this article I&#8217;ll provide an [...]</p><p>The post <a href="http://www.programmingr.com/content/animations-r/">Animations in R</a> appeared first on <a href="http://www.programmingr.com">ProgrammingR</a>.</p><div class='yarpp-related-rss'>

More like this:<ol>
<li><a href='http://www.programmingr.com/content/progress-bars-in-r-using-winprogressbar/' rel='bookmark' title='Progress bars in R using winProgressBar'>Progress bars in R using winProgressBar</a></li>
<li><a href='http://www.programmingr.com/content/positioning-charts-fig-and-fin/' rel='bookmark' title='Positioning charts with fig and fin'>Positioning charts with fig and fin</a></li>
<li><a href='http://www.programmingr.com/content/rstudio-development-environment/' rel='bookmark' title='RStudio Development Environment'>RStudio Development Environment</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Animated charts can be very helpful in illustrating concepts or discovering relationships, which makes them very helpful in teaching and exploratory research. Fortunately, creating animated graphs in R is fairly straightforward, once you have the right tools and understand a few basic principles about how the animations are created.</p>
<p>In this article I&#8217;ll provide an example of how to use the <span style="font-family: courier new,courier;">animation</span> package to create an animated chart with a couple of bells and whistles.</p>
<p>The package installs out-of-the-box with several animations that are tailored for instruction. The examples are of varying complexity ranging from a simple coin flip simulation to illustrations of mathematical problems such as Buffon&#8217;s needle problem. In most scenarios, however, you&#8217;ll want to create your own animations, so let&#8217;s look at how to do that. </p>
<p>First, there are several different formats in which you can create your animations &#8211; GIF, HTML, LaTeX, SWF and mp4. The <span style="font-family: courier new,courier;">saveGIF()</span> function call below illustrates the generic format for each of the calls:</p>
<p><span style="font-family: courier new,courier;">saveGIF({</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; for (i in 1:10) plot(runif(10), ylim = 0:1)</span><br /><span style="font-family: courier new,courier;">}) </span></p>
<p>Understanding that the package creates animations by generating and then compiling many graphs is central to creating polished custom animations. As you can see, the syntax looks a little unfamiliar at first because the inside of the function call is a custom loop that creates the individual graphs. (Note: If you&#8217;re familiar with with the way the <span style="font-family: courier new,courier;">boot()</span> function works, this is somewhat similar.) Once those individual graphs are created, the function compiles the images in the format specified by the function call. As you might have guessed, most of the animation types require that you install 3rd party libraries for R to be able to do the compilations. The installation of these libraries is covered in the package help.</p>
<p>Basic use of the animation functions is covered in the package help, but the application of the functions to novel tasks can still be a little difficult. As a result, I&#8217;ve created an example that illustrates how to use the functions to create animations with a couple of bells and whistles. </p>
<p>This animation plots the density functions of 150 draws of 100 values from a normally distributed random variable. To make things a little more interesting (i.e., make the distribution move), a constant that varies based on the iteration count is added to the 100 values. The chart also includes a slightly stylized frame tracker (or draw counter) along the top of the chart and a horizontal bar that notes the current position and previous two positions of the sample mean. Finally, the foreground color of the chart changes based on the mean of the distribution. </p>
<p>&nbsp;</p>
<p>###################################<br /><span style="font-family: courier new,courier;">library(animation)</span></p>
<p><span style="font-family: courier new,courier;">#Set delay between frames when replaying</span><br /><span style="font-family: courier new,courier;">ani.options(interval=.05)</span></p>
<p><span style="font-family: courier new,courier;"># Set up a vector of colors for use below </span><br /><span style="font-family: courier new,courier;">col.range &lt;- heat.colors(15)</span></p>
<p><span style="font-family: courier new,courier;"># Begin animation loop</span><br /><span style="font-family: courier new,courier;"># Note the brackets within the parentheses</span><br /><span style="font-family: courier new,courier;">saveGIF({</span><br /><span style="font-family: courier new,courier;">&nbsp; </span><br /><span style="font-family: courier new,courier;">&nbsp; # For the most part, it&#8217;s safest to start with graphical settings in </span><br /><span style="font-family: courier new,courier;">&nbsp; # the animation loop, as the loop adds a layer of complexity to </span><br /><span style="font-family: courier new,courier;">&nbsp; # manipulating the graphs. For example, the layout specification needs to </span><br /><span style="font-family: courier new,courier;">&nbsp; # be within animation loop to work properly.</span><br /><span style="font-family: courier new,courier;">&nbsp; layout(matrix(c(1, rep(2, 5)), 6, 1))</span><br /><span style="font-family: courier new,courier;">&nbsp; </span><br /><span style="font-family: courier new,courier;">&nbsp; # Adjust the margins a little</span><br /><span style="font-family: courier new,courier;">&nbsp; par(mar=c(4,4,2,1) + 0.1)</span><br /><span style="font-family: courier new,courier;">&nbsp; </span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; # Begin the loop that creates the 150 individual graphs</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; for (i in 1:150) {</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # Pull 100 observations from a normal distribution</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # and add a constant based on the iteration to move the distribution</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; chunk &lt;- rnorm(100)+sqrt(abs((i)-51))</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # Reset the color of the top chart every time (so that it doesn&#8217;t change as the </span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # bottom chart changes)</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; par(fg=1)</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # Set up the top chart that keeps track of the current frame/iteration</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # Dress it up a little just for fun</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; plot(-5, xlim = c(1,150), ylim = c(0, .3), axes = F, xlab = &#8220;&#8221;, ylab = &#8220;&#8221;, main = &#8220;Iteration&#8221;)</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; abline(v=i, lwd=5, col = rgb(0, 0, 255, 255, maxColorValue=255))</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; abline(v=i-1, lwd=5, col = rgb(0, 0, 255, 50, maxColorValue=255))</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; abline(v=i-2, lwd=5, col = rgb(0, 0, 255, 25, maxColorValue=255))</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # Bring back the X axis</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; axis(1)</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # Set the color of the bottom chart based on the distance of the distribution&#8217;s mean from 0</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; par(fg = col.range[mean(chunk)+3])</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # Set up the bottom chart</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp; plot(density(chunk), main = &#8220;&#8221;, xlab = &#8220;X Value&#8221;, xlim = c(-5, 15), ylim = c(0, .6))</span></p>
<p><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # Add a line that indicates the mean of the distribution. Add additional lines to track</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # previous means</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; abline(v=mean(chunk), col = rgb(255, 0, 0, 255, maxColorValue=255))</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (exists(&#8220;lastmean&#8221;)) {abline(v=lastmean, col = rgb(255, 0, 0, 50, maxColorValue=255)); prevlastmean &lt;- lastmean;}</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (exists(&#8220;prevlastmean&#8221;)) {abline(v=prevlastmean, col = rgb(255, 0, 0, 25, maxColorValue=255))}</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #Fix last mean calculation</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lastmean &lt;- mean(chunk)</span><br /><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp; }</span><br /><span style="font-family: courier new,courier;">})</span></p>
<p><span style="font-family: courier new,courier;">########################</span></p>
<p>And the final product:</p>
<p><a href="http://imgur.com/GLByH"><img title="Hosted by imgur.com" src="http://i.imgur.com/GLByH.gif" alt="" /></a></p>
<p>A couple of closing notes:</p>
<ul>
<li>Because there are external programs involved (e.g., SWF Tools, ImageMagick, FFmpeg), the setup for this package is slightly more difficult than the average package and things will likely seem less polished than normal. Things may also not work as well; you&#8217;ll need to be prepared to be flexible with your animation formats and graph layouts.</li>
</ul>
<ul>
<li>Animation works exceptionally well when smaller numbers of individual graphs are being compiled, but as the number of individual graphs grows, so does your likelihood of hitting a problem. E.g., although GIF is a very exportable and transportable format, and therefore ideal for many situations, I found that animations with more than ~500 source graphs just didn&#8217;t compile. The limit for HTML was similar. Your mileage may vary, but again, be prepared to be flexible.</li>
</ul>
<ul>
<li>If you do not need to transport your animation and it will have less than a few hundred individual images, you can avoid installing 3rd party software by using the saveHTML function. This output also includes an interface that allows you to pause and move within the animation easily.</li>
</ul>
<ul>
<li>As mentioned in the code above, if you&#8217;re having trouble getting a particular graphical parameter to work, make sure that it is in the internal loop. For efficiency, you want to keep the loop as clean as possible of course, but some things need to be specified each time a new chart is plotted, and therefore need to be inside the loop.</li>
</ul>
<ul>
<li>Animations aren&#8217;t very common in research presentations, but can provide extensive insight beyond static images. Given R&#8217;s advanced graphing capabilities, it&#8217;s possible to create very nice animations without needing to learn a completely different software package.</li>
</ul>
<p>If you&#8217;ve created an animation you&#8217;d like to share or have additional tips, feel free add them to the comments.</p>
<div class="shr-publisher-159"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic --><div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 0px;padding: 0px;font-style:italic"><br />
<strong>Looking for an R programmer or statistical programming consultant? ProgrammingR offers consulting services. For more information contact us at info@programmingr.com.</strong>
<br />
<br />
ProgrammingR offers two ways for you to stay up to date. To be notified when new articles and book reviews are posted, subscribe to the <a href="http://feeds.feedburner.com/ProgrammingR" title="ProgrammingR articles and book reviews feed">ProgrammingR articles feed</a>. To be notified when new R-based job listings are posted, subscribe to the <a href="http://feeds.feedburner.com/ProgrammingRjobs" title="ProgrammingR jobs feed">ProgrammingR jobs feed</a>. You may also want to <a href="http://www.programmingr.com/contact" title="Post an R consultant listing">post an R consultant listing</a>, <a href="http://www.programmingr.com/category/stype/r-consultants" title="ProgrammingR consultant listings">hire an R consultant</a>, or ask a question in the <a href="http://www.programmingr.com/forum/" title="ProgrammingR forums">forums</a>.
<br />
<br />
</div><p>The post <a href="http://www.programmingr.com/content/animations-r/">Animations in R</a> appeared first on <a href="http://www.programmingr.com">ProgrammingR</a>.</p><div class='yarpp-related-rss'>
<p>More like this:</p><ol>
<li><a href='http://www.programmingr.com/content/progress-bars-in-r-using-winprogressbar/' rel='bookmark' title='Progress bars in R using winProgressBar'>Progress bars in R using winProgressBar</a></li>
<li><a href='http://www.programmingr.com/content/positioning-charts-fig-and-fin/' rel='bookmark' title='Positioning charts with fig and fin'>Positioning charts with fig and fin</a></li>
<li><a href='http://www.programmingr.com/content/rstudio-development-environment/' rel='bookmark' title='RStudio Development Environment'>RStudio Development Environment</a></li>
</ol>
</div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/ProgrammingR?a=D1xBcIkxF54:58u7gVZpN6Y:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/ProgrammingR?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ProgrammingR?a=D1xBcIkxF54:58u7gVZpN6Y:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/ProgrammingR?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ProgrammingR/~4/D1xBcIkxF54" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.programmingr.com/content/animations-r/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.programmingr.com/content/animations-r/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=animations-r</feedburner:origLink></item>
		<item>
		<title>RStudio Development Environment</title>
		<link>http://feedproxy.google.com/~r/ProgrammingR/~3/1g8yPNnJPl0/</link>
		<comments>http://www.programmingr.com/content/rstudio-development-environment/#comments</comments>
		<pubDate>Fri, 23 Mar 2012 17:55:55 +0000</pubDate>
		<dc:creator>bryan</dc:creator>
				<category><![CDATA[Articles]]></category>

		<guid isPermaLink="false">http://127.0.0.1/wordpress78/?p=147</guid>
		<description><![CDATA[<p>Compared to many other languages of equal popularity, there are realtively few development environments for R. In fact, the total number of production ready R IDEs could probably be counted on one hand. That deficiency is a small price to pay to use R and if you&#8217;re not already accustomed to using IDEs for other [...]</p><p>The post <a href="http://www.programmingr.com/content/rstudio-development-environment/">RStudio Development Environment</a> appeared first on <a href="http://www.programmingr.com">ProgrammingR</a>.</p><div class='yarpp-related-rss'>

More like this:<ol>
<li><a href='http://www.programmingr.com/content/webscraping-using-readlines-and-rcurl/' rel='bookmark' title='Webscraping using readLines and RCurl'>Webscraping using readLines and RCurl</a></li>
<li><a href='http://www.programmingr.com/content/installing-quantstrat-r-forge-and-source/' rel='bookmark' title='Installing quantstrat from R-forge and source'>Installing quantstrat from R-forge and source</a></li>
<li><a href='http://www.programmingr.com/content/progress-bars-in-r-using-winprogressbar/' rel='bookmark' title='Progress bars in R using winProgressBar'>Progress bars in R using winProgressBar</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p><a href="http://imgur.com/CMBrt"><img src="http://i.imgur.com/CMBrtl.jpg" title="RStudio Layout" alt="RStudio Layout" style = "float: right; padding: 3px;" height = "200" /></a>Compared to many other languages of equal popularity, there are realtively few development environments for R. In fact, the total number of production ready R IDEs could probably be counted on one hand. That deficiency is a small price to pay to use R and if you&#8217;re not already accustomed to using IDEs for other languages, you probably haven&#8217;t missed it too much. But RStudio goes a long way toward providing a full-featured R development platform, that, once you&#8217;ve used it, quickly becomes hard to give up again. </p>
<p>RStudio has some nice graphical features and the layout is clean and logical for the most part. Functionally, some of the best features are:<br />
</p>
<ul>
<li>Plot caching (allows you to flip back through previous graphs without rerunning them, making it much easier to review your graphical output)</li>
<li>Function, object and <em>parameter</em> listing and completion that works even with user-defined functions</li>
<li>Shortcuts for quickly drilling down into functions</li>
</ul>
<p>
<a href="http://imgur.com/o2QAF"><img src="http://i.imgur.com/o2QAF.jpg" title="RStudio paramater completion" alt="RStudio paramater completion" alt="" height = "150" /></a></p>
<p>RStudio also provides version control integration (Git, SVN) which could prove to be very helpful, but I haven&#8217;t yet tested it. I can&#8217;t speak to how well it works, just that it is available.</p>
<p>In addition to these positives, RStudio has an active support system with developer participation via the <a href="http://support.rstudio.org" title="RStudio Support" alt = "RStudio Support">RStudio support site</a>.</p>
<p>Overall, I&#8217;ve been very impressed with RStudio over the past few weeks. If you haven&#8217;t yet tested it, I suggest you give it a try. Given the growth of R over recent years, I think it&#8217;s time we expected development tools to mature to the level that they have for other programming languages with similar levels of adoption. The only way that will produce sustainable, mature products is if there is a constant demand in the market.</p>
<p>Already using something else? Feel free to mention your favorite R IDE in the comments.</p>
<p></p>
<div class="shr-publisher-147"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic --><div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 0px;padding: 0px;font-style:italic"><br />
<strong>Looking for an R programmer or statistical programming consultant? ProgrammingR offers consulting services. For more information contact us at info@programmingr.com.</strong>
<br />
<br />
ProgrammingR offers two ways for you to stay up to date. To be notified when new articles and book reviews are posted, subscribe to the <a href="http://feeds.feedburner.com/ProgrammingR" title="ProgrammingR articles and book reviews feed">ProgrammingR articles feed</a>. To be notified when new R-based job listings are posted, subscribe to the <a href="http://feeds.feedburner.com/ProgrammingRjobs" title="ProgrammingR jobs feed">ProgrammingR jobs feed</a>. You may also want to <a href="http://www.programmingr.com/contact" title="Post an R consultant listing">post an R consultant listing</a>, <a href="http://www.programmingr.com/category/stype/r-consultants" title="ProgrammingR consultant listings">hire an R consultant</a>, or ask a question in the <a href="http://www.programmingr.com/forum/" title="ProgrammingR forums">forums</a>.
<br />
<br />
</div><p>The post <a href="http://www.programmingr.com/content/rstudio-development-environment/">RStudio Development Environment</a> appeared first on <a href="http://www.programmingr.com">ProgrammingR</a>.</p><div class='yarpp-related-rss'>
<p>More like this:</p><ol>
<li><a href='http://www.programmingr.com/content/webscraping-using-readlines-and-rcurl/' rel='bookmark' title='Webscraping using readLines and RCurl'>Webscraping using readLines and RCurl</a></li>
<li><a href='http://www.programmingr.com/content/installing-quantstrat-r-forge-and-source/' rel='bookmark' title='Installing quantstrat from R-forge and source'>Installing quantstrat from R-forge and source</a></li>
<li><a href='http://www.programmingr.com/content/progress-bars-in-r-using-winprogressbar/' rel='bookmark' title='Progress bars in R using winProgressBar'>Progress bars in R using winProgressBar</a></li>
</ol>
</div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/ProgrammingR?a=1g8yPNnJPl0:Zapbo56b_qE:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/ProgrammingR?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ProgrammingR?a=1g8yPNnJPl0:Zapbo56b_qE:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/ProgrammingR?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ProgrammingR/~4/1g8yPNnJPl0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.programmingr.com/content/rstudio-development-environment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.programmingr.com/content/rstudio-development-environment/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=rstudio-development-environment</feedburner:origLink></item>
		<item>
		<title>Installing quantstrat from R-forge and source</title>
		<link>http://feedproxy.google.com/~r/ProgrammingR/~3/qw339ipSxiY/</link>
		<comments>http://www.programmingr.com/content/installing-quantstrat-r-forge-and-source/#comments</comments>
		<pubDate>Tue, 10 Jan 2012 22:52:10 +0000</pubDate>
		<dc:creator>bryan</dc:creator>
				<category><![CDATA[Articles]]></category>

		<guid isPermaLink="false">http://127.0.0.1/wordpress78/?p=129</guid>
		<description><![CDATA[<p>R is used extensively in the financial industry; many of my recent clients have been working in or developing products for the financial sector. Some common applications are to use R to analyze market data and evaluate quantitative trading strategies. Custom solutions are almost always the best way to do this, but the quantstrat package [...]</p><p>The post <a href="http://www.programmingr.com/content/installing-quantstrat-r-forge-and-source/">Installing quantstrat from R-forge and source</a> appeared first on <a href="http://www.programmingr.com">ProgrammingR</a>.</p><div class='yarpp-related-rss'>

More like this:<ol>
<li><a href='http://www.programmingr.com/content/webscraping-using-readlines-and-rcurl/' rel='bookmark' title='Webscraping using readLines and RCurl'>Webscraping using readLines and RCurl</a></li>
<li><a href='http://www.programmingr.com/content/progress-bars-in-r-using-winprogressbar/' rel='bookmark' title='Progress bars in R using winProgressBar'>Progress bars in R using winProgressBar</a></li>
<li><a href='http://www.programmingr.com/content/animations-r/' rel='bookmark' title='Animations in R'>Animations in R</a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>R is used extensively in the financial industry; many of my recent clients have been working in or developing products for the financial sector. Some common applications are to use R to analyze market data and evaluate quantitative trading strategies. Custom solutions are almost always the best way to do this, but the <code>quantstrat</code> package can make it easy to quickly get a high-level understanding of a strategy&#8217;s potential. However, <code>quantstrat</code> is still under development, and this, combined with a lack of documentation and the complex nature of the tasks involved, make it difficult to work with. This article addresses one of the most basic issues with <code>quantstrat</code> &#8211; getting it installed. <code>quantstrat</code> and it&#8217;s required packages currently aren&#8217;t available on CRAN &#8211; you have to get them from R-forge. As a result, the installation is slightly less straightforward than other packages and provides an opportunity to discuss how to install packages from R-forge and locally from source. Although this article focuses on installing <code>quantstrat</code>, these instructions will help with any R-package that you need to build from source.<br />
</br><br />
If you&#8217;re installing from R-forge, the process is only moderately different than installing from CRAN; simply change the <code>install.packages</code> command to point to the R-forge repository:</p>
<p><code><br />
install.packages("FinancialInstrument", repos="http://R-Forge.R-project.org")</code></p>
<p><code>install.packages("blotter", repos="http://R-Forge.R-project.org")</code></p>
<p><code>install.packages("quantstrat", repos="http://R-Forge.R-project.org")</code><br />
</br><br />
Since the <code>FinancialInstrument</code> and <code>blotter</code> packages are dependencies for <code>quantstrat</code>, you can download and install all three at once with just the last line.<br />
</br><br />
In some cases, you may need to build the packages yourself. You&#8217;ll need to set your system up to compile R source code if it isn&#8217;t already. To do so, follow steps 1-3 below. If your system is already set up to compile R source code, you can skip to step 4.<br />
</br><br />
# 1) Install <code>Rtools</code> package (must be done manually from http://www.murdoch-sutherland.com/Rtools/</p>
<p># 2) Install LaTex from www.miktex.org/</p>
<p># 3) Install InnoSetup http://www.jrsoftware.org/</p>
<p># 4) Download the three package source files available from R-forge http://r-forge.r-project.org/R/?group_id=316</p>
<p># 5) Install the packages using the commands below (substituting the appropriate version numbers):</p>
<p><code><br />
install.packages("C:/yourpath/FinancialInstrument_0.9.18.tar.gz", repos = NULL, type="source")</code></p>
<p><code>install.packages("C:/yourpath/blotter_0.8.4.tar.gz", repos = NULL, type="source")</code></p>
<p><code>install.packages("C:/yourpath/quantstrat_0.6.1.tar.gz", repos = NULL, type="source")</code><br />
</br><br />
Note that these directions are relevant until the packages are available on CRAN, after which, you&#8217;ll be able to download and install them like any other package (I&#8217;ll make a note on this post once that happens). Also note that since these packages are under heavy development, you&#8217;ll want to update them often.</p>
<p></p>
<div class="shr-publisher-129"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic --><div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 0px;padding: 0px;font-style:italic"><br />
<strong>Looking for an R programmer or statistical programming consultant? ProgrammingR offers consulting services. For more information contact us at info@programmingr.com.</strong>
<br />
<br />
ProgrammingR offers two ways for you to stay up to date. To be notified when new articles and book reviews are posted, subscribe to the <a href="http://feeds.feedburner.com/ProgrammingR" title="ProgrammingR articles and book reviews feed">ProgrammingR articles feed</a>. To be notified when new R-based job listings are posted, subscribe to the <a href="http://feeds.feedburner.com/ProgrammingRjobs" title="ProgrammingR jobs feed">ProgrammingR jobs feed</a>. You may also want to <a href="http://www.programmingr.com/contact" title="Post an R consultant listing">post an R consultant listing</a>, <a href="http://www.programmingr.com/category/stype/r-consultants" title="ProgrammingR consultant listings">hire an R consultant</a>, or ask a question in the <a href="http://www.programmingr.com/forum/" title="ProgrammingR forums">forums</a>.
<br />
<br />
</div><p>The post <a href="http://www.programmingr.com/content/installing-quantstrat-r-forge-and-source/">Installing quantstrat from R-forge and source</a> appeared first on <a href="http://www.programmingr.com">ProgrammingR</a>.</p><div class='yarpp-related-rss'>
<p>More like this:</p><ol>
<li><a href='http://www.programmingr.com/content/webscraping-using-readlines-and-rcurl/' rel='bookmark' title='Webscraping using readLines and RCurl'>Webscraping using readLines and RCurl</a></li>
<li><a href='http://www.programmingr.com/content/progress-bars-in-r-using-winprogressbar/' rel='bookmark' title='Progress bars in R using winProgressBar'>Progress bars in R using winProgressBar</a></li>
<li><a href='http://www.programmingr.com/content/animations-r/' rel='bookmark' title='Animations in R'>Animations in R</a></li>
</ol>
</div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/ProgrammingR?a=qw339ipSxiY:PNgYPpCAMqk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/ProgrammingR?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/ProgrammingR?a=qw339ipSxiY:PNgYPpCAMqk:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/ProgrammingR?d=qj6IDK7rITs" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/ProgrammingR/~4/qw339ipSxiY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.programmingr.com/content/installing-quantstrat-r-forge-and-source/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.programmingr.com/content/installing-quantstrat-r-forge-and-source/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=installing-quantstrat-r-forge-and-source</feedburner:origLink></item>
	</channel>
</rss>
