0

Not my area of expertise, so apologies in advance. I am trying to run a command through system2() in R

The "planet" command (python program) works fine when typed directly in CMD:

F:\>planet --version
>1.5.2

However, I can't get it to recognize the command via system2() in either R or RStudio:

my_command <- "planet"
my_args <- " --version"
system2(command=my_command, args=my_args, stdout=TRUE)

>Error in system2(command = my_command, args = my_args, stdout = TRUE) : 
  '"planet"' not found

I read elsewhere that sometimes system() and system2() work in mysterious ways compared to shell(). So I also tried:

my_command <- "C:\\WINDOWS\\system32\\cmd.exe"
my_args <- "planet --version"
system2(command=my_command, args=my_args, stdout=TRUE)

>[1] "Microsoft Windows [Version 10.0.22621.1265]"     "(c) Microsoft Corporation. All rights reserved."
[3] ""                                                "C:\\Users\\alonzo\\Documents>"                  
Warning message:
In readLines(rf) :
  incomplete final line found on 'C:\Users\alonzo\AppData\Local\Temp\Rtmpi0YeU3\file62084c285bff'

Any advice? I believe this all used to work fine on a different computer. I just installed Python and "planet" on this computer so maybe there is a PATH issue but it's not clear to me. Thank you.

  • afaics you got there halfway. the system2 command is built like this: `system2(command = "powershell", args = "help", stdout = T)`. you can ofc. use `cmd` or `planet` (includng the path there, instead of `powershell` but then you need to be careful with `args=` & `input=`. For example, with anaconda: `system2("C:/Users/.../Anaconda3/Scripts/activate.bat", "C:/Users/.../Anaconda3 && conda --help")` works well, in this case only calling `--help` – D.J Mar 13 '23 at 13:28
  • I ran your command ```system2(command = "powershell", args = "help", stdout = T)``` successfully in R. However, if I change to ```system2(command = "powershell", args = "planet", stdout = T)```, it doesn't work. But ```planet``` works fine directly in powershell. Maybe you address this is the second part of your comment, but I didn't quite follow. – mikealonzo47 Mar 13 '23 at 15:15
  • How did you install `planet`? If you just installed them, you might want to restart your computer or at least R. Change to PATH values only take place when a program starts. It will not change while a program is running. – MrFlick Mar 13 '23 at 15:17
  • @MrFlick... embarrassingly, restarting solved the problem. I was too far into the rabbit hole. Thank you. – mikealonzo47 Mar 13 '23 at 15:28

0 Answers0