Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 204771

How to run Python script from R?

$
0
0

I'm trying a simple example but it fails:

system("cmd.exe", input = 'python --version')

Microsoft Windows [Wersja 6.1.7601] Copyright (c) 2009 Microsoft Corporation. Wszelkie prawa zastrzezone.

C:\Users\cp\Documents\R DATA\LocalAuth>python --version Nazwa 'python' nie jest rozpoznawana jako polecenie wewnetrzne lub zewnetrzne, program wykonywalny lub plik wsadowy.

I understand, the cmd should not work there, but when I open:

system("C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", input = 'python --version')

Windows PowerShell Copyright (C) 2016 Microsoft Corporation. All rights reserved.

PS C:\Users\cp\Documents\R DATA\LocalAuth> python --version python : The term 'python' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + python --version + ~~~~~~ + CategoryInfo : ObjectNotFound: (python:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

When I open this console manually it works, but, in properties I see the full path:

%windir%\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy ByPass -NoExit -Command "& 'C:\ProgramData\Anaconda3\shell\condabin\conda-hook.ps1' ; conda activate 'C:\ProgramData\Anaconda3'"

How can I use it with all these parameters in R? When I try to use it link within system command I get:

Error in "%windir%\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy ByPass -NoExit -Command "& : operations are possible only for numeric, logical or complex types

I guess this must work someway: while I enter the dir within command console (cmd.exe) to "C:\ProgramData\Anaconda3" and type python --version I get a message but with system("C:\\ProgramData\\Anaconda3\\ python --version") it doesn't work. Why?

EDIT

Found non-elegent solution

setwd("C:/ProgramData/Anaconda3/")
system(command = 'cmd.exe', input = 'python --version')

It works but changes the working dir which is not required.


Viewing all articles
Browse latest Browse all 204771

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>