Book Review: Exploring Everyday Things with R and Ruby by Sau Sheong Chang (O’Reilly)

Exploring Everyday Things with R and Ruby, as the title suggests, is a book about data exploration, written in a very easy and very unusual way, that will make it hard to put down.

In the beginining it starts with a short introduction to the two languages used to achieve its purpose.

It gives a short explanation about the reason of using Ruby, followed by installation instructions and some basic ruby information. After that there is a short introduction to Ruby’s UI toolkit called Shoes.

The second initial part covers the other language to be used in the examples to follow, R. There are again the reason for picking R, installation instructions and a brief introduction to the capabilities of the language and especially the data analysis and graphing abilities.

Following the first two parts, is where the book starts to get really interesting and fun and it will certainly make you want to try the examples worked on.
Subjects like ‘Offices and Restrooms’ which is about deternining the correct people-to-restrooms ratio, ‘How to Be an Armchair Economist’ about a market economy simulation, ‘Discover Yourself Through Email’ dealing with email data mining, ‘In A Heartbeat’ for measuring the hearbeat, including a homemade digital stethoscope, ‘Schooling Fish and Flocking Birds’ a simulation of the Boids algorithm in Ruby, and finally ‘Money, Sex and Evolution’ an entire artificial world populate by the roids of the previous example.

All of the examples are fascinating, something that I would never imagine it would be possible to simulate before reading this book, and also include information about their specific fields.

So in conclusion, it is a very enjoyable, interesting and out of the ordinary book, helped greatly by the author’s unique writing style, and one that I would recommend to anyone with an interest in Ruby or R to read.

build association for has_one in rails

Problem

You would like to use the build method for creating an association (details) that belongs to another assocation (user).
When the user has many details then you would have something like the following:

class User < ActiveRecord::Base
  has_many :details
end

then you could do:

User.details.build

but when you have:

class User < ActiveRecord::Base
  has_one :detail
end

would throw an error:

NoMethodError: undefined method `build' ...

Solution

In order to be able to use the build in a has_one relation you would need to use like:

User.build_detail

libv8 error in new rails installation

Problem

You are getting a libv8 installation error in a new rails 4.0 application in an older linux installation

An error occurred while installing libv8 (3.16.14.3), and Bundler cannot continue.
Make sure that `gem install libv8 -v '3.16.14.3'` succeeds before bundling.

Solution

This is causes by the latest gem version of the therubyracer dependency on the libv8.
You can get over it by specifying version 0.11.4 for the gem as in:

gem 'therubyracer', '~> 0.11.4', platforms: :ruby

and then running bundle install again.