How can I access the windows registry inside R. For example, I want to access the folder:
[HKEY_LOCAL_MACHINE\SOFTWARE\R-core\R\3.0.2]
and the key called "InstallPath"
to get:
"C:\\Program Files\\R\\R-3.0.2"
Many thanks!
How can I access the windows registry inside R. For example, I want to access the folder:
[HKEY_LOCAL_MACHINE\SOFTWARE\R-core\R\3.0.2]
and the key called "InstallPath"
to get:
"C:\\Program Files\\R\\R-3.0.2"
Many thanks!
You could use readRegistry()
.
On my machine:
fp <- file.path("SOFTWARE", "R-core", "R", "3.1.0", fsep="\\")
readRegistry(fp, "HLM") ## "HLM" eventually resolves to "HKEY_LOCAL_MACHINE"
# $InstallPath
# [1] "C:\\R\\R-current"
(Also, for future reference, in this case you could probably have found that out with a quick call to apropos("registry")
or even apropos("reg")
.)
From your question it is not obvious why you'd need to access the registry. If you just want the home directory of your R installation, you can use R.home()
. Alternatively you could use Sys.getenv("R_HOME")
. If that doesn't give you what you need (I can't test on Windows right now), maybe one of the other environment variables gives you what you need.