<?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>Linux etc. &#187; R</title>
	<atom:link href="http://promberger.info/linux/category/r/feed/" rel="self" type="application/rss+xml" />
	<link>http://promberger.info/linux</link>
	<description>my outsourced memory for your perusal</description>
	<lastBuildDate>Thu, 08 Sep 2011 11:06:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>ggplot2 error &#8220;invalid argument to unary operator&#8221;</title>
		<link>http://promberger.info/linux/2011/08/08/ggplot2-error-invalid-argument-to-unary-operator/</link>
		<comments>http://promberger.info/linux/2011/08/08/ggplot2-error-invalid-argument-to-unary-operator/#comments</comments>
		<pubDate>Mon, 08 Aug 2011 14:24:05 +0000</pubDate>
		<dc:creator>Marianne</dc:creator>
				<category><![CDATA[R]]></category>

		<guid isPermaLink="false">http://promberger.info/linux/?p=377</guid>
		<description><![CDATA[I had a longish ggplot command and kept getting the error: invalid argument to unary operator It happened when I was specifying custom labels with scale_y_continuous but it turns out this was irrelevant and it hinged on a line break. It turnsout (at least when stepping through the code with ESS in Emacs using C-c [...]]]></description>
			<content:encoded><![CDATA[<p>I had a longish ggplot command and kept getting the error:</p>
<pre>invalid argument to unary operator</pre>
<p>It happened when I was specifying custom labels with <code>scale_y_continuous</code> but it turns out  this was irrelevant and it hinged on a line break. It turnsout (at least when stepping through the code with ESS in Emacs using <code>C-c C-c</code>, bound to <code>ess-eval-function-or-paragraph-and-step</code>, you need to have the <code>+</code> of tying different ggplot bits together on the end of the preceding line.</p>
<p>This won&#8217;t work:</p>
<pre>ggplot(longdata, aes(x=x, y = y))
+ geom_jitter(alpha = 0.6)
</pre>
<p>This will:</p>
<pre>
ggplot(longdata, aes(x=x, y = y)) +
geom_jitter(alpha = 0.6)
</pre>
<p>(Or, put it all on one line).</p>
]]></content:encoded>
			<wfw:commentRss>http://promberger.info/linux/2011/08/08/ggplot2-error-invalid-argument-to-unary-operator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How not to ask a question on R-help</title>
		<link>http://promberger.info/linux/2010/02/12/how-not-to-ask-a-question-on-r-help/</link>
		<comments>http://promberger.info/linux/2010/02/12/how-not-to-ask-a-question-on-r-help/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 12:03:20 +0000</pubDate>
		<dc:creator>Marianne</dc:creator>
				<category><![CDATA[Noobs]]></category>
		<category><![CDATA[R]]></category>

		<guid isPermaLink="false">http://promberger.info/linux/?p=349</guid>
		<description><![CDATA[One great way to get help with R is by asking a question on the r-help mailing list. More often than not I have actually figured out the answer simply by typing up the question, because that made me think more clearly about what the problem really was. The people on the list are exceedingly [...]]]></description>
			<content:encoded><![CDATA[<p>One great way to get help with R is by asking a question on the r-help mailing list. More often than not I have actually figured out the answer simply by typing up the question, because that made me think more clearly about what the problem really was. The people on the list are exceedingly helpful. Not all of the posters are. I&#8217;ll now start collecting some fun examples of threads which might be called &#8220;How not to ask a quesiton on R-help&#8221;. Here is <a href="http://tolstoy.newcastle.edu.au/R/e9/help/10/02/4677.html">the first one</a>. Nice quote from Greg Snow:</p>
<blockquote><p>
If you show us your data/code/output as has been requested, then we may be able to tell which it is. Without that information you are expecting either R or the members of the list to read your mind.  I keep making notes to my future self to use the timetravel package (not written yet, that&#8217;s why I need my future self to use it) to send a copy of the esp package (also not written yet) back in time to me so I can use it for situations like this.  But so far that has not worked (maybe my future self is even more lazy than my present self, or my near future self does something to offend my far future self enough that he is unwilling to do this small favor for my current past self, darn, either way means I should probably do better on the diet/exercise).
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://promberger.info/linux/2010/02/12/how-not-to-ask-a-question-on-r-help/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>R: loops vs apply (vectorization)</title>
		<link>http://promberger.info/linux/2010/02/10/r-loops-vs-apply-vectorization/</link>
		<comments>http://promberger.info/linux/2010/02/10/r-loops-vs-apply-vectorization/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 14:08:03 +0000</pubDate>
		<dc:creator>Marianne</dc:creator>
				<category><![CDATA[R]]></category>

		<guid isPermaLink="false">http://promberger.info/linux/?p=346</guid>
		<description><![CDATA[A helpful article in by Uwe Ligges and John Fox in R news 2008(1), pp 46-50, about loops vs. apply was just pointed out on R-help. I&#8217;ve uploaded it here (pdf).]]></description>
			<content:encoded><![CDATA[<p>A helpful article in by Uwe Ligges and John Fox in R news 2008(1), pp 46-50, about loops vs. apply was just pointed out on R-help. I&#8217;ve uploaded it <a href="http://promberger.info/files/rnews-vectorvsloops2008.pdf">here (pdf)</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://promberger.info/linux/2010/02/10/r-loops-vs-apply-vectorization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My first RMySQL session</title>
		<link>http://promberger.info/linux/2010/01/21/my-first-rmysql-session/</link>
		<comments>http://promberger.info/linux/2010/01/21/my-first-rmysql-session/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 14:01:48 +0000</pubDate>
		<dc:creator>Marianne</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[R]]></category>

		<guid isPermaLink="false">http://promberger.info/linux/?p=332</guid>
		<description><![CDATA[# 'fai1' is an empty MySQL database for which 'mpromber' has all privileges mycon]]></description>
			<content:encoded><![CDATA[<pre># 'fai1' is an empty MySQL database for which 'mpromber' has all privileges
mycon <- dbConnect(MySQL(),user='mpromber',dbname='fai1') # pass seems to be read from ~/.my.cnf
# dsub is a data frame:
dbWriteTable(mycon,"dsub",dsub) # create table "dsub"
dbDisconnect(mycon) # close connection
</pre>
<p>Time for lunch.</p>
]]></content:encoded>
			<wfw:commentRss>http://promberger.info/linux/2010/01/21/my-first-rmysql-session/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>r-cran-rmysql</title>
		<link>http://promberger.info/linux/2010/01/20/r-cran-rmysql/</link>
		<comments>http://promberger.info/linux/2010/01/20/r-cran-rmysql/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 15:39:05 +0000</pubDate>
		<dc:creator>Marianne</dc:creator>
				<category><![CDATA[R]]></category>

		<guid isPermaLink="false">http://promberger.info/linux/?p=328</guid>
		<description><![CDATA[Memo to self: I installed RMySQL using sudo aptitude install r-cran-rmysql because when I used install.packages("RMySQL") it asked my to specify the MySQL libraries and headers and whatnot and don&#8217;t know where they are.]]></description>
			<content:encoded><![CDATA[<p>Memo to self: I installed RMySQL using </p>
<pre>sudo aptitude install r-cran-rmysql</pre>
<p>because when I used </p>
<pre>install.packages("RMySQL")</pre>
<p>it asked my to specify the MySQL libraries and headers and whatnot and don&#8217;t know where they are.</p>
]]></content:encoded>
			<wfw:commentRss>http://promberger.info/linux/2010/01/20/r-cran-rmysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use R to help with lottery drawing</title>
		<link>http://promberger.info/linux/2010/01/07/use-r-to-help-with-lottery-drawing/</link>
		<comments>http://promberger.info/linux/2010/01/07/use-r-to-help-with-lottery-drawing/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 13:04:50 +0000</pubDate>
		<dc:creator>Marianne</dc:creator>
				<category><![CDATA[Noobs]]></category>
		<category><![CDATA[R]]></category>

		<guid isPermaLink="false">http://promberger.info/linux/?p=325</guid>
		<description><![CDATA[When you start using R, it can be confusing that if you assign something to an object you do not get visual feedback: x x [1] 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 You can exploit this fact for doing a quick-and-dirty lottery. Assume you have a [...]]]></description>
			<content:encoded><![CDATA[<p>When you start using R, it can be confusing that if you assign something to an object you do not get visual feedback:</p>
<pre>x <- rep(1:3,5)</pre>
<p>You have to then type <code>x</code> to see it:</p>
<pre>> x
 [1] 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3</pre>
<p>You can exploit this fact for doing a quick-and-dirty lottery. Assume you have a file with email addresses, one per line, called "entries.txt". First, read them and assign them to an object:</p>
<pre>entries <- readLines("entries.txt")</pre>
<p>Next, create an index of numbers of the same length but in random order:</p>
<pre>index <- sample(1:length(entries),length(entries))</pre>
<p>Note that you don't see it unless you type <code>index</code>. Combine index and emails in a dataframe (also not directly visible):</p>
<pre>dat <- data.frame(cbind(index,entries))</pre>
<p>Now, go to <a href="http://random.org">random.org</a> and draw a number from the index. Type <code>dat</code> to reveal who you drew. This method makes it a bit more "blind" and a bit less likely that you'll cheat.</p>
]]></content:encoded>
			<wfw:commentRss>http://promberger.info/linux/2010/01/07/use-r-to-help-with-lottery-drawing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nice R example from r-help</title>
		<link>http://promberger.info/linux/2009/11/05/nice-r-example-from-r-help/</link>
		<comments>http://promberger.info/linux/2009/11/05/nice-r-example-from-r-help/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 14:48:34 +0000</pubDate>
		<dc:creator>Marianne</dc:creator>
				<category><![CDATA[R]]></category>

		<guid isPermaLink="false">http://promberger.info/linux/?p=317</guid>
		<description><![CDATA[I don&#8217;t know the first thing about programming, but sometimes you see something and appreciate how elegant it is. This small solution from r-help is a good example. Someone wanted, given a vector c('p','p','t','t','t','p','k','t') to produce NA NA 1 2 3 test]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t know the first thing about programming, but sometimes you see something and appreciate how elegant it is. This small solution from <a href="http://tolstoy.newcastle.edu.au/R/e8/help/09/11/3767.html">r-help</a> is a good example. Someone wanted, given a vector <code>c('p','p','t','t','t','p','k','t')</code> to produce <code>NA NA 1 2 3</code></p>
<pre>
test <- c('p','p','t','t','t','p','k','t')
v <- cumsum(ind <- test == 't')
v[!ind] <- NA
</pre>
<p>I didn't know you could assign something to an object and use it at the same time. Very neat. So if you wanted this all at once, you could also do:</p>
<pre>v <- ifelse(cumsum(ind <- test=='t')==0,NA,cumsum(ind))</pre>
<p>or</p>
<pre>ifelse((v <- cumsum(test=='t'))==0,NA,v)</pre>
<p>Maybe Dimitris' solution is in fact preferred for R, using indexing instead of if/ else, but I don't know enough about R to know whether that makes a difference.</p>
]]></content:encoded>
			<wfw:commentRss>http://promberger.info/linux/2009/11/05/nice-r-example-from-r-help/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>R: watch out when comparing vectors using &#8220;==&#8221;</title>
		<link>http://promberger.info/linux/2009/09/25/r-watch-out-when-comparing-vectors-using/</link>
		<comments>http://promberger.info/linux/2009/09/25/r-watch-out-when-comparing-vectors-using/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 08:37:33 +0000</pubDate>
		<dc:creator>Marianne</dc:creator>
				<category><![CDATA[R]]></category>

		<guid isPermaLink="false">http://promberger.info/linux/?p=295</guid>
		<description><![CDATA[This question was on the R-help mailing list today: I have a data frame &#8220;test&#8221;: test test$total [1] 7 7 8 8 9 9 10 10 to this: > rep(needed,length.out=length(test$total)) [1] 7 9 7 9 7 9 7 9 The two vectors just happen to coincide at test$total[1] and test$total[6]. The recycling is of course [...]]]></description>
			<content:encoded><![CDATA[<p>This question was on the R-help mailing list today:</p>
<blockquote><p>
I have a data frame &#8220;test&#8221;:</p>
<pre>test<-data.frame(x=c(1,2,3,4,5,6,7,8),y=c(2,3,4,5,6,7,8,9),total=c(7,7,8,8,9,9,10,10))
test</pre>
<p>I have a vector "needed":</p>
<pre>needed<-c(7,9)
needed</pre>
<p>I need the result to look like this:</p>
<pre>1 2 7
2 3 7
5 6 9
6 7 9</pre>
<p>When I do the following:</p>
<pre>result<-test[test["total"]==needed,]
result</pre>
<p>I only get unique rows that have 7 or 9 in "total":</p>
<pre>1 2 7
6 7 9</pre>
<p>[...]
</p></blockquote>
<p>The solution is to use <code>%in%</code> instead:</p>
<pre>test[test$total %in% needed,]</pre>
<p>A quick aside: note that you don't select the column "total" by using <code>test["total"]</code>, instead, you need to index correctly and use <code>test[,"total"]</code>, or, more succinctly, use <code>test$total</code> for dataframes. Check also <code>identical(test["total"],test$total)</code> and <code>identical(test[,"total"],test$total)</code>.</p>
<p>Why doesn't <code>==</code> work here? It works just fine if you want to find all rows where the column <code>total</code> equals 7:</p>
<pre>test[test$total == 7,]</pre>
<p>The trick is that to R, <code>test$total</code>, <code>needed</code> and <code>7</code> are all vectors. <code>==</code> compares them element by element. Since <code>7</code> and <code>needed</code> are shorter than <code>test$total</code>, they are recycled as often as needed to give the same length as <code>test$total</code>. (Note, by the way, that you can of course directly look at the logical index by typing: <code>test$total==needed</code>.) So what R is doing is comparing this:</p>
<pre>> test$total
[1]  7  7  8  8  9  9 10 10</pre>
<p>to this:</p>
<pre>> rep(needed,length.out=length(test$total))
[1] 7 9 7 9 7 9 7 9</pre>
<p>The two vectors just happen to coincide at test$total[1] and test$total[6]. The recycling is of course no problem when you look for matches with a single number, because:</p>
<pre>> rep(7,length.out=length(test$total))
[1] 7 7 7 7 7 7 7 7</pre>
<p>will do just fine.</p>
<p>To get the help text on <code>%in%</code> by the way, you need to quote it:</p>
<pre>?"%in%"</pre>
]]></content:encoded>
			<wfw:commentRss>http://promberger.info/linux/2009/09/25/r-watch-out-when-comparing-vectors-using/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to install RGoogleDocs (on Ubuntu)</title>
		<link>http://promberger.info/linux/2009/09/14/rgoogledocs/</link>
		<comments>http://promberger.info/linux/2009/09/14/rgoogledocs/#comments</comments>
		<pubDate>Mon, 14 Sep 2009 12:40:23 +0000</pubDate>
		<dc:creator>Marianne</dc:creator>
				<category><![CDATA[R]]></category>

		<guid isPermaLink="false">http://promberger.info/linux/?p=277</guid>
		<description><![CDATA[RGoogleDocs is not available from CRAN, but from Omegahat.org. To install, sudo R, then install.packages("RGoogleDocs", repos = "http://www.omegahat.org/R") RGoogleDocs requires RCurl, and will automatically install it. However, for me, this resulted in the error message: checking for curl-config... no Cannot find curl-config and RGoogleDocs was not installed. This is in fact in the RCurl FAQ. [...]]]></description>
			<content:encoded><![CDATA[<p>RGoogleDocs is not available from CRAN, but from <a href="http://www.omegahat.org/RGoogleDocs/">Omegahat.org</a>. To install, <code>sudo R</code>, then</p>
<pre>install.packages("RGoogleDocs", repos = "http://www.omegahat.org/R")</pre>
<p>RGoogleDocs requires RCurl, and will automatically install it. However, for me, this resulted in the error message:</p>
<pre>checking for curl-config... no
Cannot find curl-config</pre>
<p>and RGoogleDocs was not installed. This is in fact in the <a href="http://www.omegahat.org/RCurl/FAQ.html">RCurl FAQ</a>. The solution may differ for your system, but on Xubuntu Jaunty I needed to get:</p>
<pre>sudo aptitude install libcurl4-gnutls-dev</pre>
<p>This fixed the RCurl problem, but I installation of XML (also required, and also automatically installed when you install RGoogleDocs) failed with:</p>
<pre>checking for xml2-config... no
Cannot find xml2-config
ERROR: configuration failed for package �XML�</pre>
<p>You guessed it:</p>
<pre>sudo aptitude install libxml2-dev</pre>
<p>So here&#8217;s the whole thing for cut-and-paste:</p>
<pre>sudo aptitude install libcurl4-gnutls-dev libxml2-dev</pre>
<p>Then:</p>
<pre>sudo R</pre>
<p>Then, inside R:</p>
<pre>install.packages("RGoogleDocs", repos = "http://www.omegahat.org/R")</pre>
<h3>Addendum</h3>
<p>Just had to install RGoogleDocs again and had a different issue. It complained that it couldn&#8217;t get package <code>bitops</code> which seems to be a depenency for RCurl. First step (which I just learned):</p>
<pre>install.packages("RGoogleDocs", repos = "http://www.omegahat.org/R", dependencies = TRUE)</pre>
<p>was not sufficient in my case. Had to manually first</p>
<pre>install.packages("bitops")</pre>
<h3>Addendum</h3>
<p>Version 0.4.0, which you get from Omegahat, doesn&#8217;t work but throws an authentication failure when you try to load a spreadsheet.<br />
Try version <a href="http://www.omegahat.org/RGoogleDocs/RGoogleDocs_0.4-1.tar.gz">0.4.1</a> (downloads a .tar.gz file). To install the file:</p>
<pre>install.packages("~/downloads/RGoogleDocs_0.4-1.tar.gz",repos=NULL)</pre>
<p> (of course, replace ~/downloads/ with the appropriate directory).<br />
<strong>Doesn&#8217;t work for me</strong> (22/2/2011). I still get &#8220;unauthorized&#8221; when trying to access a document (I can access the list of documents just fine).</p>
]]></content:encoded>
			<wfw:commentRss>http://promberger.info/linux/2009/09/14/rgoogledocs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Emacs with ESS and AucTeX on Windows</title>
		<link>http://promberger.info/linux/2009/09/14/emacs-with-ess-and-auctex-on-windows/</link>
		<comments>http://promberger.info/linux/2009/09/14/emacs-with-ess-and-auctex-on-windows/#comments</comments>
		<pubDate>Mon, 14 Sep 2009 10:53:14 +0000</pubDate>
		<dc:creator>Marianne</dc:creator>
				<category><![CDATA[Emacs]]></category>
		<category><![CDATA[LaTeX]]></category>
		<category><![CDATA[MS Windows]]></category>
		<category><![CDATA[R]]></category>

		<guid isPermaLink="false">http://promberger.info/linux/?p=270</guid>
		<description><![CDATA[I will have to use MS Windows for my new job, at least some of the time. I&#8217;ll put related posts in a new &#8220;MS Windows&#8221; category. If you use R, you most likely want ESS (Emacs Speaks Statistics) for your GNU Emacs. If you use LaTeX, you will also want AucTeX. I highly recommend [...]]]></description>
			<content:encoded><![CDATA[<p>I will have to use MS Windows for my new job, at least some of the time. I&#8217;ll put related posts in a new &#8220;MS Windows&#8221; category.</p>
<p>If you use <a href="http://www.r-project.org">R</a>, you most likely want <a href="http://ess.r-project.org/">ESS (Emacs Speaks Statistics)</a> for your GNU Emacs. If you use LaTeX, you will also want AucTeX. </p>
<p>I highly recommend you use <a href="http://vgoulet.act.ulaval.ca/en/ressources/emacs/">Vincent Goulet&#8217;s modified Emacs version</a>. As an additional benefit, it comes as a convenient self-installing .exe file.</p>
<p>Thanks Vincent!</p>
<p>p.s. To get LaTeX on Windows, you will want to get <a href="http://miktex.org/">MiKTeX</a>. MiKTeX is very nice and can auto-install missing packages on the fly when you want to use them in a document.</p>
]]></content:encoded>
			<wfw:commentRss>http://promberger.info/linux/2009/09/14/emacs-with-ess-and-auctex-on-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

