I want to run two R scripts in a 32bit and in a 64bit R respectively.
To automate this process, I have looked at this answer, which proposes a good way of automatizing this transition. This solution is inefective for more recent R versions, as from version 4.2.0, R has dropped support for 32bit builds.
In practice this means that as I need to use R_32bit, I have been forced to have
R Version 3.6.1 for my 32bit needs
R Version 4.2.1 for my 64bit needs
This means that the installations will be located in different folders, making the solution proposed here infeasible.
Hoiw can I access the environment variables that keeps track of the installation folder for the R 32 bit and the R 64 bit in my computer?
These environment variables are somewhere, as RStudio keeps track of these 32bit and 64bit installations which allows changing between them in Tools-> Global Options -> General
CodePudding user response:
You could query the environment for the "PATH" variable and scan its content. On a windows machine:
path_entries <-
Sys.getenv('PATH') |>
strsplit(';') |>
unlist()
## look for version 3.6.1
path_entries |>
(\(x) x[grep(x, pattern = 'R-3.6.1')])()
CodePudding user response:
I found out a way of requesting this from the Registry information:
# find the path to a R32bit and 64bit R installations
fp32 <- file.path("SOFTWARE", "R-core", "R32", fsep="\\")
fp64 <- file.path("SOFTWARE", "R-core", "R64", fsep="\\")
# path to Rscripts:
RScript_path_32 <- paste0(readRegistry(fp, "HLM")$InstallPath,"\\bin\\i386\\Rscript.exe")
RScript_path_64 <- paste0(readRegistry(fp, "HLM")$InstallPath,"\\bin\\x64\\Rscript.exe")
Finally, "HLM" is one of several potential Hives:
Hive code | Hive Name |
---|---|
HLM | HKEY_LOCAL_MACHINE |
HCR | HKEY_CLASSES_ROOT |
HCU | HKEY_CURRENT_USER |
HU | HKEY_USERS |
HCC | HKEY_CURRENT_CONFIG |
HPD | HKEY_PERFORMANCE_DATA |