External Email - Use Caution
Hello Shrikanth,
When you source the freesurfer setup script in your shell, e.g., bash,
$ source $FREESURFER_HOME/SetUpFreeSurfer.sh
- it sets your PATH, SUBJECTS_DIR and a few other variables. It’s the addition to PATH of something like /usr/local/freesurfer/7.2.0/bin that enables freesurfer commands to be found, e.g.,
$ which mri_convert$ /usr/local/freesurfer/7.2.0/mri_convert
So you could cut and paste the absolute path of a freesurfer command to run in the R environment via the system() command, i.e., use whatever is echoed by the “which” command above in the shell where you run freesurfer.
You could also try to use a wrapper script to reproduce setting PATH and the freesurfer environment and run that script in the system() call. Something like (change path to FREESURFER_HOME as need be),
$ vi fs_from_r.sh
— start here —#!/usr/bin/env bash
export FREESURFER_HOME=/usr/local/freesurfer/7.2.0 source $FREESURFER_HOME/SetUpFreeSurfer..sh
# add any freesurfer commands after this
— end here —
$ chmod 755 fs_from_r.sh
Test run it in your bash sell first to see that it works,
$ ./fs_from_r.sh
Then see if you can run the fs_from_r.sh script via the R system() command. You probably need to give the absolute path to the script though.
- R.
On Oct 6, 2021, at 16:13, Yadav, Shrikanth Muralidhar <SMYADAV(a)mgh.harvard.edu> wrote:Hello Freesurfer Developers,I had a freesurfer-Rstudio issue today which I solved by just working on a Linux shell script. However, I wanted to know if it is possible to send freesurfer related commands from R studio out of curiosity.My Problem:I was trying to use freesurfer commands like mri_convert by sending them through the "system()" function in R. However, I got a "sh: mri_convert command not found" error. This indicates freesurfer is not sourced into the Linux terminal in the R Session. My Question: Is it possible to run freesurfer related commands from the rstudio terminal? What I did:I looked up this problem online and found a similar example where the user needed the function bedtools. But updating the system path still threw the same error with .In addition, I was able to send commands like "dcm2niix" from R using the system function mentioned above. I am certain this is a sourcing issue. Would appreciate any insightThank youShrikanth_______________________________________________Freesurfer mailing listFreesurfer@nmr.mgh.harvard.eduhttps://mail.nmr.mgh.harvard.edu/mailman/listinfo/freesurfer