Upgrading Subversion on Mac OS X

July 27, 2009 by Andrej Kastrin

Leopard comes with preinstalled Subversion 1.4.x by default. You can check out the svn --version command and watch out the output:

$ svn --version
svn, version 1.4.4 (r25188)
  compiled Sep 23 2007, 22:32:34

Copyright (C) 2000-2006 CollabNet.
Subversion is open source software, see http://subversion.tigris.org/
This product includes software developed by CollabNet (http://www.Collab.Net/).

The following repository access (RA) modules are available:

* ra_dav : Module for accessing a repository via WebDAV (DeltaV) protocol.
 - handles 'http' scheme
 - handles 'https' scheme
* ra_svn : Module for accessing a repository using the svn network protocol.
 - handles 'svn' scheme
* ra_local : Module for accessing a repository on local disk.
 - handles 'file' scheme

As you may notice, this is not up to date version of the Subversion client. Currently the most recent binary builds with installer comes from CollabNet. Simply download the package and install the Subversion binaries. By default the CollabNet package installs Subversion to /opt/subversion/bin.

Now we should check which installed instance of the Subversion is used by executing which svn command. This command will return the path to the original Subversion version you are using. On my system this is:

$ which svn
/usr/bin/svn

Note that the path of the build in Subversion client is different to the one that the CollabNet binary is installed to. We must ensure that the new binaries are on the path before original Subversion libraries. Simply open your .bash_profile file in your home folder with your favourite text editor and add /opt/subversion/bin to your PATH:

export PATH=/opt/subversion/bin:$PATH

Now execute the svn --version again and watch the output:

$ svn --version
svn, version 1.6.3 (r38063)
   compiled Jun 23 2009, 16:38:16

Copyright (C) 2000-2009 CollabNet.
Subversion is open source software, see http://subversion.tigris.org/
This product includes software developed by CollabNet (http://www.Collab.Net/).

The following repository access (RA) modules are available:

* ra_neon : Module for accessing a repository via WebDAV protocol using Neon.
  - handles 'http' scheme
  - handles 'https' scheme
* ra_svn : Module for accessing a repository using the svn network protocol.
  - with Cyrus SASL authentication
  - handles 'svn' scheme
* ra_local : Module for accessing a repository on local disk.
  - handles 'file' scheme
* ra_serf : Module for accessing a repository via WebDAV protocol using serf.
  - handles 'http' scheme
  - handles 'https' scheme

It works! The new version is now 1.6.3.

Psychology of object-oriented programming

July 6, 2009 by Andrej Kastrin

When you look at the person on the street, you see the person as an object. Generally, an object is defined by two features: attributes and behaviors. An attribute is a characteristic of an object. The attributes differentiate between the various objects. A person has attributes, such as first name, height, weight, age, hair color, etc. A person also has behaviors, such as breathing, walking, crying, etc. As you may have noticed, a behavior is an action that an object is capable of performing. In other words, behavior of an object is what the object can do.

Object-oriented programming (OOP) is a computer programming paradigm that uses objects and relationships between them to design applications. Objects are building blocks of object-oriented (OO) program. Generally speaking, the OO program is a collection of objects. In computer language an attribute is data associated with an object and behavior is something performed by an object. The aim in OOP is to translate attributes and behaviors of a real-world object into class that consists of attributes and methods understood by a machine. The data of a class is represented by attributes, while methods implement the required behavior of a class.

The abstract object is used to describe a real object. In OOP first we create an abstract object and then use the abstract object to create a real object. A real object is called an instance of the abstract object. Therefore, an instance is a real object. In other words, an instance is the computer’s version of a real object. OOP aims to mimic real-world objects by defining a class. Specifically, you create an object within a program by defining a class. A class consists of data members and member methods. Data members are used to store attributes of an object. Member methods define an object’s behavior. A behavior is emulated in a program by a method. A class is a template of blueprint that defines attributes and methods of a real-world object.

LaTeX, TextMate, and Skim

June 26, 2009 by Andrej Kastrin

First, to sketch out the background. Generally, you need three essential pieces of software to produce and view LaTeX document:

  1. text editor for editing your LaTeX source file,
  2. the LaTeX program for compiling your LaTeX source file into PDF document, and
  3. a PDF viewer for previewing and printing your document.

There is a plethora of LaTeX distributions available for Mac OS X platform. An overview of some well known distributions can be found on TeX on Mac OS X wiki.

If you are using Fink (or MacPorts) for installing packages under Mac OS X, you can install LaTeX using this excellent package manager. Fink users install LaTeX with

$ sudo fink selfupdate
$ sudo fink install tetex

One very useful component of Fink is Fink Commander, which provides friendly GUI front-end to Fink. Find the package “tetex-base” and highlight it. Then press the blue “plus sign” button in the menu bar to install it as a binary package. During the installation Fink Commander will pop up a window asking for you answer; you can continue by simply accepting the default answer. You can find further details addressing Fink (or MacPorts) issues here.

If you are not using Fink, I recommend to install MacTex which is a precompiled TeX Live LaTeX distribution for OS X. By the way, TeX Live is the most popular LaTeX distribution developed by the TeX user groups. At the moment of this writing, MacTeX consist of two parts: MacTeX-2008 and MacTeXtras. MacTeX-2008 is an install package which install everything you need to run LaTeX on Mac OS X. MacTeXtras is a collection of optional extras. The package is huge, so take a cup of coffee (or two) during the download.

Skim is notably the first free PDF viewer for Mac OS X. It’s open-source application, of course. It provides tight interaction with LaTeX and is highly customizable. Download and install Skim.app in the Application folder. Then open Skim’s Preferences dialog, select the Sync tab and make sure that the “Check for file changes” option is disabled and that “PDF-TeX Sync support” is set to the “TextMate” preset.

TextMate is a general-purpose GUI text editor for Mac OS X. TextMate has emerged as the new baseline for what a text editor should be capable of. Actually, it’s not open-source. You can download 30 day trial or purchase a license for €48.75. What makes TextMate so excited for me, is the open-source developer community that provides extensions (bundles) which provide additional functionality to TextMate. At the time of this writing the Subversion repository contains exactly 160 bundles. By default, TextMate comes with integrated LaTeX bundle, so it’s LaTeX-ready.

However, to configure TextMate we should use a LaTeX Preferences dialog which is available under “Bundles -> LaTeX -> Preferences”. Make sure that “Default Engine” is set to “pdflatex” and the “Use Latexmk.pl” option is enabled. Latexmk.pl script automatically runs latex, bibtex, and makeindex as many times as needed to resolve all cross-references and citations in your source file. Finally, you should set “View in” option to “Skim” and ensure that “Show pdf automatically” option is enabled.

LaTeX environment is now ready. To compile your document with LaTeX press ⌘R. You could also select “Typeset & View (PDF)” in the LaTeX bundle menu. TextMate shows the log messages, warnings and errors generated during the compilation in a popup window. Skim opens automatically if the LaTeX compilation was successful.

Batch processing with R

June 18, 2009 by Andrej Kastrin

According to Wikipedia batch processing is execution of a series of programs (“jobs”) without human interaction. Batch job can run non-interactively, so all input data is preselected through scripts or command-line parameters.

R provides you a simple way to run a script non-interactively with input file from “infile” and send output to “outfile”. You can also pass arguments to batch job.

First we use “cat” command and “>” operator to create a small script file. The “cat” command takes input from keyboard and redirect it to a file:

$ cat > hello_world.R
# Hello World example
a <- c("Hello, world!")
print(a)

Type “Control-D” to signal the end of the code. Now we use the R command mode to send “hello_world.R” as a batch job from [STDIN] and show the result on [STDOUT]:

$ R --vanilla --slave < hello_world.R

This command says “invoke hello_world.R non-interactively”. By default, the output is shown on the screen, but we can use “>” operator to redirect it to a file:

$ R --vanilla --slave < hello_world.R > result.txt

More interesting job is to pass our own arguments to script. Let’s put some commands into a script file:

$ cat > print_args.R << EOF
args <- commandArgs()
print(args)
q()
EOF

And running it looks like:

$ R --slave "--args a=100 b=200" < print_args.R
[1] "/Library/Frameworks/R.framework/Resources/bin/exec/i386/R"
[2] "--slave"
[3] "--args"
[4] "a=100"
[5] "b=200"

The “commandArgs()” function has an argument “trailingOnly”; when TRUE the function only returns the script-specific arguments after the “args” argument. So we can slightly modify our script:

$ cat > print_my_args.R << EOF
args <- commandArgs(TRUE)
print(args)
q()
EOF

The output of this command then returns:

$ R --slave "--args a=100 b=200" < print_my_args.R
[1] "a=100" "b=200"

References:

Setting environment variable in Mac OS X

June 16, 2009 by Andrej Kastrin

If you want to run RSRuby with Eclipse then you have ensure that the R_HOME environment variable is set correctly. On OS X this is R_HOME=/Library/Frameworks/R.framework/Resources. Basically there are several ways to do that.

There is a special environment file which reads each time a user logs in. The environment file is ~/.MacOSX/environment.plist. The dot (.) in the front the folder name makes it hidden so it won’t be visible in Finder by default. If environment.plist file is there you can open it with Property List Editor, otherwise you will have to create it yourself.

To create the directory and the file open the Terminal.app and type:

$ cd
$ mkdir .MacOSX
$ touct .MacOSX/environment.plist
$ open .MacOSX/environment.plist

This should open a new, empty environment.plist file in Property List Editor. Select Root and Add a Child. The key should be the name of variable you want to set (R_HOME), Class should be string (string), and Value should be the value you want to set for this variable (/Library/Frameworks/R.framework/Resources).

Now you should log out and in again to bring the new environment variable into action.

References

The Classification Song

March 4, 2009 by Andrej Kastrin

The Classification Song

(After Mozart’s “Bastien und Bastienne”, 4th Scene, No.8)

Lyrics: Claus Weihs
Singer: Claus Weihs
Piano: Julia Schiffner


We are here to praise together:
Classification, Data Analysis,
With this song to show their strengths
Classification, Data Analysis,
Support progress mathematic’lly,
mathematic’lly.
We have learned classes are fuzzy,
and regression is outdated,
So, we are modern now
applying Art’ficial Neural Nets
And Support Vector Machines.

Replace trees by random forests,
do not use the good old err’r rates
but turn over to ideal features.
Be as modern as you can,
Be as modern as you can,
And invent clever involved theories
Just forget interpretation
and be optimal instead.

We are here to praise together:
Classification, Data Analysis,
With this song to show their strengths
Classification, Data Analysis,
Support progress mathematic’lly,
mathematic’lly.
We apply our newest methods
to all fields of science now,
econometrics, biometrics,
even music, linguistics,
and archaeology.

Let us link these different fields
To make clear our ubiquity
And our indispensability.
So, remember all the time,
That our methods have to be applied,
Thus, take care of practical tools.
And prepare interpretation,
Be as simple as you can.

1o steps to become a better writer

October 29, 2008 by Andrej Kastrin

1o steps to become a better writer by Brian Clark:

  1. Write.
  2. Write more.
  3. Write even more.
  4. Write even more than that.
  5. Write when you don’t want to.
  6. Write when you do.
  7. Write when you have something to say.
  8. Write when you don’t.
  9. Write every day.
  10. Keep writing.

Writing strategies of productive academic writing

October 15, 2008 by Andrej Kastrin

Times ago Hartley and Branthwaite (1989) conduct interesting survey among British psychologist on their writing habits and their attitudes about academic writing. They found out that the highly productive writers of papers did not always enjoy expressing what they wanted to say as much as their less productive colleagues, but they felt that their writing was very important to them. In the conclusion they also provide us a set of strategies for better academic writing:

  1. Make a rough plan (which you needn’t necessarily stick to).
  2. Complete sections one at a time. It may help to do them in order.
  3. Use a word processor if possible. :)
  4. Revise and redraft at least twice.
  5. Plan to spend about 2-5 hours writing per week in term time.
  6. Find quiet conditions in which to write and, if possible, always write in the same place (or places).
  7. Set goals and targets for yourself.
  8. Get colleagues and friends to comment on early drafts.
  9. Collaborate with longstanding colleagues and trusted friends.

Tuzla, 11 October 2008

October 12, 2008 by Andrej Kastrin

Yesterday I had a lecture at the University of Tuzla (Bosnia and Herzegovina). The meeting was organized by professor Terzić and his group. I talked about meta-analysis. Meta analysis, primary originating in psychology, is one of the most important tools in modern molecular biology and genetics in particular. This was my first visit of Bosnia, excluding short crosses en route to South Dalmatia.

How to write a lot by Paul J. Silvia

October 10, 2008 by Andrej Kastrin

That’s the title of the book which I order a few weeks ago. Although the author is psychologist and he writes from a point of view of a researcher in that domain, he provides the reader with a lot of useful advices and helpful suggestions about effective publishing. Silvia claims that writing is a habit and that the scholar needs a schedule to write. Like you brush your teeth, wake up at 4 a.m. when your baby has a nightmare, etc., you should schedule your writing. The major hint I took from Silvia is to write every day.