Monday, October 21, 2013

ESS (Emacs Speaks Statistics) now supports compiling knitr

First, new version of ESS needs to be installed.  I use Aquamacs, so I want to make sure that I update Aquamacs. You can do this by uncommenting appropriate lines in Makeconf file of the ESS distribution (search for Aquamacs in Makeconf file).

Two variables need to be set within emacs.

  • Change 'ess-swv-processor' to 'knitr'
  • Set the variable 'ess-swv-plug-into-AUCTeX' to use the existing interface for compiling LaTeX files: i.e., C-c C-c
Now you should be able to use 'C-c C-c Sweave' or 'C-c C-c LaTeXSweave' commands to compile your Rnw files.

Reading Microsoft Excel files into R in Ubuntu 12.04


People still send data around in Microsoft Excel format: xlsx. In order to import xlsx data into R, one can use the xlsx package. When I tried to install the package in R, I ran into libjvm.so not found error.

 libjvm.so: cannot open shared object file: No such file or directory

There is a stackoverflow thread on this.

After xlsx package was installed properly, the launched jvm did not have enough memory. The way to allow more memory to the jvm. This stackoverflow thread explains how to do this.

For example, to allocate 2GB memory for the jvm instance,

options(java.parameters = "-Xmx2000m")

DONE!

Thursday, October 17, 2013

Cross-platform, Acrobat compatible PDF highlighting in Ubuntu, Android and Mac OSX on Dropbox

I have a Mac as my notebook, Ubuntu 12.04 LTS as my workstation, Nexus 7 2 (FHD) as my tablet and an iPhone 4S (ios 6). I want to read PDF documents across devices and highlight for later. However, I ran into some difficulties in various aspects. Here are some issues I noticed.

  1. Google drive does not let Android edit files. This is a deal breaker because this means I cannot highlight as I am reading on my Nexus 7. FAIL
  2. Okular maybe a competent PDF reader, its highlight functionality is application specific. FAIL
  3. Skim on the Mac OS is the same way: application specific highlights. FAIL
  4. Dropbox PDF viewer does not display highlights. FAIL
  5. Opening a PDF on ios (using "Open in..." function) automatically makes a copy of the file, and, thus, will not save back to the original. FAIL
Here are some work-arounds I used to remedy some of the issues:

Nexus 7 (Android):
  1. Use Dropbox. Android app allows edits on mobile devices
  2. Use Acrobat to highlight
Ubuntu 12.04 LTS:
  1. Use PDF-XChange under Wine in Ubuntu. It works like a charm. There also is a portable version available for download on CNET.
  2. Wine program launcher can easily be created using Wine Launcher Creator (WLC). It is available here.
Mac OSX 10.8.5 (Mountain Lion):
  1. Use Preview to highlight

I don't know if I will be able to find any workaround for the iPhone. The fundamental design of the OS seems such that I cannot modify the original file. Oh well. I can still view highlights by opening a copy in Acrobat.

Wednesday, October 9, 2013

plyr parallel backend using doSNOW

You often want to parallelize some "embarrassingly parallel" computations. Doing this with R can be simple.

library(MASS)
library(plyr)
library(doSNOW)
cl <- makeCluster(8,type='SOCK')
registerDoSNOW(cl)
clusterEvalQ(cl, library(MASS))
set.seed(123)
x <- laply(1:15,function(x){mvrnorm(n=10000,mu=c(0,0),Sigma=matrix(c(1,0.9,0.9,1),2,2))},.parallel=TRUE)
alply(x,1,function(x){var(x)},.parallel=TRUE)
stopCluster(cl)