I need to print my r version in a bash chunk in an r markdown file. In my terminal, I can print the version using "R --version" but when I try that command in bash I get the following error "R: command not found." When I use commands like git --version in the bash shell it works normally. Does anyone have any idea why the R --version code is different?
Thank you!
CodePudding user response:
R -e 'cat(sessionInfo()$R.version$version.string, "\n")'
CodePudding user response:
You might be able to try this:
$(type R | grep -o '/.*') --version
type
will get you to the correct R version, grep
will extract the path, and then you can pass the --version
flag to get the R chunk.
Terminal output:
$ $(type R | grep -o '/.*') --version
R version 4.1.0 (2021-05-18) -- "Camp Pontanezen"
Copyright (C) 2021 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin17.0 (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License versions 2 or 3.
For more information about these matters see
https://www.gnu.org/licenses/.