`system` doesn't have access to path in RStudio

I'm trying to send a system command in RStudio with the system command. I am trying to interface with pixi.

If I run this in my terminal, it works irrespective of whether I use sh/bash/zsh/nushell:

❯ r

R version 4.4.2 (2024-10-31) -- "Pile of Leaves"
Copyright (C) 2024 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin20

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> system("pixi -V")
pixi 0.47.0
>

Similarly, if I run pixi -V in the RStudio Terminal, it also works. Likewise, it works in both the Terminal and console in Positron.

But I get an error if I run it in the R console in RStudio:

> system("pixi -V")
sh: pixi: command not found
Warning message:
In system("pixi -V") : error in running command

So a couple of questions:

  • How come stuff on PATH everywhere else is not on PATH in the shell called by system?
  • How can I make the above example work? Can I make a function that automatically adds it to the PATH of whichever shell RStudio uses?

I'm on RStudio Version 2025.05.0+496 (2025.05.0+496).

Random idea, does shell("pixi -V") work?

I'm on MacOS, so unfortunately not. shell only works on Windows.

1 Like

Bear with me here. I'm on Linux, and I'm not sure how directly this will translate to MacOS.

If I run echo $PATH in the RStudio terminal, I get a complete search path for executable programs including stuff I added in my local configuration. If I run system("echo $PATH") in the RStudio console, I get a considerably shorter path, minus the local configuration bits. So this may boil down to whether "pixi" is installed on the basic system path (I'm pretty sure I'm abusing terminology there) or somewhere that gets added to your command path in your personal configuration files.

There's a support ticket that might be relevant. Meanwhile, a couple of possible workarounds come to mind. One is supplying the path to "pixi" in the argument to system(). Another is to put a symlink to "pixi" somewhere on the path that RStudio uses (the path you get in the console).