0

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

  • Does `R.home()` work for you? See also this SO-answer: https://stackoverflow.com/questions/12291418/how-can-i-make-r-read-my-environmental-variables#12291478 –  Oct 14 '22 at 08:33
  • Thanks for the reply. This helps only partially. R.home() directs to the 64bit installation directory. How do I access the 32bit instllation directory? – user7964529 Oct 14 '22 at 10:51

2 Answers2

1

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')])()
  • this provides a partial answer, thanks. however, I still have the problem of locating the 32bit and the 64 bit installations, even if they might no t be in the PATH variable. – user7964529 Oct 14 '22 at 11:47
  • As long as there's an entry in the registry (again assuming windows) this might work: https://stackoverflow.com/questions/23936347/access-windows-registry-inside-r –  Oct 14 '22 at 11:51
0

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