[R] system() or shell() with python script

Paul Hiemstra p.hiemstra at geo.uu.nl
Tue Oct 20 12:43:10 CEST 2009


Remko Duursma wrote:
> Hi all,
>
> I am having some problems calling a python script from R that resides
> in a folder that is in the path (WindowsXP):
>   
Hi Remko,

Some suggestions:

1. Try to see if the path that R has from a call to system is correct 
(i.e. the same as from cmd):

system("path")

2. Try calling it with python added in front:

system("python script.py")

3. Add a shebang line to the top of your script like:

#! c:/Program Files/Python/python.exe

This tells the OS which program you want to use to run the script.

cheers,
Paul

ps maybe superfluous, but try the python getopt package for reading 
commandline arguments.
>   
>> system("quickPadTool.py")
>>     
> Warning message:
> In system("quickPadTool.py") : quickPadTool.py not found
>
> # I also tried 'shell' (and shell.exec as well).
>   
>> shell("quickPadTool.py")
>>     
> 'quickPadTool.py' is not recognized as an internal or external command,
> operable program or batch file.
> Warning message:
> In shell("quickPadTool.py") :
>   'quickPadTool.py' execution failed with error code 1
>
> I can run the script fine from a command window just fine, from the
> same directory.
>
> Any pointers?
>
> thanks,
> Remko
>
>
>
>
>
> -------------------------------------------------
> Remko Duursma
> Post-Doctoral Fellow
>
> Centre for Plants and the Environment
> University of Western Sydney
> Hawkesbury Campus
> Richmond NSW 2753
>
> Dept of Biological Science
> Macquarie University
> North Ryde NSW 2109
> Australia
>
> Mobile: +61 (0)422 096908
> www.remkoduursma.com
>
> ______________________________________________
> 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.
>   


-- 
Drs. Paul Hiemstra
Department of Physical Geography
Faculty of Geosciences
University of Utrecht
Heidelberglaan 2
P.O. Box 80.115
3508 TC Utrecht
Phone:  +3130 274 3113 Mon-Tue
Phone:  +3130 253 5773 Wed-Fri
http://intamap.geo.uu.nl/~paul




More information about the R-help mailing list