[R] Update MS Windows PATH variable based on a R script

Yihui Xie xie at yihui.name
Fri Dec 9 04:14:38 CET 2011


Probably cool but "evil", I should say, but I do not have a better
choice at the moment.

This script does not take the R version into account (e.g. after you
update R, your new version may not be able to get into PATH via this
script), so you may consider improving it a little bit. Please contact
me offline if you are interested.

Regards,
Yihui
--
Yihui Xie <xieyihui at gmail.com>
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA



On Thu, Dec 8, 2011 at 4:16 PM, Janko Thyson
<janko.thyson.rstuff at googlemail.com> wrote:
> This is a very very very late follow up, but I remember asking this question
> and just stumbled across an answer by Yihui. Check his file
> 'add-R-path-win.R' script which you can find at
> https://github.com/yihui/lyx/blob/master/README.md
>
> Very cool, thanks Yihui.
>
> Regards,
> Janko
>
>
> On 29.06.2011 20:58, Duncan Murdoch wrote:
>>
>> On 29/06/2011 2:24 PM, Janko Thyson wrote:
>>>
>>> Dear list,
>>>
>>> this is not directly an R question, but it is somewhat related to R
>>> aspects, so I hope it's okay to post it here:
>>>
>>> I'd like to update my windows PATH based on a script routine in order to
>>> make sure that crucial components are contained. Much like what happens
>>> at the installation of Rtools (if desired). Now, can you do that from
>>> within R or do I need some sort of windows batch file or something like
>>> AutoIt script (http://www.autoitscript.com/site/autoit/)? If so, what
>>> would I need to put in there?
>>
>>
>> You need to set the registry entry if you want a persistent change to the
>> PATH.  Sys.setenv just modifies R's copy of the PATH.  Child processes will
>> see the modifications, but they don't last beyond the R session.
>>
>> You'll have to check MS docs to find which registry entry to mess with.
>>  Alternatively, if you feel lucky, just use Control Panel to set some
>> strange path, then see where your change showed up using regedit.
>>
>> R doesn't have a built-in function to write to the registry, but there are
>> various utilities available outside of R to do it.
>>
>> Duncan Murdoch
>>
>>>
>>> Here's what I tried in R:
>>>
>>> unlist(strsplit(Sys.getenv("PATH"), ";"))
>>> PATH.0<- Sys.getenv("PATH")
>>> PATH.1<- paste(PATH.0, "C:\\blabla\bin")
>>> Sys.setenv("PATH"=PATH.1)
>>> unlist(strsplit(Sys.getenv("PATH"), ";"))
>>>
>>> The changes seem to be reflected, but when I check my PATH the new entry
>>> isn't there. I guess there is no actual "feedback" to Windows system
>>> environment variable and that's exactly what I would like to accomplish
>>>
>>> Thanks a lot for any advice,
>>> Janko
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list