Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set RHOME env-var to account for Rscript #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Set RHOME env-var to account for Rscript #4

wants to merge 1 commit into from

Conversation

mhermher
Copy link

Rscript is not portable because it uses a compile time absolute path for the R home directory. So any R code that calls something like system('/path/to/Rscript', ...) will fail because the Rscript file will in turn call R at the original hard-coded absolute path. For example, parallel::newPSOCKnode() uses this type of command, meaning that any code using PSOCK parallel cluster will not work.

I am not sure if shiny or any of this electron setup ever calls code that in turn makes a call to Rscript. If not, then it is probably fine.

Interestingly, Rscript does check to see if the R home directory is being overridden in the environment, and uses that path instead of the compile time path. However, it does so by looking for the deprecated RHOME env-var instead of R_HOME. Instead of re-compiling Rscript (and wrangling with all the tooling involved in that), we can work around it by assigning into the RHOME env-var as well.

I actually have not tested your library here, but I was reading through it because I was trying to create a portable R as well. I see that you have a binary Rscript in the root directory, so maybe this is a re-compiled version that works so maybe my change is not needed at all.

You can test it simply by ./R-Portable-Mac/bin/Rscript -e "R.home()" and see if that is correctly set. Without this current fix, my attempt at portable R was giving me the compile time path rather than the ported path.

Rscript is not portable because it uses a compile time absolute path for the R home directory. So any R code that calls something like `system('/path/to/Rscript', ...)` will fail because the Rscript file will in turn call R at the original hard-coded absolute path. For example, parallel::newPSOCKnode() uses this type of command, meaning that any code using PSOCK parallel cluster will not work.

I am not sure if shiny or any of this electron setup ever calls code that in turn makes a call to Rscript. If not, then it is probably fine.

Interestingly, Rscript does check to see if the R home directory is being overridden in the environment, and uses that path instead of the compile time path. However, it does so by looking for the deprecated RHOME env-var instead of R_HOME. Instead of re-compiling Rscript (and wrangling with all the tooling involved in that), we can work around it by assigning into the RHOME env-var as well.
@mhermher
Copy link
Author

Sorry if you have already accounted for this. I wanted to type that all out for my own documentation at least. Ignore this PR if you've already resolved this in some other way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant