Build R

1. Install R

Choose a mirror site geographically close to you, and download either the appropriate binary for your platform (or the source code and then compile yourself). Set your path appropriately. For example, my R executable is under /Applications/R.app/Contents/MacOS on my Mac OS X, so I add /Applications/R.app/Contents/MacOS as one of the search paths in my C shell startup configuration file .cshrc

If the installation is successful, the following command on the prompt


will bring you into the R world! Quit R by typing q()

> q()                           

or hitting letter "d" while holding down CTRL key.

2. Download some prerequisite packages from R

Run the following inside R:


3. All AFNI programs in R are distributed with the AFNI package, and can be found in the abin directory.

4. Error regarding missing R_io.so 

a) Make sure you have the most recent version of AFNI. 

b) Make sure you have the most recent version of R. 

c) Run the following command line and see if there are any missing libraries:

ldd `@GetAfniBin`/R_io.so

d) Copy and paste the following at the R prompt: 

first.in.path <- function(file) { 
ff <- paste(strsplit(Sys.getenv('PATH'),':')[[1]],'/', file, sep='') 
#cat('Using ', ff[1],'\n'); 
return(gsub('//','/',ff[1], fixed=TRUE)) 


(ll <- find.in.path('R_io.so')) 

Report to us: (1) the missing libraries revealed from c) above; (2) the output of the last two lines from d) above; (3) your computer OS version (and 32- or 64-bit?); (4) the second line from the output of the following command line at the terminal: afni -ver; (5) the first three lines from the output of the command line at the terminal: R --version

5. Fix for "segfault error" on Mac when running any R-related program 

For those who encounter the following error on Mac OS when running R-related programs (3dMVM, 3dLME, 3dMEMA, ...) 

> *** caught segfault *** 
> address ..., cause 'memory not mapped' 
> ... 

here is the solution: 

1) Remove everything under /Library/Frameworks/R.framework/ 
2) Delete R.app under /Applications/ 
3) Reinstall R (for Mac OS 10.9.x right now, consider installing the development version at http://r.research.att.com/mavericks/R-devel/R-devel-mavericks.pkg)

Related topics


1. Linear mixed-effects modeling: 3dLME

2. Independent component analysis: 3dICA