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()https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/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:
1. I looked up this problem online and found a similar examplehttps://stackoverflow.com/questions/26065564/why-cant-i-call-system-functions-in-r-that-clearly-work-in-my-terminal where the user needed the function bedtools. But updating the system path still threw the same error with . 2. 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 insight Thank you
Shrikanth
External Email - Use Caution
Hi Shrikanth,
All commands can be called from R, there is nothing special about FreeSurfer commands in that regard. If the command is not found from R, there is an issue with the path. The easiest way to check that is to simply use the full path to the command in question, this always works.
E.g., first find out the full path to mris_convert in a system shell (like bash):
$ which mris_convert /home/ts/software/freesurfer6/bin/mris_convert
Now call the command in R:
$ R
system("/home/ts/software/freesurfer6/bin/mris_convert")
Usage: /home/spirit/software/freesurfer/bin/mris_convert [options] <input file> <output file>
This program will convert MRI-surface data formats.
Valid options are: -p input is a patch, not a full surface -c <scalar file> input is scalar curv overlay file (must still specify surface) // snip.
For me, simply running
system("mris_convert")
also works, but this depends on your shell setup and the way you started R studio. Could it be that you have started R studio by clicking on an application icon in the start menu or desktop? In that case it cannot work, because your shell setup (which adds the FreeSurfer directory to your PATH) is not executed in the graphical user interface. If you start rstudio from a shell that has the correct setup (e.g., by typing 'rstudio' in bash), the environment will propagate to the R studio session and it will work.
Good luck,
Tim
-- Dr. Tim Schäfer Postdoc Computational Neuroimaging Department of Child and Adolescent Psychiatry, Psychosomatics and Psychotherapy University Hospital Frankfurt, Goethe University Frankfurt am Main, Germany
On 10/06/2021 10:13 PM Yadav, Shrikanth Muralidhar smyadav@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()https://secure-web.cisco.com/1HS7iIMyc0gEzsQMpQT62b7IKzVGhTakcOKRrwA-tYqxWswxeLVBy4LLYwrO3P03-9ong9GeOSuFOGdh1_tEDdswoGcg84_X-rYNSGFFMuh8eIDWOURHo99-YQTMlU0ND0KcNictGXAahu8EXzRUwEdCenb0mPBB4GKqQ57bsFkxNEHwpvougFCi4pFj7jBMWZru6lOOBA7ePwrL_rb1asckMsGHmzBsqvLugcXopG8PPzZRxMjJwkNMBWRpHzy65/https%3A%2F%2Fwww.rdocumentation.org%2Fpackages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2Fsystem" 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 examplehttps://secure-web.cisco.com/1HMdOF-GdNuwE8gUaDbRzRJkVriFZc44FGzUxZlQ2XxaG0tBsFqDdcUrQNWmykrXasw2XuJoSwSMrWgaDKuXf0YQsEe3xU86dE7iXnT3ClsaaWMLQPycexd7Jx9Ig-FyRdgNE54yRS73yMYoF6BAWKsWq6zTcVlfj6PPT0PwZVmghRRdqPnPXbc0Ywk0ubqQ_Mem6sToiIRGaZS7Kw8CA3tsUEuus3xfK2PlL7JvkjY_opzAWxMXmVwqNcI21tz8p/https%3A%2F%2Fstackoverflow.com%2Fquestions%2F26065564%2Fwhy-cant-i-call-system-functions-in-r-that-clearly-work-in-my-terminal 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 insight Thank you
Shrikanth _______________________________________________ Freesurfer mailing list Freesurfer@nmr.mgh.harvard.edu https://secure-web.cisco.com/16TW0p1qyaaO71A2RR6XWXYdUtChCRR8q0C6G-C2_xjRBGX... The information in this e-mail is intended only for the person to whom it is addressed. If you believe this e-mail was sent to you in error and the e-mail contains patient information, please contact the Mass General Brigham Compliance HelpLine at http://secure-web.cisco.com/1ewN2EV_5sgIQUfyf2Xi9ZLlHzrBFc4FcWBjnrVfwmewKrO9... . If the e-mail was sent to you in error but does not contain patient information, please contact the sender and properly dispose of the e-mail. Please note that this e-mail is not secure (encrypted). If you do not wish to continue communication over unencrypted e-mail, please notify the sender of this message immediately. Continuing to send or respond to e-mail after receiving this message means you understand and accept this risk and wish to continue to communicate over unencrypted e-mail.
freesurfer@nmr.mgh.harvard.edu