Access Windows Registry inside R

為{幸葍}努か 提交于 2021-02-11 04:21:23

问题


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!


回答1:


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").)




回答2:


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.



来源:https://stackoverflow.com/questions/23936347/access-windows-registry-inside-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!