Thursday, March 26, 2009

Installing packages in R

R is an open source statistical tool which has received a lot of attention in recent days.
For some time, I have been an active user of that tool because my PhD research requires some kind of statistical analysis. I found an interesting article about fitting distributions with R in which the author employs some R libraries that don't come included with the R basic installation.
The easy way to install additional libraries is using your 'root' system account. Thus,  execute 'R' and invoke the 'install.packages()' command from the R prompt.
In my case, I  selected the required libraries ('vcd' and 'fBasics') and 'OK' button. However the compilation process failed. So, previous to install/compile any additional R package it is necessary to install the 'R-devel' package.
Afterward, I installed 'vcd' first and then 'fBasics'. Now, I got a succeeded installation.

Additional Resources

Tuesday, March 17, 2009

inserting hibernate_sequence and current date and time in PostgreSQL

Recently, I need to add a record in a table from a database instance created by Grails.
Grails relies on hibernate to make persistent all domain classes defined in an application. Thus, most of the Grails applications define a hibernate_sequence in their database model.
In particular, I'm working with grails 1.0.3 and PostgreSQL as my back-end.

Now, I needed to insert a new record in one table from my Grails application which also has an  attribute of type 'Date'.

For simplicity assume that my table exhibits the following structure:

Table 'demo'

id -> bigint
date -> timestamp
name -> character varying(255)

     "demo_pkey' PRIMARY KEY, btree(id)

In order to make a proper insertion of a new record, execute the following line:

insert into demo (id,date,name) values (nextval('hibernate_sequence'),now(),'John');

;-) (It works on PostgreSQL, may be possible that other back-ends require a slightly different syntax).