<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	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/"
	>

<channel>
	<title>Software for Exploratory Data Analysis and Statistical Modelling &#187; R Environment</title>
	<atom:link href="http://www.wekaleamstudios.co.uk/topics/r-environment/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.wekaleamstudios.co.uk</link>
	<description>Statistical Modelling with R</description>
	<lastBuildDate>Wed, 01 Feb 2012 19:44:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Surfaces in ternary plots</title>
		<link>http://www.wekaleamstudios.co.uk/posts/surfaces-in-ternary-plots/</link>
		<comments>http://www.wekaleamstudios.co.uk/posts/surfaces-in-ternary-plots/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 19:44:22 +0000</pubDate>
		<dc:creator>Ralph</dc:creator>
				<category><![CDATA[Lattice Graphics]]></category>
		<category><![CDATA[levelplot]]></category>
		<category><![CDATA[mixture]]></category>
		<category><![CDATA[surface]]></category>
		<category><![CDATA[ternary plot]]></category>

		<guid isPermaLink="false">http://www.wekaleamstudios.co.uk/?p=1782</guid>
		<description><![CDATA[In mixture experiments there is a constraint that the variables are the proportions of components that are mixed together with the consequence that these proportions sum to one. When fitting regression models to data from mixture experiments we may be interested in reprenting the fitted model with a surface plot. The constraint on proportions means [...]]]></description>
			<content:encoded><![CDATA[<p>In mixture experiments there is a constraint that the variables are the proportions of components that are mixed together with the consequence that these proportions sum to one. When fitting regression models to data from mixture experiments we may be interested in reprenting the fitted model with a surface plot.<span id="more-1782"></span></p>
<p>The constraint on proportions means that the mixture data can be described in one dimension lower than the total number of components. For example when there are three mixture components a two dimension plot can be used to represent the mixture within an equilateral triangle.</p>
<p>To create a surface within the mixture triangle we can create a grid of points and then convert these pairs of points into mixture triples.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">mygrid = rbind(
	expand.grid(
		x = seq(0, 1.0, length.out = 500),
		y = seq(0, sqrt(3)/2, length.out = 500)
	)
)</pre></div></div>

<p>The conversion formulae are shown below:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">mygrid$a = (sqrt(3) * (mygrid$x - 0.5) + (mygrid$y - 0.5 * sqrt(3))) /
  (- sqrt(3) - 0.5 * sqrt(3))
mygrid$b = (- sqrt(3) * (mygrid$x - 0.5) + (mygrid$y - 0.5 * sqrt(3))) /
  (- sqrt(3) - 0.5 * sqrt(3))
mygrid$c = 1 - mygrid$a - mygrid$b</pre></div></div>

<p>The next step is to calculate our surface values, a trivial example of which is:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">mygrid$z = 10 + 4 * mygrid$a + 3 * mygrid$b</pre></div></div>

<p>We then need to <em>trick</em> the plotting function by setting all invalid mixture combinations to be missing values.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">mygrid$z[mygrid$a &lt; 0 | mygrid$b &lt; 0 | mygrid$c &lt; 0] = NA
mygrid$z[mygrid$a &gt; 1 | mygrid$b &gt; 1 | mygrid$c &gt; 1] = NA</pre></div></div>

<p>Lastly we use the levelplot function in the lattice package.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">trellis.par.set(&quot;axis.line&quot;,list(col=NA,lty=1,lwd=1))
levelplot(z ~ x*y, data = mygrid,
	col.regions = gray(101:0/101), scales = list(draw=FALSE),
	xlab = &quot;&quot;, ylab = &quot;&quot;,
	panel = function(x, y, z, ...)
	{
		panel.levelplot(x, y, z, ...)
		panel.lines(c(0,1), c(0,0), col = &quot;black&quot;)
		panel.lines(c(0,0.5), c(0,sqrt(3)/2), col = &quot;black&quot;)
		panel.lines(c(0.5,1), c(sqrt(3)/2,0), col = &quot;black&quot;)
		panel.text(0.5, sqrt(3)/2, &quot;C&quot;, pos=3)
		panel.text(0, 0, &quot;A&quot;, pos=2)
		panel.text(1, 0, &quot;B&quot;, pos=4)
	},
	xlim = c(-0.2,1.2),
	ylim = c(-0.2, 0.2+sqrt(3)/2)
)</pre></div></div>

<p>This forms the basis of a ternary surface plot and various adjustments can be easily made to customise the plot.</p>
<div id="attachment_1792" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.wekaleamstudios.co.uk/wp-content/uploads/2012/02/ternaryplot.png"><img src="http://www.wekaleamstudios.co.uk/wp-content/uploads/2012/02/ternaryplot-300x300.png" alt="Ternary Plot" title="Ternary Plot" width="300" height="300" class="size-medium wp-image-1792" /></a><p class="wp-caption-text">Example of a surface plot in a ternary diagram</p></div>
<p>Other useful resources are provided on the <a href="http://www.wekaleamstudios.co.uk/supplementary-material/">Supplementary Material</a> page.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wekaleamstudios.co.uk/posts/surfaces-in-ternary-plots/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cricket All Round Performances</title>
		<link>http://www.wekaleamstudios.co.uk/posts/cricket-all-round-performances/</link>
		<comments>http://www.wekaleamstudios.co.uk/posts/cricket-all-round-performances/#comments</comments>
		<pubDate>Mon, 19 Sep 2011 22:12:43 +0000</pubDate>
		<dc:creator>Ralph</dc:creator>
				<category><![CDATA[R Environment]]></category>
		<category><![CDATA[batting]]></category>
		<category><![CDATA[bowling]]></category>
		<category><![CDATA[cricket]]></category>
		<category><![CDATA[runs]]></category>
		<category><![CDATA[wickets]]></category>

		<guid isPermaLink="false">http://www.wekaleamstudios.co.uk/?p=1685</guid>
		<description><![CDATA[In cricket a player who can perform well with both the bat and bowl is a great asset for any team and across the history of international cricket there have been a number of cricketers that hall into this bracket. It is difficult to specify a set of criteria to determine whether a player can [...]]]></description>
			<content:encoded><![CDATA[<p>In cricket a player who can perform well with both the bat and bowl is a great asset for any team and across the history of international cricket there have been a number of cricketers that hall into this bracket.<span id="more-1685"></span></p>
<p>It is difficult to specify a set of criteria to determine whether a player can be described as an all-rounder. To compare the performances of various all-rounders we can look at the subset of crickters who have scored at least 1,000 runs and taken at least 100 wickets at Test Match level. This is not a perfect criteria as there will be players who have taken part in sufficient test matches that they will be included even though they are clearly much stronger in one of the two disciplines but very handy in the other.</p>
<p>A total of 54 test match cricketers were identified based on this criteria (up to and including test match 2004) and a scatter plot of the performances can be seen <a href='http://www.wekaleamstudios.co.uk/wp-content/uploads/2011/09/allrounder-graph1.pdf'>here</a>. The graph shows that the majority of players in the bottom left region of the graph with a handful of batsmen and bowlers at the extremes in terms of runs or wickets.</p>
<p>To get a better idea of the balance between wickets and runs we can zoom in on the bottom left hand region of the graph to get this <a href='http://www.wekaleamstudios.co.uk/wp-content/uploads/2011/09/allrounder-graph2.pdf'>display</a>. This new graph suggests that although there have been a number of English cricketers that has scored 1,000 runs and taken 100 wickets they do not have the longevity of players from other countries.</p>
<p>There are naturally other measures of performance that could be used to compare this set of allround cricketers which might provided a more illuminating insight into all round performances.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wekaleamstudios.co.uk/posts/cricket-all-round-performances/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Colours in R</title>
		<link>http://www.wekaleamstudios.co.uk/posts/colours-in-r/</link>
		<comments>http://www.wekaleamstudios.co.uk/posts/colours-in-r/#comments</comments>
		<pubDate>Mon, 19 Sep 2011 13:37:28 +0000</pubDate>
		<dc:creator>Ralph</dc:creator>
				<category><![CDATA[R Environment]]></category>
		<category><![CDATA[colour]]></category>
		<category><![CDATA[rgb]]></category>

		<guid isPermaLink="false">http://www.wekaleamstudios.co.uk/?p=1681</guid>
		<description><![CDATA[There is a handy webpage which provides a chart of colours available in R. The chart is also available in pdf from the webpage.]]></description>
			<content:encoded><![CDATA[<p>There is a handy <a href="http://research.stowers-institute.org/efg/R/Color/Chart/">webpage</a> which provides a chart of colours available in R. The chart is also available in pdf from the webpage.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wekaleamstudios.co.uk/posts/colours-in-r/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting rid of white space at the beginning and end of a string</title>
		<link>http://www.wekaleamstudios.co.uk/posts/getting-rid-of-white-space-at-the-beginning-and-end-of-a-string/</link>
		<comments>http://www.wekaleamstudios.co.uk/posts/getting-rid-of-white-space-at-the-beginning-and-end-of-a-string/#comments</comments>
		<pubDate>Thu, 28 Jul 2011 11:01:19 +0000</pubDate>
		<dc:creator>Ralph</dc:creator>
				<category><![CDATA[S Programming]]></category>
		<category><![CDATA[stringr]]></category>
		<category><![CDATA[str_trim]]></category>
		<category><![CDATA[whitespace]]></category>

		<guid isPermaLink="false">http://www.wekaleamstudios.co.uk/?p=1660</guid>
		<description><![CDATA[There are situations where we are working with character strings extracted from various sources and it can be annoying when there is white space at the beginning and/or end of the strings. This whitespace can cause problems when attemping to sort, subset or various other common operations. The stringr package has a handy function str_trim [...]]]></description>
			<content:encoded><![CDATA[<p>There are situations where we are working with character strings extracted from various sources and it can be annoying when there is white space at the beginning and/or end of the strings. This whitespace can cause problems when attemping to sort, subset or various other common operations.<span id="more-1660"></span></p>
<p>The <strong>stringr</strong> package has a handy function <strong>str_trim</strong> (edited) that comes to the rescue and is straightforward to use. First up make sure that the package is available in the <strong>R</strong> session:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">require(stringr)</pre></div></div>

<p>Here is a basic example with a simple string:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">&gt; &quot;  This is an example of whitespace.  &quot;
[1] &quot;  This is an example of whitespace.  &quot;
&gt; str_trim(&quot;  This is an example of whitespace.  &quot;)
[1] &quot;This is an example of whitespace.&quot;</pre></div></div>

<p>As we can see this is very simple and is set up to work on a vector of character strings as well.</p>
<p>Other useful resources are provided on the <a href="http://www.wekaleamstudios.co.uk/supplementary-material/">Supplementary Material</a> page. Visit <a href="http://en.wikibooks.org/wiki/R_Programming/Text_Processing">here</a> for more examples of string manipulation.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wekaleamstudios.co.uk/posts/getting-rid-of-white-space-at-the-beginning-and-end-of-a-string/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>R.NET</title>
		<link>http://www.wekaleamstudios.co.uk/posts/r-net/</link>
		<comments>http://www.wekaleamstudios.co.uk/posts/r-net/#comments</comments>
		<pubDate>Mon, 04 Jul 2011 17:47:50 +0000</pubDate>
		<dc:creator>Ralph</dc:creator>
				<category><![CDATA[R Environment]]></category>
		<category><![CDATA[R.net]]></category>

		<guid isPermaLink="false">http://www.wekaleamstudios.co.uk/?p=1656</guid>
		<description><![CDATA[The R.NET project provides a mechanism for communicating with R from a .NET application. This appears to be a promising way to create simple interfaces to some of the functionality of R. Some examples of using R.NET can be found here and here.]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://rdotnet.codeplex.com/"><strong>R.NET</strong></a> project provides a mechanism for communicating with <strong>R</strong> from a .NET application. This appears to be a promising way to create simple interfaces to some of the functionality of <strong>R</strong>.<span id="more-1656"></span></p>
<p>Some examples of using <strong>R.NET</strong> can be found <a href="http://psychwire.wordpress.com/2011/06/19/making-guis-using-c-and-r-with-the-help-of-r-net/">here</a> and <a href="http://psychwire.wordpress.com/2011/06/25/importing-and-displaying-a-data-frame-with-c-and-r-net/">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wekaleamstudios.co.uk/posts/r-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generalized Linear Models &#8211; Poisson Regression</title>
		<link>http://www.wekaleamstudios.co.uk/posts/generalized-linear-models-poisson-regression/</link>
		<comments>http://www.wekaleamstudios.co.uk/posts/generalized-linear-models-poisson-regression/#comments</comments>
		<pubDate>Sun, 26 Jun 2011 09:28:50 +0000</pubDate>
		<dc:creator>Ralph</dc:creator>
				<category><![CDATA[Grammar of Graphics]]></category>
		<category><![CDATA[Linear Models]]></category>
		<category><![CDATA[Statistical Modelling]]></category>
		<category><![CDATA[Generalized Linear Model]]></category>
		<category><![CDATA[glm]]></category>
		<category><![CDATA[Poisson]]></category>
		<category><![CDATA[update]]></category>

		<guid isPermaLink="false">http://www.wekaleamstudios.co.uk/?p=1547</guid>
		<description><![CDATA[The Generalized Linear Model (GLM) allows us to model responses with distributions other than the Normal distribution, which is one of the assumptions underlying linear regression as used in many cases. When data is counts of events (or items) then a discrete distribution is more appropriate is usually more appropriate than approximating with a continuous [...]]]></description>
			<content:encoded><![CDATA[<p>The Generalized Linear Model (GLM) allows us to model responses with distributions other than the Normal distribution, which is one of the assumptions underlying linear regression as used in many cases. When data is counts of events (or items) then a discrete distribution is more appropriate is usually more appropriate than approximating with a continuous distribution, especially as our counts should be bounded below at zero. Negative counts do not make sense.<span id="more-1547"></span></p>
<p><!--[Fast Tube]--><span id="Z1qE9-Vqw50" style="display:block;"><a title="Click here to watch this video!" href="http://www.wekaleamstudios.co.uk/posts/generalized-linear-models-poisson-regression/#Z1qE9-Vqw50"><img src="http://i.ytimg.com/vi/Z1qE9-Vqw50/0.jpg" alt="Fast Tube" border="0" width="320" height="240" /></a><br /><small>Fast Tube by <a title="Casper's Blog" href="http://blog.caspie.net/">Casper</a></small></span><!--[/Fast Tube]--></p>
<p>To investigate using Poisson regression via the GLM framework consider a small data set on failure modes (<a href="http://www.sci.usq.edu.au/staff/dunn/Datasets/tech-glms.html">here</a>).</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">&gt; failure.df = read.table(&quot;twomodes.dat&quot;, header = TRUE)
&gt; failure.df
  Mode1 Mode2 Failures
1  33.3  25.3       15
2  52.2  14.4        9
3  64.7  32.5       14
4 137.0  20.5       24
5 125.9  97.6       27
6 116.3  53.6       27
7 131.7  56.6       23
8  85.0  87.3       18
9  91.9  47.8       22</pre></div></div>

<p>The machinery is run in two modes and the objective of the analysis is to determine whether the number of failures depends on how long the machine is run in mode 1 or mode 2 and whether there is an interaction between the time in each mode to increases or decreases the number of failures.</p>
<p>The response for this set of data is the number of failures (count) so a Poisson regression model is considered.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">&gt; fmod1 = glm(Failures ~ Mode1 * Mode2, data = failure.df, family = poisson)
&gt; summary(fmod1)
&nbsp;
Call:
glm(formula = Failures ~ Mode1 * Mode2, family = poisson, data = failure.df)
&nbsp;
Deviance Residuals: 
       1         2         3         4         5         6         7         8         9  
 0.91003  -1.15601  -0.28328  -0.10398   0.03526   0.84825  -0.49211  -0.57298   0.64821  
&nbsp;
Coefficients:
              Estimate Std. Error z value Pr(&gt;|z|)    
(Intercept)  2.105e+00  4.481e-01   4.698 2.63e-06 ***
Mode1        7.687e-03  4.285e-03   1.794   0.0729 .  
Mode2        4.703e-03  1.163e-02   0.405   0.6858    
Mode1:Mode2 -1.978e-05  1.037e-04  -0.191   0.8487    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
&nbsp;
(Dispersion parameter for poisson family taken to be 1)
&nbsp;
    Null deviance: 16.996  on 8  degrees of freedom
Residual deviance:  3.967  on 5  degrees of freedom
AIC: 55.024
&nbsp;
Number of Fisher Scoring iterations: 4</pre></div></div>

<p>The model output does not provide any support for an interaction between the number of time spent in the two different modes of operation. If we remove the interaction term and re-fit the model, using the update function, we get:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">&gt; fmod2 = update(fmod1, . ~ . - Mode1:Mode2)
&gt; summary(fmod2)
&nbsp;
Call:
glm(formula = Failures ~ Mode1 + Mode2, family = poisson, data = failure.df)
&nbsp;
Deviance Residuals: 
     Min        1Q    Median        3Q       Max  
-1.21984  -0.44735  -0.05893   0.68351   0.87510  
&nbsp;
Coefficients:
            Estimate Std. Error z value Pr(&gt;|z|)    
(Intercept) 2.175168   0.255456   8.515  &lt; 2e-16 ***
Mode1       0.007015   0.002429   2.888  0.00387 ** 
Mode2       0.002549   0.002835   0.899  0.36852    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
&nbsp;
(Dispersion parameter for poisson family taken to be 1)
&nbsp;
    Null deviance: 16.9964  on 8  degrees of freedom
Residual deviance:  4.0033  on 6  degrees of freedom
AIC: 53.06
&nbsp;
Number of Fisher Scoring iterations: 4</pre></div></div>

<p>This output suggests that the time of operation in mode 1 is important for determining the number of faults but the time of operation in mode 2 is not important. One last step gives us:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">&gt; fmod3 = update(fmod2, . ~ . - Mode2)
&gt; summary(fmod3)
&nbsp;
Call:
glm(formula = Failures ~ Mode1, family = poisson, data = failure.df)
&nbsp;
Deviance Residuals: 
     Min        1Q    Median        3Q       Max  
-1.43194  -0.56958  -0.00745   0.66742   0.82231  
&nbsp;
Coefficients:
            Estimate Std. Error z value Pr(&gt;|z|)    
(Intercept) 2.237196   0.243053   9.205  &lt; 2e-16 ***
Mode1       0.007705   0.002264   3.403 0.000667 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
&nbsp;
(Dispersion parameter for poisson family taken to be 1)
&nbsp;
    Null deviance: 16.9964  on 8  degrees of freedom
Residual deviance:  4.8078  on 7  degrees of freedom
AIC: 51.865
&nbsp;
Number of Fisher Scoring iterations: 4</pre></div></div>

<p>The diagnostic plots are shown below which do not indicate any major problems with the final model, especially given the small number of data points.</p>
<div id="attachment_1644" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.wekaleamstudios.co.uk/wp-content/uploads/2011/06/Poisson-Regression.png"><img src="http://www.wekaleamstudios.co.uk/wp-content/uploads/2011/06/Poisson-Regression-300x300.png" alt="Residual Plots for Poisson Regression model" title="Residual Plots for Poisson Regression model" width="300" height="300" class="size-medium wp-image-1644" /></a><p class="wp-caption-text">Four diagnostic plots for a Poisson regression model based on total failures</p></div>
<p>Other useful resources are provided on the <a href="http://www.wekaleamstudios.co.uk/supplementary-material/">Supplementary Material</a> page.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wekaleamstudios.co.uk/posts/generalized-linear-models-poisson-regression/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Handling Errors Gracefully</title>
		<link>http://www.wekaleamstudios.co.uk/posts/handling-errors-gracefully/</link>
		<comments>http://www.wekaleamstudios.co.uk/posts/handling-errors-gracefully/#comments</comments>
		<pubDate>Fri, 27 May 2011 20:44:29 +0000</pubDate>
		<dc:creator>Ralph</dc:creator>
				<category><![CDATA[S Programming]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[try]]></category>
		<category><![CDATA[tryCatch]]></category>

		<guid isPermaLink="false">http://www.wekaleamstudios.co.uk/?p=1635</guid>
		<description><![CDATA[In R functions sometimes produces warnings or errors. In the case of errors execution of a function or a series of commands can get halted when an error occurs, which can in some cases be frustrating especially if we want to continue our calculations. There are various functions available in R for dealing with errors [...]]]></description>
			<content:encoded><![CDATA[<p>In <strong>R</strong> functions sometimes produces warnings or errors. In the case of errors execution of a function or a series of commands can get halted when an error occurs, which can in some cases be frustrating especially if we want to continue our calculations.<span id="more-1635"></span></p>
<p>There are various functions available in <strong>R</strong> for dealing with errors and in this post we will consider some basic examples of how to make use of the <strong>try</strong> function.</p>
<p>To illustrate how to use <strong>try</strong> let&#8217;s look at what happens if we run code to print out a non-existent object in our workspace:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">&gt; print(d)
Error in print(d) : object 'd' not found</pre></div></div>

<p>Now if we try to run another command at the same time to print out a string then we would get the following output:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">&gt; print(d); print(&quot;Hi&quot;)
Error in print(d) : object 'd' not found</pre></div></div>

<p>Here execution of the code halts after the first command fails and generates an error. We can modify this code to call the <strong>try</strong> function with the <strong>print</strong> statement:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">&gt; try(print(d)); print(&quot;Hi&quot;)
Error in print(d) : object 'd' not found
[1] &quot;Hi&quot;</pre></div></div>

<p>The second statement is now evaluated even though an error occurs at the first statement. This is a trivial example and in other situations we might consider using the <strong>tryCatch</strong> function which has various arguments in addition to the expression to evaluate including a function to be called when an error occurs.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wekaleamstudios.co.uk/posts/handling-errors-gracefully/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RStudio</title>
		<link>http://www.wekaleamstudios.co.uk/posts/rstudio/</link>
		<comments>http://www.wekaleamstudios.co.uk/posts/rstudio/#comments</comments>
		<pubDate>Fri, 29 Apr 2011 08:47:19 +0000</pubDate>
		<dc:creator>Ralph</dc:creator>
				<category><![CDATA[R Environment]]></category>
		<category><![CDATA[RStudio]]></category>

		<guid isPermaLink="false">http://www.wekaleamstudios.co.uk/?p=1620</guid>
		<description><![CDATA[As has been discussed on various blogs the RStudio interface to R has been released. It is definitely worth checking out as it has the potential to improve the user experience for R.]]></description>
			<content:encoded><![CDATA[<p>As has been discussed on various <a href="http://www.theusrus.de/blog/r-guis-which-one-fits-you/">blogs</a> the <a href="http://www.rstudio.org/">RStudio</a> interface to <a href="http://www.r-project.org/">R</a> has been released. It is definitely worth checking out as it has the potential to improve the user experience for R.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wekaleamstudios.co.uk/posts/rstudio/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>R Matrix Operations</title>
		<link>http://www.wekaleamstudios.co.uk/posts/r-matrix-operations/</link>
		<comments>http://www.wekaleamstudios.co.uk/posts/r-matrix-operations/#comments</comments>
		<pubDate>Sun, 27 Mar 2011 15:09:40 +0000</pubDate>
		<dc:creator>Ralph</dc:creator>
				<category><![CDATA[S Programming]]></category>
		<category><![CDATA[matrix]]></category>

		<guid isPermaLink="false">http://www.wekaleamstudios.co.uk/?p=1607</guid>
		<description><![CDATA[R can be used to perform various matrix calculations. This include functions for creating matrices (matrix), addition (+), multiplication (%*%) and inversion (solve). Fast Tube by Casper Other useful resources are provided on the Supplementary Material page.]]></description>
			<content:encoded><![CDATA[<p><strong>R</strong> can be used to perform various matrix calculations. This include functions for creating matrices (<strong>matrix</strong>), addition (<strong>+</strong>), multiplication (<strong>%*%</strong>) and inversion (<strong>solve</strong>).<span id="more-1607"></span></p>
<p><!--[Fast Tube]--><span id="fF9cV-Fi4wE" style="display:block;"><a title="Click here to watch this video!" href="http://www.wekaleamstudios.co.uk/posts/r-matrix-operations/#fF9cV-Fi4wE"><img src="http://i.ytimg.com/vi/fF9cV-Fi4wE/0.jpg" alt="Fast Tube" border="0" width="320" height="240" /></a><br /><small>Fast Tube by <a title="Casper's Blog" href="http://blog.caspie.net/">Casper</a></small></span><!--[/Fast Tube]--></p>
<p>Other useful resources are provided on the <a href="http://www.wekaleamstudios.co.uk/supplementary-material/">Supplementary Material</a> page.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wekaleamstudios.co.uk/posts/r-matrix-operations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>R Package Automated Download</title>
		<link>http://www.wekaleamstudios.co.uk/posts/r-package-automated-download/</link>
		<comments>http://www.wekaleamstudios.co.uk/posts/r-package-automated-download/#comments</comments>
		<pubDate>Sun, 06 Mar 2011 09:46:41 +0000</pubDate>
		<dc:creator>Ralph</dc:creator>
				<category><![CDATA[R Environment]]></category>
		<category><![CDATA[automate]]></category>
		<category><![CDATA[available.packages]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[download.packages]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[package]]></category>
		<category><![CDATA[repository]]></category>

		<guid isPermaLink="false">http://www.wekaleamstudios.co.uk/?p=1600</guid>
		<description><![CDATA[There are situations where we might want to run R on a standalone machine so need to download a (potentially) large number of packages to install on this system. Rather than having to through the pain of searching through CRAN to find the packages and all the dependencies and manually download, it would be nice [...]]]></description>
			<content:encoded><![CDATA[<p>There are situations where we might want to run <strong>R</strong> on a standalone machine so need to download a (potentially) large number of packages to install on this system. Rather than having to through the pain of searching through CRAN to find the packages and all the dependencies and manually download, it would be nice to be able grab all available packages in one go and then set them up as a local repository.<span id="more-1600"></span></p>
<p>There are some functions provided in <strong>R</strong> that could take away some of the pain. After setting our default repository we can use the <strong>available.packages</strong> function to generate a list of available packages (no surprise there) and then use the <strong>download.packages</strong> function to download them to a suitable directory on our PC.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">&gt; pkg.list = available.packages()
&gt; download.packages(pkgs = pkg.list, destdir = &quot;C:\\MyRPackages&quot;)</pre></div></div>

<p>This will grab the list of available packages and download them to the directory <em>C:\MyRPackages</em> so that they can be installed as required or burnt to CD/DVD and transferred to the standalone PC.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wekaleamstudios.co.uk/posts/r-package-automated-download/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

