Compile R 3.2.2 on AIX 6.1

Here are my notes compiling 64-bit R 3.2.2 on AIX 6.1. As a pre-requisite, read the AIX notes from R-admin. Like the notes, I had GCC installed from here by our admin, along with many other pre-requisites. These were installed prior to compiling R. Note that you could grab newer versions of each package by going to (needed for R-dev).

## list of packages

## conversting unicode, ascii, etc; aix version is not compatible with

## dependency for unicode support; just need to extract to root / ##
need the gnu version of make

## libm ## jre

#### python

Add /opt/freeware/bin to PATH.

Now, download the R source tarball, extract, and cd.

Next, update src/main/dcf.c from the R-dev as a bug that causes readDCF to segfault when using install.packages; no need to do this for future versions of R. Then apply this patch from here to fix the following error:

gcc -maix64 -pthread -std=gnu99 -I../../../../include -DNDEBUG
-I../../../include -I../../../../src/include -DHAVE_CONFIG_H
-I../../../../src/main -I/usr/local/include  -mminimal-toc    -O2 -g
-mcpu=power6  -c gramRd.c -o gramRd.o

gcc -maix64 -pthread -std=gnu99 -shared -Wl,-brtl -Wl,-G -Wl,-bexpall
-Wl,-bnoentry -lc -L/usr/local/lib -o text.o init.o Rmd5.o
md5.o signals.o install.o getfmts.o http.o gramLatex.o gramRd.o -lm

make[6]: Entering directory '/sas/data04/vinh/R-3.2.2/src/library/tools/src'

mkdir -p -- ../../../../library/tools/libs

make[6]: Leaving directory '/sas/data04/vinh/R-3.2.2/src/library/tools/src'

make[5]: Leaving directory '/sas/data04/vinh/R-3.2.2/src/library/tools/src'

make[4]: Leaving directory '/sas/data04/vinh/R-3.2.2/src/library/tools'

make[4]: Entering directory '/sas/data04/vinh/R-3.2.2/src/library/tools'

installing 'sysdata.rda'

Error: Line starting 'Package: tools ...' is malformed!

Execution halted

../../../share/make/ recipe for target 'sysdata' failed

make[4]: *** [sysdata] Error 1

make[4]: Leaving directory '/sas/data04/vinh/R-3.2.2/src/library/tools'

Makefile:30: recipe for target 'all' failed

make[3]: *** [all] Error 2

make[3]: Leaving directory '/sas/data04/vinh/R-3.2.2/src/library/tools'

Makefile:36: recipe for target 'R' failed

make[2]: *** [R] Error 1

make[2]: Leaving directory '/sas/data04/vinh/R-3.2.2/src/library'

Makefile:28: recipe for target 'R' failed

make[1]: *** [R] Error 1

make[1]: Leaving directory '/sas/data04/vinh/R-3.2.2/src'

Makefile:59: recipe for target 'R' failed

make: *** [R] Error 1

Hopefully, this patch will make it to R-dev so that it is no longer needed for future versions of R.

export OBJECT_MODE=64
export CC="gcc -maix64 -pthread"
export CXX="g++ -maix64 -pthread"
export FC="gfortran -maix64 -pthread"
export F77="gfortran -maix64 -pthread"
export CFLAGS="-O2 -g -mcpu=power6"
export FFLAGS="-O2 -g -mcpu=power6"
export FCFLAGS="-O2 -g -mcpu=power6"
./configure --prefix=/path/to/opt ## custom location so I don't need root
make -j 16
make install
## add /path/to/opt/bin to PATH

The last step may complain about NEWS.pdf not found in a directory and a certain directory is not found in the destination. For the former, just do touch NEWS.pdf to where it’s supposed to be; for the latter, create the directory yourself.

Build 32 bit R on 64 bit Ubuntu by utilizing chroot

In the past, I’ve described how one could build multiarch (64 bit and 32 bit) versions of R on a 64 bit Ubuntu machine. The method based on this thread no longer works as of R 2.13 or 2.14 I believe. I received advice from someone on #R over on freenode (forgot who) a few months ago that suggested the chroot route (see this also). I recently tried it and wanted to document the procedures. Although the solution isn’t as nice as the previous multiarch route, it will suffice for now. With the chroot method, first compile the 64 bit version of R the usual way. For the 32 bit version of R, do:

<pre class="src src-sh"><span style="color: #ff4500;">#### </span><span style="color: #ff4500;">change my.username to your username, or modify path per your taste</span>

### create chroot jail sudo apt-get install dchroot debootstrap sudo mkdir ~/chroot-R32 sudo emacs -q -nw /etc/schroot/schroot.conf ## paste the following in the file: (no quotes) [natty] description=Ubuntu Natty location=/home/my.username/chroot-R32 priority=3 users=my.username groups=sbuild root-groups=root

## build a basic Ubuntu system in the chroot jail sudo debootstrap –variant=buildd –arch i386 natty /home/my.username/chroot-R32 ## pick a mirror from

## copy my source locations for apt sudo cp /etc/apt/sources.list /var/chroot/etc/apt/sources.list ## edit this new file if to reflect only the needed source

### do following steps whenever you need to access 32 bit R ## access to proc and dns sudo mount -o bind /proc /home/my.username/chroot-R32/proc sudo cp /etc/resolv.conf /home/my.username/chroot-R32/etc/resolv.conf ## go into jail; do this whenever you want sudo chroot /home/my.username/chroot-R32 dpkg-architecture ## make sure system is i386 ### now the root / location should reflect the jail

### following happens in jail ## tools needed to build R apt-get install gcc g++ gfortran libreadline-dev libx11-dev xorg-dev ## get svn to get latest r source code apt-get install git-core subversion

## compile 32 bit R cd home/ mkdir R32 cd R32 svn checkout r-devel cd r-devel/ apt-get install rsync ./tools/rsync-recommended ./configure make make install R

How big is my /home/my.username/chroot-R32 folder? It is at 791 MB after the above steps. Let me know if you have suggestions for having both 32 bit or 64 concurrently on Linux. I believe Windows and Mac ships and compiles both 32 bit and 64 bit versions of R. I’m surprised this isn’t the case for Linux.

Log output for screen

The one thing that annoys me when I use screen is that I can’t scroll up after a long output has printed. To log outputs, add the following near the top (required!) of your screenrc file ($HOME/.screenrc):

# auto-log
## search for "STRING ESCAPES" in the manpage
# logfile /tmp/screen_%Y-%m-%d-%c:%s_%n.log
## not using above because every window gets its own time too.  rather use session name; need 4.01.00devel (GNU450e8f3) 2-May-06 and above
logfile /tmp/screen-%S-%n.log
deflog on

For example, my rc file now looks like:

escape ^Oo
# auto-log
## search for "STRING ESCAPES" in the manpage
# logfile /tmp/screen_%Y-%m-%d-%c:%s_%n.log
## not using above because every window gets its own time too.  rather use session name; need 4.01.00devel (GNU450e8f3) 2-May-06 and above
logfile /tmp/screen-%S-%n.log
deflog on
##escape \56\56 ##ascii octal Use C-. for escape
## following for starting screen at 1 instead of 0
bind c screen 1
bind 0 select 10
screen 1
select 1

When I originally had the log options at the bottom, logging did not work for me.

Finally, you can use the %S string escape to refer to the session name in screen 4.01.00devel (GNU450e8f3) 2-May-06 and after. It might be wise to install the git version of screen.

Compiling bleeding edge version of screen

sudo apt-get remove screen
git clone git://
cd screen
tar xvf screen-*.tar.gz
cd screen*/
sudo make install

R from source

The following are notes for myself.

I like to use the bleeding edge version of R:

<pre class="example">svn checkout r-devel

cd r-devel ./tools/rsync-recommended

use the following to update sources: svn update


sudo apt-get build-dep r-base

sudo apt-get install gcc g++ gfortran libreadline-dev libx11-dev xorg-dev

sudo apt-get install texlive texinfo

./configure make sudo make install

Compile R on Mac OS X

I did this before on my Macbook, but never documented. Wanted to document my attempt on the Mac virtual machine.

  1. Install Xcode (gcc/g++) and gfortran per this site.
  2. Download the R source file (2.12 in this example), and extract it.
  3. ./configure did not work (Fortran issue). Per this, this, and this, I used: ./configure --with-blas‘-framework vecLib’ –with-lapack –with-aqua –enable-R-framework F77=”gfortran -arch x86_64″= (the F77 is needed!).
  4. make then sudo make install.
  5. Add /Library/Frameworks/R.framework/Versions/Current/Resources/bin to PATH in ~/.bashrc.

Compiling and Cross-compiling R packages for Windows (win32)

so recently i’m learning how to compile and cross-compile R packages from source for windows machines, which means i have to create windows binaries. the first option is to build on a windows system, and the 2nd is to cross-build on an intel-based linux or mac system. i will outline my experience.

Send it off to a Build Farm If you have the source package ready for install on a linux based system, you can send it off to a server and have it automatically build. This is probably the easiest way.

Building R packages and binaries on a Windows system. References: Requirements: Rtools and R source file

At the time of this writing, I am using R 2.9.2 and using Rtools29.

  1. First, install Rtools, which includes some basic unix utilities, compilers (MinGW), windows compatible perl, unicode, Tcl, and some bitmap stuff.

Install should be in C:\Rtools and C:\R. Go ahead and install everything, including the Tcl stuff. In the install, go ahead and click modify Path variable if you have admin access. if not, add the subfolders of Rtools that has bin into the user ‘Path’ variable (either for User or for System) from the Control Panel > System > something > Advanced tab > Environment variable button. The variable should be something like ‘H:\Rtools\bin;H:\Rtools\MinGW\bin\;H:\Rtools\perl\bin\’.

  1. go to start > run > cmd to open a command window. I placed my R source tar.gz file in H:\R. now, use tar zxvf to unarchive it.
  2. Move H:\R\Tcl into the R-version folder that we just unarchived. Move the folders ‘unicode’ and ‘bitmap’ from H:\R\src\gnuwin32 into R-version\src\gnuwin32. Main thing is we need the iconv.dll file.
  3. goto R-version\src\gnuwin32\. type make (or make all) to compile. this gave me a couple errors. if u don’t have Tcl in the right location, edit the R-version\src\gnu32\MkRules and change the path for Tcl. I also got an error where it couldn’t find the tmp folder, so i just created H:\tmp. R successfully compiled: see R-version\bin\.
  4. To make the windows binaries, I have a package folder prepared under mac/linux. I copied it to the windows machine, and i did something like in H:\R\ (where the package folder is in, say H:\R\MyPackage):

H:\R\R-version\bin\Rcmd.exe build –binary MyPackage The source should be compiled into a dll and i get a zip file where i could install on other windows machines.

Cross building package win32 (windows) binaries on an intel-based mac or linux Since i don’t have a windows system (i did it on my brother’s computer), it could be convenient to build this on my mac or linux system. The R core team used to support cross building, but stripped support as of v 2.9. I first outline my experience with R 2.8 on my Mac OS X. Look at the R-admin help file for cross-building in the 2.8. I also got help from this post on R-dev, and a few inquiries with the poster through email.

Requirements: R source code file MinGW for mac (I installed v.4.3.0 binaries and added the location to my PATH variable) R (mac/linux, your system) binaries (version must match that of source. i had R 2.8 currently installed at the time, so i cross-build this version). R win32 binaries (same version as well): u can install this from source using the cross-build stuff, but i kept getting errors. so, what i did, was used the windows installer and installed it using Wine on my Mac (~/.wine/drive_c/Program Files/R/R-version/ – the space in Program Files isn’t good, so i made a softlink via ln -s to ~/R)

In R-version (extracted somewher), go to /src/gnuwin32, edit MkRules, changed: BUILD=CROSS no CHM, this version picks this up by default with CROSS BINPREF=i386-mingw32-##i586-mingw32- R_EXE=/usr/bin/R###’I failed to read the instructions to set R_EXE in MkRules’

Now, suppose the name of my package is MyPackage and it is locted in Users/vinh/Downloads/Rwin (MyPackage folder is in here)

Instructions here are found in README.package of gnuwin32:

<pre class="src src-sh"><span style="color: #b0c4de;">cd</span> .../src/gnuwin32

make PKGDIR=/mysources RLIB=/R/win/library pkg-mypkg make PKGDIR=/mysources RLIB=/R/win/library lazyload-mypkg cd /R/win/library zip -r9X /dest/ mypkg

in my gnuwin32 folder, i did:

<pre class="src src-sh">make <span style="color: #eedd82;">PKGDIR</span>=/Users/vinh/Downloads/Rwin/ <span style="color: #eedd82;">RLIB</span>=/Users/vinh/R/library/ pkg-MyPackage

[it compiled my dll file] make PKGDIR=/Users/vinh/Downloads/Rwin/ RLIB=/Users/vinh/R/library/ kazyload-MyPackage cd ~/R/library zip -r9X MyPackage MyPackage

Now I have that can be installed on windows machines! Remember, ~/R is the softlinked version of where my windows version of R is.

Next, i’m going to attempt cross-compiling on R 2.9.2, where support is no longer supported, but as the post i referenced above described, this should still be do-able. I will update this.

record music from using shell-fm

as i mentioned before again and again, i’ve been working on to get shell-fm to record music from originally, i was trying to get shell-fm pipe to tee to save the songs and play using madplay (or mplayer) based on this method. this worked. i just need to write scripts to post process the songs to get id3 tags, etc. things work, and i have something like this in my shell-fm.rc file:

<pre class="src src-sh">extern = tee <span style="color: #ffa07a;">"/Users/vinh/shell-fm-saves/%a;%t;%l;%d.mpg3"</span> | madplay -Q -

##extern = tee “/Users/vinh/shell-fm-saves/%a;%t;%l;%d.mpg3″ | mplayer -cache 32 -

however, if u look at the end of the same page, it mentions hacking the source code because u can get shell-fm to automatically save free files, and get id3 tags on there. hopped on #shell-fm on the freenode and spoke to the author. (i tried this before but it didn’t work — reason was i didnt do a make clean first…i had residuals from the fail install since its on a mac).

now, to get shell-fm to compile with recording of every songs and get id3 tags working, just install libtag via MacPorts, modify play.c (search for freetrack and comment out that part):

<pre class="src src-C"><span style="color: #00ffff;">if</span>( <span style="color: #ff4500;">/*</span><span style="color: #ff4500;">freetrack &amp;&amp; strlen(freetrack) &gt; 0 &amp;&amp; </span><span style="color: #ff4500;">*/</span> haskey(&amp; rc, <span style="color: #ffa07a;">"download"</span>)) {

to compile, go in the source directory, do a make clean, then do the following on a mac:

<pre class="src src-sh">cc -o shell-fm -D__darwin__ -Os -Wall -W -I./include/ -DLIBAO -I/opt/local/include -I/opt/local/include -L/opt/local/lib -lmad -lm -Wl,-framework -Wl,AudioUnit -L/opt/local/lib -lao -lpthread -DTAGLIB <span style="color: #fa8072;">`pkg-config --libs taglib_c`</span> *.c

the author helped me figure out the DTAGLIB stuff, and how to get this command originally (had to remove the main.c in the middle and change the last .a file to *.c).


<pre class="src src-sh">cp ./shell-fm /usr/bin/

cd ../manual make sudo shell-fm.1 /usr/share/man/man1/

now, go to ~/.shell-fm/shell-fm.rc and put in download = /Users/vinh/shell-fm-saves/%a – %t.mp3 and all completed songs will be saved WITH id3tag

hacking/editing portfile (MacPorts) to compile madplay for use with shell-fm (

so recently i compiled shell-fm, a command-line player. in order to record music with shell-fm, i can output the stream of incoming data into tee, which saves the data to a file and at the same time pipes it out to stdout, and have that piped to madplay, a command-line player.

i had mplayer installed, but in order to get the piping of the streaming data to work, i had to to specify a cache ‘| mplayer -cache 32 -‘ (- means to take from stdin) in order for the music to play at the right rate. otherwise, the mplayer plays at a slower rate. the shell-fm wikidot recommends madplay.

madplay doesn’t compile easily on a mac os x, so i had to resort to MacPorts for the installation. it installs fine, but madplay plays noise. googled it, and stumbled on this post. he figured out it was an endian issue.

i tried applying his patch (‘patch < temp.patch’) to the original source code, however, it didn’t compile. figured out that i need the patch and the flags (CFLAGS, LDFLAGS) from Macports as well. i didn’t know how to apply both patches. hopped on #MacPorts on the freenode, and spoke with toby.

i created the 2nd patch and called it temp.patch in /opt/local/var/macports/sources/ edited /opt/local/var/macports/sources/ and added temp.patch to the list of patch files. now running ‘sudo port install madplay’ did the trick after uninstalling (sources and portfiles still around). voila, i have a working install on mac os x.

toby committed the new patch to macports, so now things should work. to get the new patches, i had to run ‘sudo port -d sync’ to sync the newest patch files. i uninstalled and reinstalled and the new official patch works.

i learned how macports operated and how to apply patch files in this adventure.