<?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>Amble Ramble</title>
	<atom:link href="http://ambleramble.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://ambleramble.org</link>
	<description></description>
	<lastBuildDate>Mon, 19 Mar 2012 21:16:05 +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>Connecting R to a PostgreSQL Database</title>
		<link>http://ambleramble.org/2012/03/19/connecting-r-to-a-postgresql-database/</link>
		<comments>http://ambleramble.org/2012/03/19/connecting-r-to-a-postgresql-database/#comments</comments>
		<pubDate>Mon, 19 Mar 2012 21:16:05 +0000</pubDate>
		<dc:creator>Roy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ambleramble.org/?p=38</guid>
		<description><![CDATA[Connecting R to a PostgreSQL Database We’ve an amazing collection of data stored in a PostgreSQL database. I use R for help visualizing and analyzing some of this data. In the past I’ve used ODBC for general database connectivity and RODBC from within R. I’ve found setup of ODBC with PostgreSQL driver quick and easy [...]]]></description>
			<content:encoded><![CDATA[<h1>Connecting R to a PostgreSQL Database</h1>
<p>We’ve an amazing collection of data stored in a PostgreSQL database. I use R for help visualizing and analyzing some of this data. In the past I’ve used ODBC for general database connectivity and RODBC from within R.</p>
<p>I’ve found setup of ODBC with PostgreSQL driver quick and easy in Ubuntu Linux. Something along the lines of this (untested) block of code:</p>
<p><code>sudo apt-get install odbc-postgresql<br />
sudo sh -c 'echo "[PostgreSQL]<br />
Description = PostgreSQL driver for Linux &amp; Windows<br />
Driver = /usr/lib/odbc/psqlodbcw.so<br />
Setup = /usr/lib/odbc/libodbcpsqlS.so" > /etc/odbcinst.ini'</p>
<p>sudo sh -c 'echo "[ODBC Data Sources]<br />
demodb = The Data Base</p>
<p>[demodb]<br />
Driver = /usr/lib/odbc/psqlodbcw.so<br />
Database = demo<br />
Servername = localhost<br />
Port = 5432<br />
Protocol = 9.0.5<br />
ReadOnly = Yes</p>
<p>[ODBC]<br />
InstallDir = /usr/lib" >> /etc/odbc.ini'<br />
</code></p>
<p>Continue by installing the RODBC library within R and everything is good to go.  And then I got a Mac…</p>
<h2>Problems with ODBC in OSX</h2>
<p>I tried to use a similar ODBC setup to communicate with the PostgreSQL database on my MacBook, but I failed to succeed in doing this.</p>
<p>First attempt used the <a href="http://www.iodbc.org/dataspace/iodbc/wiki/iODBC/Downloads">iODBC</a> framework configured and the <a href="http://www.postgresql.org/ftp/odbc/versions/src/">psqlodbc driver</a> configured using advice on setting up linker flags from this <a href="http://archives.postgresql.org/pgsql-odbc/2008-09/msg00032.php">email</a>. Attempts to connect using RODBC segfaulted.</p>
<p>Second attempt tried using unixODBC installed via <tt>port</tt> and a reconfigured <a href="http://www.postgresql.org/ftp/odbc/versions/src/">psqlodbc driver</a>. Attempts to connect using RODBC segfaulted again.</p>
<p>I poked a bit outside of R to see if I could spot the problem. Testing outside of R seemed to show that ODBC was unable to connect to my server, but didn’t spend very much time getting a solid diagnosis. I wanted a solution that worked, rather than one that required non-trivial compiling, configuring, and testing. Having burnt my allocated time on documentation and forums I decided to try solutions outside of ODBC.</p>
<h2>Solution with RPostgreSQL with DBI</h2>
<p>A bit of forum searching brought me upon this email describing <a href="https://stat.ethz.ch/pipermail/r-help/2010-October/256938.html">how to connect to a remote PostgreSQL database from R on mac osx</a>. I was happy to see that the external dependancies I’m used to with ODBC did not exist. Installed the <a href="http://cran.r-project.org/web/packages/DBI/index.html">DBI</a> and <a href="http://cran.r-project.org/web/packages/RPostgreSQL/index.html">RPostgreSQL</a> R libraries, then fired up R.</p>
<p><code>$ R<br />
> dbname <- "demo"<br />
> dbuser <- "demo_uer"<br />
> dbpass <- "demo_password"<br />
> dbhost <- "localhost"<br />
> dbport <- 5432<br />
> drv <- dbDriver("PostgreSQL")<br />
> con <- dbConnect(drv, host=dbhost, port=dbport, dbname=dbname,<br />
                   user=dbuser, password=dbpass)<br />
> dbListTables(con)<br />
</code></p>
<p>All good! I guess that moving forward I’ll transition myself over to using RPostgreSQL with DBI within R.</p>
]]></content:encoded>
			<wfw:commentRss>http://ambleramble.org/2012/03/19/connecting-r-to-a-postgresql-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Django Setup from Shell</title>
		<link>http://ambleramble.org/2011/09/01/django-setup-from-shell/</link>
		<comments>http://ambleramble.org/2011/09/01/django-setup-from-shell/#comments</comments>
		<pubDate>Thu, 01 Sep 2011 21:50:37 +0000</pubDate>
		<dc:creator>Roy</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://ambleramble.org/?p=32</guid>
		<description><![CDATA[Django uses a number of settings typically defined in the settings module within a project. These can be loaded into the interactive python shell for extra interactive fun. from django.core.management import setup_environ from myapp import settings setup_environ(settings)]]></description>
			<content:encoded><![CDATA[<p>Django uses a number of settings typically defined in the <tt>settings</tt> module within a project.  These can be loaded into the interactive python shell for extra interactive fun.</p>
<p><code>from django.core.management import setup_environ<br />
from myapp import settings<br />
setup_environ(settings)<br />
</code> </p>
]]></content:encoded>
			<wfw:commentRss>http://ambleramble.org/2011/09/01/django-setup-from-shell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generating PNGs from matplotlib on a Server</title>
		<link>http://ambleramble.org/2011/03/24/png-matplotlib-server/</link>
		<comments>http://ambleramble.org/2011/03/24/png-matplotlib-server/#comments</comments>
		<pubDate>Thu, 24 Mar 2011 23:38:05 +0000</pubDate>
		<dc:creator>Roy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ambleramble.org/?p=28</guid>
		<description><![CDATA[Migrated from my local machine to a remote server a data analysis that plots data using Python&#8217;s matplotlib and saves the plots to PNGs. Running the analysis turned up an unexpected error that ends by noting: no display name and no $DISPLAY environment variable Bummer. A quick search turned up more documentation on this from [...]]]></description>
			<content:encoded><![CDATA[<p>Migrated from my local machine to a remote server a data analysis that plots data using Python&#8217;s matplotlib and saves the plots to PNGs.  Running the analysis turned up an unexpected error that ends by noting:</p>
<p><code>no display name and no $DISPLAY environment variable</code></p>
<p>Bummer.  A quick search turned up more documentation on this from both the official matplotlib documentation on <a href="http://matplotlib.sourceforge.net/faq/howto_faq.html#howto-webapp">using matplotlib in a webapp</a> and <a href="http://stackoverflow.com/questions/2801882/generating-a-png-with-matplotlib-when-display-is-undefined">generating PNGs in matplotlib when DISPLAY is not defined</a>.</p>
<p>The two typical solutions are to explicitly set a backend in the Python code (this must be done before any other matplotlib imports):</p>
<p><code>import matplotlib<br />
# Force matplotlib to not use any Xwindows backend.<br />
matplotlib.use('Agg')</code></p>
<p>or set the backend using the matplotlibrc file.</p>
]]></content:encoded>
			<wfw:commentRss>http://ambleramble.org/2011/03/24/png-matplotlib-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Summing a Column of Numbers</title>
		<link>http://ambleramble.org/2011/02/06/summing-a-column-of-numbers/</link>
		<comments>http://ambleramble.org/2011/02/06/summing-a-column-of-numbers/#comments</comments>
		<pubDate>Mon, 07 Feb 2011 06:09:55 +0000</pubDate>
		<dc:creator>Roy</dc:creator>
				<category><![CDATA[Shell]]></category>

		<guid isPermaLink="false">http://ambleramble.org/?p=21</guid>
		<description><![CDATA[I&#8217;m a command line junkie who only turns to higher level scripting when a line of piped together commands falls short. A common task that I run into is summing a column of data from a text file. Typically, my data is in a gnuplot friendly format makes extracting the column easy: grep -v "^#" [...]]]></description>
			<content:encoded><![CDATA[<p>
I&#8217;m a command line junkie who only turns to higher level scripting when<br />
a line of piped together commands falls short.  A common task that I run<br />
into is summing a column of data from a text file.  Typically, my data<br />
is in a gnuplot friendly format makes extracting the column easy:
</p>
<p><code>grep -v "^#" bandwidth.dat | cut -f3 -d' '</code></p>
<p>
Now what is an easy way to sum that data?  I&#8217;ve seen solutions using<br />
awk, but I&#8217;m not much of an awk fan.  Much more exciting is a version<br />
using paste:
</p>
<p><code>grep -v "^#" bandwidth.dat | cut -f3 -d' ' | paste -sd + | bc</code></p>
]]></content:encoded>
			<wfw:commentRss>http://ambleramble.org/2011/02/06/summing-a-column-of-numbers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

