R command not found

Hello!

I’m running into some issues with using R with AFNI on a macOS Catalina 10.15.6. The AFNI version I’m using (output of afni -version) is: Precompiled binary macos_10.12_local: Mar 30 2020 (Version AFNI_20.0.24 ‘Galba’).

I’m trying to run 3dMVM and at first I got some error messages that said “Failed to load R_io.so with this error message,” but based on this message chain I downloaded R 3.6, which seemed to fix that initial issue. However, now when I try to run 3dMVM I get a new error message “R: Command not found.”

My 3dMVM code previously worked on another machine (linux), so I think it’s more an issue with my local OS (and I previously encountered some issues downloading AFNI for Catalina that I never really addressed…). Any advice for how to fix this?

Thanks!
Janelle

Hi, Janelle-

I think that indeed that older version of AFNI binaries had a mismatch with the R_io.so and R version 3.6. Since that time we have resolved that issue in that particular file.

So, if you update your AFNI binaries:


@update.afni.binaries -d

… that should sort things out.

Please let us know if that does/doesn’t work!

–pt

Thanks for the help!

I was able to run the command successfully, but even after restarting the computer, it’s still throwing the same error “R: Command not found.” When I do “which R” it points to an anaconda R rather than R proper; I have R 3.6 downloaded, but is it possible that AFNI is trying to use the wrong R?

-Janelle

Hmm, I didn’t realize that you have multiple Rs on your system… What is the output of:


afni_system_check.py -check_all

?

–pt

Oh yes, I should have specified - I have a few versions of R downloaded!

Output of that command is:

-------------------------------- general ---------------------------------
architecture: 64bit
system: Darwin
release: 19.6.0
version: Darwin Kernel Version 19.6.0: Thu Jun 18 20:49:00 PDT 2020; root:xnu-6153.141.1~1/RELEASE_X86_64
distribution: 10.15.6
number of CPUs: 16
apparent login shell: bash
shell RC file: .bashrc (exists)

--------------------- AFNI and related program tests ---------------------
which afni : /Users/liuj10/abin/afni
afni version : Precompiled binary macos_10.12_local: Sep 17 2020
: AFNI_20.2.18 ‘Aulus Vitellius’
AFNI_version.txt : AFNI_20.2.18, macos_10.12_local, Sep 17 2020
which python : /Users/liuj10/opt/anaconda2/bin/python
python version : 2.7.16
which R : /Users/liuj10/opt/anaconda2/bin/R
R version : R version 3.6.1 (2019-07-05) – “Action of the Toes”
which tcsh : /bin/tcsh

instances of various programs found in PATH:
afni : 1 (/Users/liuj10/abin/afni)
R : 2
/Users/liuj10/opt/anaconda2/bin/R
/Library/Frameworks/R.framework/Versions/3.6/Resources/bin/R
python : 2
/Users/liuj10/opt/anaconda2/bin/python2.7
/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
python2 : 2
/Users/liuj10/opt/anaconda2/bin/python2.7
/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
python3 : 1 (/usr/bin/python3)

testing ability to start various programs…
afni : success
suma : success
3dSkullStrip : success
uber_subject.py : success
3dAllineate : success
3dRSFC : success
SurfMesh : success
3dClustSim : success
3dMVM : FAILURE
Error in dyn.load(ll) :
unable to load shared object ‘/Users/liuj10/abin/R_io.so’:
dlopen(/Users/liuj10/abin/R_io.so, 6): Library not loaded: /sw/Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libR.dylib
Referenced from: /Users/liuj10/abin/R_io.so
Reason: image not found
Calls: source … withVisible → eval → eval → set_R_io → dyn.load
Execution halted

checking for R packages…
rPkgsInstall -pkgs ALL -check : success

R RHOME : /Users/liuj10/opt/anaconda2/lib/R

checking for $HOME files…
.afnirc : found
.sumarc : found
.afni/help/all_progs.COMP : found

------------------------------ python libs -------------------------------
** failed to load module PyQt4
– PyQt4 is no longer needed for an AFNI bootcamp

++ module loaded: matplotlib.pyplot
module file : /Users/liuj10/opt/anaconda2/lib/python2.7/site-packages/matplotlib/pyplot.pyc

-------------------------------- env vars --------------------------------
PATH = /usr/local/ANTs/bin/:/Users/liuj10/opt/anaconda2/bin:/Users/liuj10/opt/anaconda2/condabin:/usr/local/fsl/bin:/usr/local/DTIPrepTools-0.1.1-Linux/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/MATLAB_R2019a.app/bin:/opt/X11/bin:/Users/liuj10/abin

PYTHONPATH =
R_LIBS =
LD_LIBRARY_PATH =
DYLD_LIBRARY_PATH (sub-shell) = :/opt/X11/lib/flat_namespace
DYLD_FALLBACK_LIBRARY_PATH (sub-shell) =

------------------------------ data checks -------------------------------
data dir : missing AFNI_data6
data dir : missing AFNI_demos
data dir : missing suma_demo
data dir : missing afni_handouts
atlas : found TT_N27+tlrc under /Users/liuj10/abin

------------------------------ OS specific -------------------------------
XQuartz version : 2.7.11

which brew : /usr/local/bin/brew
brew version : Homebrew 2.5.1

– for PyQt4 under brew, consider running:
brew install cartr/qt4/pyqt
++ found valid link /usr/local/lib/libglib-2.0.dylib
to …/Cellar/glib/2.64.3/lib/libglib-2.0.dylib
++ found 1 dylib files under ‘/opt/X11/lib/flat_namespace’
– found ‘libXt’ dylib files:
/opt/X11/lib/flat_namespace/libXt.6.dylib
– recent OS X, cheating to check DYLD_LIBRARY_PATH in cur shell ‘bash’…
++ found evar DYLD_LIBRARY_PATH = :/opt/X11/lib/flat_namespace
– recent OS X, cheating to check DYLD_LIBRARY_PATH in shell ‘tcsh’…
++ found evar DYLD_LIBRARY_PATH = /opt/X11/lib/flat_namespace

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

  • just be aware: login shell ‘bash’, but our code examples use ‘tcsh’
  • shell bash: consider sourcing (non-login) .bashrc from (login) .bash_profile
  • AFNI programs show FAILURE
  • insufficient data for AFNI bootcamp
  • consider installing gcc under homebrew

Thanks!
-Janelle

To follow up on my prior post - is there a way for me to change it so that AFNI points to the second instance of:
R (/Library/Frameworks/R.framework/Versions/3.6/Resources/bin/R)
python (/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7)
python2 (/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7)

rather than using the anaconda versions of those programs?

Thanks!
Janelle

Hi, Janelle-

Sorry for the delayed reply, I lost this thread on the MB.

Umm, I’m not sure what exactly is wrong. It seems like the R being used is 3.6.3… It is also odd that something with /sw/Library is listed, because that looks like a fink-installed tree.

There are some other things in the “fix” notes at the bottom to do. Do you have Xcode installed (needed for gcc compiler)? Could you try running this and see if it does any work:


xcode-select --install

Also, for the bash shell stuff, could you copy+paste the following into a terminal:


echo "" >> ~/.bash_profile
echo "source ~/.bashrc" >> ~/.bash_profile
echo "" >> ~/.bash_profile

And perhaps could you try logging out and logging back in again, and seeing what the output of:
afni_system_check.py -check_all
shows?

–pt

Hi, no worries - totally understand how things pile up quickly on the MB!

I believe I do have Xcode already installed (“which g++” returns “/usr/bin/g++”).

I did the copy/pasting for the bash stuff, and also restarted my computer. After this, the output of “afni_system_check.py -check_all” is:


-------------------------------- general ---------------------------------
architecture:         64bit 
system:               Darwin
release:              19.6.0
version:              Darwin Kernel Version 19.6.0: Thu Jun 18 20:49:00 PDT 2020; root:xnu-6153.141.1~1/RELEASE_X86_64
distribution:         10.15.6
number of CPUs:       16
apparent login shell: bash
shell RC file:        .bashrc (exists)

--------------------- AFNI and related program tests ---------------------
which afni           : /Users/liuj10/abin/afni
afni version         : Precompiled binary macos_10.12_local: Sep 27 2020 
                     : AFNI_20.2.19 'Aulus Vitellius'
AFNI_version.txt     : AFNI_20.2.19, macos_10.12_local, Sep 27 2020
which python         : /Users/liuj10/opt/anaconda2/bin/python
python version       : 2.7.16
which R              : /Users/liuj10/opt/anaconda2/bin/R
R version            : R version 3.6.1 (2019-07-05) -- "Action of the Toes"
which tcsh           : /bin/tcsh

instances of various programs found in PATH:
    afni    : 1   (/Users/liuj10/abin/afni)
    R       : 2 
      /Users/liuj10/opt/anaconda2/bin/R
      /Library/Frameworks/R.framework/Versions/3.6/Resources/bin/R
    python  : 2 
      /Users/liuj10/opt/anaconda2/bin/python2.7
      /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
    python2 : 2 
      /Users/liuj10/opt/anaconda2/bin/python2.7
      /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
    python3 : 1   (/usr/bin/python3)


testing ability to start various programs...
    afni                 : success
    suma                 : success
    3dSkullStrip         : success
    uber_subject.py      : success
    3dAllineate          : success
    3dRSFC               : success
    SurfMesh             : success
    3dClustSim           : success
    3dMVM                : FAILURE
        Error in dyn.load(ll) : 
          unable to load shared object '/Users/liuj10/abin/R_io.so':
          dlopen(/Users/liuj10/abin/R_io.so, 6): Library not loaded: /sw/Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libR.dylib
          Referenced from: /Users/liuj10/abin/R_io.so
          Reason: image not found
        Calls: source ... withVisible -> eval -> eval -> set_R_io -> dyn.load
        Execution halted

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

R RHOME : /Users/liuj10/opt/anaconda2/lib/R

checking for $HOME files...
    .afnirc                   : found
    .sumarc                   : found
    .afni/help/all_progs.COMP : found

------------------------------ python libs -------------------------------
** failed to load module PyQt4
-- PyQt4 is no longer needed for an AFNI bootcamp

++ module loaded: matplotlib.pyplot
   module file : /Users/liuj10/opt/anaconda2/lib/python2.7/site-packages/matplotlib/pyplot.pyc

-------------------------------- env vars --------------------------------
PATH = /usr/local/ANTs/bin/:/Users/liuj10/opt/anaconda2/bin:/Users/liuj10/opt/anaconda2/condabin:/usr/local/fsl/bin:/usr/local/DTIPrepTools-0.1.1-Linux/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/MATLAB_R2019a.app/bin:/opt/X11/bin:/Users/liuj10/abin:/Users/liuj10/abin

PYTHONPATH = 
R_LIBS = 
LD_LIBRARY_PATH = 
DYLD_LIBRARY_PATH (sub-shell) = :/opt/X11/lib/flat_namespace
DYLD_FALLBACK_LIBRARY_PATH (sub-shell) = 

------------------------------ data checks -------------------------------
data dir : missing AFNI_data6
data dir : missing AFNI_demos
data dir : missing suma_demo
data dir : missing afni_handouts
atlas    : found TT_N27+tlrc  under /Users/liuj10/abin

------------------------------ OS specific -------------------------------
XQuartz version      : 2.7.11

which brew           : /usr/local/bin/brew
brew version         : Homebrew 2.5.1

-- for PyQt4 under brew, consider running:
   brew install cartr/qt4/pyqt
++ found valid link /usr/local/lib/libglib-2.0.dylib
   to ../Cellar/glib/2.64.3/lib/libglib-2.0.dylib
++ found 1 dylib files under '/opt/X11/lib/flat_namespace'
   -- found 'libXt' dylib files:
      /opt/X11/lib/flat_namespace/libXt.6.dylib
-- recent OS X, cheating to check DYLD_LIBRARY_PATH in cur shell 'bash'...
++ found evar DYLD_LIBRARY_PATH = :/opt/X11/lib/flat_namespace
-- recent OS X, cheating to check DYLD_LIBRARY_PATH in shell 'tcsh'...
++ found evar DYLD_LIBRARY_PATH = /opt/X11/lib/flat_namespace

=========================  summary, please fix:  =========================
*  just be aware: login shell 'bash', but our code examples use 'tcsh'
*  AFNI programs show FAILURE
*  insufficient data for AFNI bootcamp
*  consider installing gcc under homebrew

And when I try to run my 3dMVM script it throws this error:


updating R_LD_LIBRARY_PATH ...

oo Warning: 
   Failed to load R_io.so with this error message:

Error in dyn.load(ll) : 
  unable to load shared object '/Users/liuj10/abin/R_io.so':
  dlopen(/Users/liuj10/abin/R_io.so, 6): Library not loaded: /sw/Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libR.dylib
  Referenced from: /Users/liuj10/abin/R_io.so
  Reason: image not found
Calls: source ... withVisible -> eval -> eval -> set_R_io -> dyn.load
Execution halted

However, a colleague recommended trying “conda deactivate” so if I enter that and then check output of “afni_system_check.py -check_all” I get:


-------------------------------- general ---------------------------------
architecture:         64bit 
system:               Darwin
release:              19.6.0
version:              Darwin Kernel Version 19.6.0: Thu Jun 18 20:49:00 PDT 2020; root:xnu-6153.141.1~1/RELEASE_X86_64
distribution:         10.15.6
number of CPUs:       16
apparent login shell: bash
shell RC file:        .bashrc (exists)

--------------------- AFNI and related program tests ---------------------
which afni           : /Users/liuj10/abin/afni
afni version         : Precompiled binary macos_10.12_local: Sep 27 2020 
                     : AFNI_20.2.19 'Aulus Vitellius'
AFNI_version.txt     : AFNI_20.2.19, macos_10.12_local, Sep 27 2020
which python         : /usr/bin/python
python version       : 2.7.16
which R              : /usr/local/bin/R
R version            : R version 3.6.3 (2020-02-29) -- "Holding the Windsock"
which tcsh           : /bin/tcsh

instances of various programs found in PATH:
    afni    : 1   (/Users/liuj10/abin/afni)
    R       : 1   (/Library/Frameworks/R.framework/Versions/3.6/Resources/bin/R)
    python  : 1   (/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7)
    python2 : 1   (/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7)
    python3 : 1   (/usr/bin/python3)


testing ability to start various programs...
    afni                 : success
    suma                 : success
    3dSkullStrip         : success
    uber_subject.py      : success
    3dAllineate          : success
    3dRSFC               : success
    SurfMesh             : success
    3dClustSim           : success
    3dMVM                : success

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

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

checking for $HOME files...
    .afnirc                   : found
    .sumarc                   : found
    .afni/help/all_progs.COMP : found

------------------------------ python libs -------------------------------
** failed to load module PyQt4
-- PyQt4 is no longer needed for an AFNI bootcamp

++ module loaded: matplotlib.pyplot
   module file : /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/pyplot.pyc

-------------------------------- env vars --------------------------------
PATH = /usr/local/ANTs/bin:/Users/liuj10/opt/anaconda2/condabin:/usr/local/fsl/bin:/usr/local/DTIPrepTools-0.1.1-Linux/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/MATLAB_R2019a.app/bin:/opt/X11/bin:/Users/liuj10/abin:/Users/liuj10/abin

PYTHONPATH = 
R_LIBS = 
LD_LIBRARY_PATH = 
DYLD_LIBRARY_PATH (sub-shell) = :/opt/X11/lib/flat_namespace
DYLD_FALLBACK_LIBRARY_PATH (sub-shell) = 

------------------------------ data checks -------------------------------
data dir : missing AFNI_data6
data dir : missing AFNI_demos
data dir : missing suma_demo
data dir : missing afni_handouts
atlas    : found TT_N27+tlrc  under /Users/liuj10/abin

------------------------------ OS specific -------------------------------
XQuartz version      : 2.7.11

which brew           : /usr/local/bin/brew
brew version         : Homebrew 2.5.1

-- for PyQt4 under brew, consider running:
   brew install cartr/qt4/pyqt
-- consider installing gcc under homebrew
++ found valid link /usr/local/lib/libglib-2.0.dylib
   to ../Cellar/glib/2.64.3/lib/libglib-2.0.dylib
++ found 1 dylib files under '/opt/X11/lib/flat_namespace'
   -- found 'libXt' dylib files:
      /opt/X11/lib/flat_namespace/libXt.6.dylib
-- recent OS X, cheating to check DYLD_LIBRARY_PATH in cur shell 'bash'...
++ found evar DYLD_LIBRARY_PATH = :/opt/X11/lib/flat_namespace
-- recent OS X, cheating to check DYLD_LIBRARY_PATH in shell 'tcsh'...
++ found evar DYLD_LIBRARY_PATH = /opt/X11/lib/flat_namespace

=========================  summary, please fix:  =========================
*  just be aware: login shell 'bash', but our code examples use 'tcsh'
*  insufficient data for AFNI bootcamp

Then when I try running the 3dMVM script, it seems to start working (calling on the correct R), but still throws an error:


updating R_LD_LIBRARY_PATH ...
Read 299 items
Loading required package: lme4
Loading required package: Matrix
Error: package or namespace load failed for ‘afex’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):
 there is no package called ‘data.table’
Execution halted

And I’ve tried doing install.packages(“afex”) but even if that works, it still throws the same error so something still seems to be wrong with how AFNI and R are communicating. Also, any time I open a new terminal window I have to re-enter conda deactivate otherwise AFNI still defaults to pointing to anaconda’s R. Is there a more permanent solution I could implement?

Thanks!
Janelle

Re. the need for “conda deactivate”: you probably have conda set to activate an environment in one of the files that is executed every time a terminal starts.

What is the output of:


conda env list

? It will display a list of conda environments on your computer, and the one with an asterisk by it will be the one activated at present.

Can you run this:


grep -h "conda activate" ~/.*rc

and post the output? I expect a specific file like ~/.bash_profile has a “conda activate …” command in it. In that case, you can open whatever file has it and comment it out, so new terminals will not have that environment being activated by default.

Also, what is the output of:


cat ~/.condarc

? That will show some of your conda default settings.

I find it weird that the “gcc” message went away when you deactivated your conda environment… But I only use conda for managing my Python usage.

In a terminal where you have run “conda deactivate”, can you run this:


sudo rPkgsInstall -pkgs ALL

(requires admin password to run). That will try to install all the necessary R libraries (afex, snow, etc.).

–pt

Output of conda env list is:


# conda environments:
#
base                  *  /Users/liuj10/opt/anaconda2
                         /usr/local/fsl/fslpython
                         /usr/local/fsl/fslpython/envs/fslpython

When I run grep -h “conda activate” ~/.*rc nothing is returned! Should I try a different file?

Output of cat ~/.condarc is:


ssl_verify: true
channels:
  - defaults

In a terminal where I ran “conda deactivate” I ran sudo rPkgsInstall -pkgs ALL but I don’t think it worked. It just printed “updating R_LD_LIBRARY_PATH …” and when I tried loading afex in R it threw an error:


$ conda deactivate
$ sudo rPkgsInstall -pkgs ALL
Password:
updating R_LD_LIBRARY_PATH ...
$
$ which R
/usr/local/bin/R
$
$ R
R version 3.6.3 (2020-02-29) -- "Holding the Windsock"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin15.6.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

[Previously saved workspace restored]

> library("afex")
[b]Loading required package: lme4
Loading required package: Matrix
Error: package or namespace load failed for ‘afex’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):
 there is no package called ‘data.table’[/b]

For the record, in the past even when I’ve tried downloading afex specifically using install.packages(“afex”), it will seem like it worked but then when I try loading the package I get the same error…

Thanks!
Janelle

hmm…

I ran into the data.table problem on 10.15 as well.
I solved it by installing it manually from within the R GUI (not R studio or command line)
I think that the R libraries must be getting installed in separate places for all of the different versions of R.
Try installing all of the necessary libraries in all of your R instances.
You can find the library location with


.Library

I think for basic afni stuff you need:
‘afex’,‘phia’,‘snow’,‘nlme’,‘lme4’,‘paran’,‘brms’

and data.table is a requirement for some of them.
Try installing data.table first.

thanks, Justin

There seems to have some issue on Mac with the most recent version (v1.13.0) of data.table

https://rdrr.io/github/Rdatatable/data.table/f/NEWS.md

To get around the problem, install an older version:

  1. Download the older version from here to a temporal directory:

https://cran.r-project.org/bin/macosx/el-capitan/contrib/3.6/data.table_1.12.8.tgz

  1. At the terminal, execute the following command:

     R CMD install data.table_1.12.8.tgz