I've noticed that the PATH is actually duplicated in e.g. R.app (when
launched from the dock).
> env <- Sys.getenv()
> as.list(env[names(env) == "PATH"])
$PATH
[1] "/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin"
$PATH
[1] "/usr/bin:/bin:/usr/sbin:/sbin"
It is the second of these that `system` sees:
> system("echo $PATH")
/usr/bin:/bin:/usr/sbin:/sbin
but if we explicitly unset and reset the PATH, we get the (expected?) PATH back:
> Sys.unsetenv("PATH")
> Sys.setenv(PATH = "/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin")
> system("echo $PATH")
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
There are a number of other environment variables that are duplicated
as well, e.g.
> names(env[duplicated(names(env))])
[1] "Apple_PubSub_Socket_Render" "DISPLAY"
"HOME"
[4] "LOGNAME" "PATH"
"SHELL"
[7] "SSH_AUTH_SOCK" "TMPDIR" "USER"
No idea if this is expected or meaningful, but I thought I would post
this for posterity.
Cheers,
Kevin
On Sat, Oct 25, 2014 at 3:01 AM, Duncan Murdoch
<[email protected]> wrote:
> On 24/10/2014, 9:03 AM, Simon Urbanek wrote:
>>
>>> On Oct 24, 2014, at 7:36 AM, peter dalgaard <[email protected]> wrote:
>>>
>>>
>>> On 24 Oct 2014, at 12:55 , Duncan Murdoch <[email protected]> wrote:
>>>
>>>> On 24/10/2014, 1:37 AM, Simon Urbanek wrote:
>>>>>
>>>>> On Oct 24, 2014, at 12:22 AM, Emma Sherratt <[email protected]>
>>>>> wrote:
>>>>>
>>>>>> Dear Mac R community,
>>>>>>
>>>>>> I wonder if anyone else has come across this issue. After installing the
>>>>>> new Mac OS10.10 Yosemite, I am now having a strange problem.
>>>>>>
>>>>>> I'm trying to use movie3d and run similar functions based on this I have
>>>>>> written myself.
>>>>>>
>>>>>> Specifically, when I run
>>>>>>
>>>>>>> system("convert --version")
>>>>>> sh: convert: command not found
>>>>>>
>>>>>> yet, it is not a path issue.
>>>>>>> Sys.getenv("PATH")
>>>>>> [1]
>>>>>> "/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/git/bin:
>>>>>> */opt/ImageMagick/bin*:/usr/texbin"
>>>>>>
>>>>>
>>>>> It is, because Yosemite ignores PATH for processes started from a GUI
>>>>> application. You will see if you run
>>>>> system("echo $PATH")
>>>>>
>>>>> You have to use full paths in Yosemite for anything that is not on the
>>>>> "sanctioned" PATH -- or use R from the shell.
>>>>
>>>> What is the best way to find the full path to a command there, since
>>>> Sys.which() sees the same PATH as system() does?
>>>>
>>>> Alternatively, how do you modify the PATH that system() sees?
>>>>
>>
>> From what I've read you can't from the parent process. You have to set it in
>> the child process once it's created - that's how some people have worked
>> around it.
>
> What about doing it from outside the process? How would I (running as
> superuser) change the path that GUI apps see, so that they can all see
> ImageMagick's convert, for example?
>
> Duncan Murdoch
>
>>
>>
>>>> Duncan Murdoch
>>>>
>>>> _______________________________________________
>>>> R-SIG-Mac mailing list
>>>> [email protected]
>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-mac
>>>
>>>
>>> Disclaimer: I'm at the office computer right now, still on Mavericks.
>>>
>>> In my limited experimentation, I found that you can pass the PATH
>>> explicitly as in
>>>
>>> path <- Sys.getenv("PATH")
>>> cmd <- paste("PATH=", path, "; which pdflatex")
>>> system(cmd)
>>>
>>> I don't recall needing to export PATH, and there could be complications
>>> with the shell flavour (sh, ash, bash, zsh, ...). Also, I think it wants to
>>> be two commands with the intervening semicolon, but it might work without
>>> it. Anyways, give it a try.
>>>
>>
>> I think it's better without so it is inherited implicitly, i.e.
>> system(paste0("PATH=",shQuote(Sys.getenv("PATH"))," which pdflatex"))
>>
>> As said above, it has to happen in the child process, that's why this works.
>>
>> Since this is a security measure, I'm not sure that we want to work around
>> it in R. Moreover, the PATH in LS apps has always been different, so you had
>> to alway exert some effort to make it match - in that sense it's not new,
>> just more complicated ;) However, I can see that it surprises people, so I'm
>> not sure what to do about it.
>>
>> Cheers,
>> Simon
>>
>>
>>
>>
>>> --
>>> Peter Dalgaard, Professor,
>>> Center for Statistics, Copenhagen Business School
>>> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
>>> Phone: (+45)38153501
>>> Email: [email protected] Priv: [email protected]
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>
>
> _______________________________________________
> R-SIG-Mac mailing list
> [email protected]
> https://stat.ethz.ch/mailman/listinfo/r-sig-mac
_______________________________________________
R-SIG-Mac mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-mac