Mac M1 install issues with R

Hello,

I am trying to install AFNI and I complete all of the install steps up until I have to run the user-install script "tcsh OS_notes.macos_12_ARM_b_user.tcsh".

the error message I get is:

rehash

setenv R_LIBS /Users/bontlewatson/sw/R-4.3.1

echo export R_LIBS=/Users/bontlewatson/sw/R-4.3.1

echo export R_LIBS=/Users/bontlewatson/sw/R-4.3.1

echo setenv R_LIBS /Users/bontlewatson/sw/R-4.3.1

mkdir -p /Users/bontlewatson/sw/R-4.3.1

rPkgsInstall -pkgs ALL

tee out.rPkgsInstall.txt

** ERROR: Failed to load R_io.so

and if I check if AFNI is installed correctly it seems okay - this is the output:

afni_system_check.py    - perform various system checks

This program is intended to be helpful for figuring out AFNI installation
issues.

examples

   1.  afni_system_check.py -check_all
   2a. afni_system_check.py -find_prog python
   2b. afni_system_check.py -find_prog python -exact yes
   3a. afni_system_check.py -disp_R_ver_for_lib $R_LIBS
   3b. afni_system_check.py -disp_abin

-----------------------------------------------------------------------------
terminal options:

   -help                : show this help
   -help_dot_files      : show help on shell setup files
   -help_rc_files       : SAME
   -hist                : show program history
   -show_valid_opts     : show valid options for program
   -todo                : show current todo list
   -ver                 : show current version

   NOTE: either a terminal or an action option is required

action options:

   -check_all           : perform all system checks
                          - see section, "details displayed via -check_all"
   -disp_num_cpu        : display number of CPUs available
   -disp_R_ver_for_lib  : display the R version used when building an R library
                          - this refers to those installed by rPkgsInstall,
                            most likely under $R_LIBS
   -disp_abin           : display directory containing 'afni' (or this)
   -disp_ver_afni       : display AFNI package version (else "None")
   -disp_ver_matplotlib : display matplotlib version (else "None")
   -disp_ver_pylibs LIB LIB ... :
                          display versions of given python libraries (else NONE)
                          - use 'ALL' to include the default test list
   -dot_file_list       : list all found dot files (startup files)
   -dot_file_show       : display contents of all found dot files
   -dot_file_pack NAME  : create a NAME.tgz package containing dot files
   -find_prog PROG      : search PATH for PROG
                          - default is *PROG*, case-insensitive
                          - see also -casematch, -exact

other options:

   -casematch yes/no    : match case in -find_prog
   -data_root DDIR      : search for class data under DDIR
   -exact yes/no        : search for PROG without wildcards in -find_prog
   -use_asc_path        : prepend ASC dir to PATH
                          (to test programs in same directory as ASC.py)
   -verb LEVEL          : set the verbosity level

-----------------------------------------------------------------------------
details displayed via -check_all (just run to see):

   general information:
      - CPU, operating system and version, # CPUs, login shell

   AFNI and related tests:
      - which afni, python, R and tcsh, along with versions
      - check for multiple afni packages in PATH
      - check that various AFNI programs run
      - check for AFNI $HOME dot files (.afnirc, .sumarc, etc.)
      - warn on tcsh version 6.22.03

   python libs:
      - check that various python libraries are found and loaded

   environment vars:
      - show PATH, PYTHONPATH, R_LIBS, LD_LIBRARY_PATH, DYLD_LIBRARY_PATH, etc.

   evaluation of dot files:
      - show the output of "init_user_dotfiles -test", restricted
        to shells of interest (user shells plus tcsh)

   data checks:
      - check for AFNI bootcamp data directories and atlases

   OS specific:
      - on linux, check for programs and version of dnf, yum
      - on macs, check for homebrew, fink, flat_namespace, etc.

   final overview:
      - report anything that seems to need fixing for a bootcamp
        (details shown earlier)

I had tried downloading an older version of R (the 3.6.1) and it still has the same error message.

I would appreciate any help - thanks!

That library will be missing if R is not installed before the user build step. Typically, R would be installed as part of this step -

zsh OS_notes.macos_12_ARM_a_admin_pt2.zsh

If you have installed it separately or retry with the previous step, then you can repeat the last step:

tcsh OS_notes.macos_12_ARM_b_user.tcsh

thank you for your response!

I tried your steps and the exact same error message comes up:

- consider monitoring the build in a separate window with:
       cd /Users/bontlewatson
       tail -f /Users/bontlewatson/afni_build/build_src/log_make.txt
       # use ctrl-c to terminate 'tail' command (not the build)
++ building (please be patient)...
** error: failed run_cmd: make AFNI_WHOMADEIT=build itall >& log_make.txt
-- status: building FAILURE
   see 'make' log file /Users/bontlewatson/afni_build/build_src/log_make.txt
** error: tail from log_make.txt:
   --------------------------------------------------
   make[1]: Entering directory '/Users/bontlewatson/afni_build/build_src'
   clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I. -I/opt/homebrew/include -I/opt/X11/include -I/usr/include -Icoxplot -Inifti/nifti2 -Inifti/niftilib -Inifti/nifticdf -Inifti/znzlib -I3DEdge/src -Irickr -Ileej3 -DHAVE_ZLIB -DHAVE_GIFTI -If2c -m64 -Wall -Wno-deprecated-declarations -Wcomment -Wformat -DUSE_TRACING -DHAVE_XDBE -DDONT_USE_MCW_MALLOC  -I/opt/R/arm64/include    -fPIC  -falign-functions=64 -Wall -g -O2  -c R_io.c -o R_io.o
   In file included from R_io.c:1:
   /Library/Frameworks/R.framework/Resources/include/R.h:43:11: fatal error: 'stdlib.h' file not found
   # include <stdlib.h> /* Not used by R itself, but widely assumed in packages */
   ^~~~~~~~~~
   1 error generated.
   make[1]: *** [/Library/Frameworks/R.framework/Resources/etc/Makeconf:191: R_io.o] Error 1
   make[1]: Leaving directory '/Users/bontlewatson/afni_build/build_src'
   make: *** [Makefile.INCLUDE:4236: R_io.so] Error 1
   --------------------------------------------------


-- shell/system command history is in:
      /Users/bontlewatson/afni_build/hist_commands.txt

++ screen text history is in:
      /Users/bontlewatson/afni_build/hist_messages.txt

rehash
setenv R_LIBS /Users/bontlewatson/sw/R-4.3.1
echo export R_LIBS=/Users/bontlewatson/sw/R-4.3.1
echo export R_LIBS=/Users/bontlewatson/sw/R-4.3.1
echo setenv R_LIBS /Users/bontlewatson/sw/R-4.3.1
mkdir -p /Users/bontlewatson/sw/R-4.3.1
rPkgsInstall -pkgs ALL
tee out.rPkgsInstall.txt

** ERROR: Failed to load R_io.so

Hi-

Could you please run this for the system check and copy+paste the output:

afni_system_check.py -check_all

? (NB: it needs that option to report on your system; otherwise it just shows the help file.)

--pt

-------------------------------- general ---------------------------------
architecture: 64bit
cpu type: arm
system: Darwin
release: 23.5.0
version: Darwin Kernel Version 23.5.0: Wed May 1 20:16:51 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T8103
distribution: 14.5
number of CPUs: 8
apparent login shell: zsh
shell RC file: .zshrc (exists)

--------------------- AFNI and related program tests ---------------------
which afni :
:
AFNI_version.txt : AFNI_24.1.22, anyos_text, Jun 21 2024, local
which python : /Users/bontlewatson/fsl/bin/python
python version : 3.11.8
which R : /usr/local/bin/R
R version : R version 4.3.1 (aarch64-apple-darwin20)

instances of various programs found in PATH:
afni : 0
R : 1 (/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/bin/R)
python : 2
/Users/bontlewatson/fsl/bin/python3.11
/opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/bin/python3.12
python2 : 0
python3 : 3
/Users/bontlewatson/fsl/bin/python3.11
/opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/bin/python3.12
/usr/bin/python3

** have python3 but not python2

testing ability to start various programs...
afni : FAILURE
/bin/sh: afni: command not found
suma : FAILURE
/bin/sh: suma: command not found
3dSkullStrip : FAILURE
/bin/sh: 3dSkullStrip: command not found
3dAllineate : FAILURE
/bin/sh: 3dAllineate: command not found
3dRSFC : FAILURE
/bin/sh: 3dRSFC: command not found
SurfMesh : FAILURE
/bin/sh: SurfMesh: command not found
3dClustSim : FAILURE
/bin/sh: 3dClustSim: command not found
uber_subject.py : success
3dMVM : FAILURE
Error in library(data.table) : there is no package called ‘data.table’
Calls: source ... suppressPackageStartupMessages -> withCallingHandlers -> library
Execution halted

------------------------ dependent program tests -------------------------
checking for dependent programs...

which tcsh : /bin/tcsh
tcsh version : 6.21.00
which Xvfb : /opt/X11/bin/Xvfb

checking for R packages...
rPkgsInstall -pkgs ALL -check : FAILURE

R RHOME : /Library/Frameworks/R.framework/Resources

------------------------------ python libs -------------------------------

++ module loaded: matplotlib.pyplot
module file : /Users/bontlewatson/fsl/lib/python3.11/site-packages/matplotlib/pyplot.py
matplotlib version : 3.8.4

++ module loaded: flask
module file : /Users/bontlewatson/fsl/lib/python3.11/site-packages/flask/init.py
flask version : 3.0.3

** failed to load module flask_cors
-- flask_cors is not required, but is desirable

-------------------------------- env vars --------------------------------
PATH = /Users/bontlewatson/install/bin:/Applications/freesurfer//bin:/Applications/freesurfer//fsfast/bin:/Users/bontlewatson/fsl/bin:/Users/bontlewatson/fsl/share/fsl/bin:/Applications/freesurfer//mni/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/bontlewatson/fsl/share/fsl/bin:/Users/bontlewatson/fsl/share/fsl/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/opt/X11/bin:/Users/bontlewatson/LayNii:/opt/homebrew/opt/python/libexec/bin:/Users/bontlewatson/abin:/opt/homebrew/opt/python/libexec/bin

PYTHONPATH =
R_LIBS = /Users/bontlewatson/sw/R-4.3.1
LD_LIBRARY_PATH =
DYLD_LIBRARY_PATH (sub-shell) = /Applications/freesurfer//lib/gcc/lib
DYLD_FALLBACK_LIBRARY_PATH (sub-shell) =
CONDA_SHLVL =
CONDA_DEFAULT_ENV =

----------------------------- eval dot files -----------------------------

----------- AFNI $HOME files -----------

.afnirc                   : found
.sumarc                   : missing
.afni/help/all_progs.COMP : missing

--------- shell startup files ----------

-- good: .tcshrc seems to contain 'source .cshrc'
-- considered operations: path, apsearch

-- note: followers should not need edits, so edit flags should be 0
(have 1 follower(s), which can be ignored)

no modifications needed across 3 dot files

------------------------------ data checks -------------------------------
data dir : missing AFNI_data6
data dir : missing AFNI_demos
data dir : missing suma_demo
data dir : missing afni_handouts
atlas : did not find TT_N27+tlrc

------------------------------ OS specific -------------------------------
XQuartz version : 2.8.5

which brew : /opt/homebrew/bin/brew
brew version : Homebrew 4.3.9-16-gb098b4c

========================= summary, please fix: =========================

  • just be aware: login shell 'zsh', but our code examples use 'tcsh'
  • missing program: afni
  • failure under initial "AFNI and related program tests"
  • AFNI programs show FAILURE
  • missing R packages (see rPkgsInstall)
  • please run: "suma -update_env" for .sumarc
  • please run: apsearch -update_all_afni_help
  • insufficient data for AFNI bootcamp
    (see "Prepare for Bootcamp" on install pages)
  • possibly missing atlases
  • consider installing gcc under homebrew
  • consider installing glib under homebrew

I also tried running the lines they suggested and this was the output:
bontlewatson@Bontles-MacBook-Air ~ % "suma -update_env" for .sumarc

zsh: command not found: suma -update_env

bontlewatson@Bontles-MacBook-Air ~ % apsearch -update_all_afni_help

zsh: command not found: apsearch

I was able to resolve this by modifying the Makefile.macos_* to include the appropriate include, library, and framework paths.

vim afni_build/git/afni/src/Makefile.macos_12_x86_64 # or use any preferred editor of your choice

and add -I/Library/Developer/CommandLineTools/SDKs/MacOSX15.2.sdk/usr/include to IFLAGS, followed by
-L/Library/Developer/CommandLineTools/SDKs/MacOSX15.2.sdk/usr/lib \ -F/Library/Developer/CommandLineTools/SDKs/MacOSX15.2.sdk/System/Library/Frameworks to LFLAGS. If you find this post years later, you might need to adjust the Mac OS version as needed (the latest was 15.2 for me, but you might have newer versions in the /Library/Developer/CommandLineTools/SDKs/ directory).

I then compiled AFNI with brew's gcc-14 compiler using:
build_afni.py -build_root ./afni_build -package macos_12_x86_64 -cc_path /usr/local/bin/gcc-14
et voila! -- status: building SUCCESS and -- status: build testing SUCCESS!