[R] PythonInR. Python script in R with parameters required. Download satellite images from NASA
Florian Schwendinger
Florian_Schwendinger at gmx.at
Sun Aug 2 13:01:42 CEST 2015
I believe the Problem is that you trying to give command line arguments
pyExecfile("myPythonScript.py") and pyExecfile only expects to get a
filename.
In Pyhton27 pyExecfile only runs the Python command execfile on the
given filename. So the Problem is that in
pyExecfile("C:/Landsat/download_espa_order.py" -e "magifranquesa at gmail.com"
-o "magifranquesa at gmail.com-07222015-120911" -d "C:/Landsat/ESPA")
your not only providing a file name but also command line arguments.
It is maybe easier for you to use the command line. Something like the
following should work
python <- "C:/Python27/python.exe"
pyScript <- "C:/Landsat/download_espa_order.py"
email <- "youremail at gmail.com"
order <- "youremail at gmail.com-order-number"
targetDirectory <- "C:/Landsat/ESPA"
pyArgs <- sprintf("--email %s --order %s --target_directory %s",
email, order, targetDirectory)
pyArgs
cmd <- sprintf("%s %s %s", python, pyScript, pyArgs)
cmd
system(cmd ,wait=FALSE)
or
system("C:/Python27/python.exe C:/Landsat/download_espa_order.py --email
magifranquesa at gmail.com --order magifranquesa at gmail.com-07222015-120911
--target_directory C:/Landsat/ESPA", wait=FALSE)
If you want to use PythonInR you could something like the following.
pyConnect(pythonExePath=python)
setwd("C:/Landsat/")
pyExec("import download_espa_order")
pySet("email", email)
pySet("order", order)
pyGet("[scene for scene in SceneFeed(email).get_items(order)]")
Florian
On 07/29/2015 06:29 PM, Magi Franquesa wrote:
> Hello,
>
> I'm trying to execute a python script within R (3.2.1 x 64) with the
> PythonInR package. I would like to download an order of satellite images
> from Nasa using a python script (
> http://landsat.usgs.gov/documents/espa_bulk_downloader_v1.0.0.zip) but I
> have no success. I first run the pyExecfile command with the *feedparser.py*
> script and then the *download_espa_order.py* giving the required parameters
> (my mail acount and the order number), here is the code:
>
> setwd("C:/Python27")
> install.packages("PythonInR")
> library(PythonInR)
> pyConnect(pythonExePath="C:/Python27/python.exe")
> pyIsConnected()
> # autodetectPython("C:/Python27/python.exe")
>
> pyExecfile("C:/Landsat/feedparser.py")
> pyExecfile("C:/Landsat/download_espa_order.py" -e "magifranquesa at gmail.com"
> -o "magifranquesa at gmail.com-07222015-120911" -d "C:/Landsat/ESPA")
>
> and I get this error:
>
> Error: unexpected string constant in
> "pyExecfile("C:/Landsat/download_espa_order.py" -e
> "magifranquesa at gmail.com""
>
> The code "C:/Landsat/download_espa_order.py" -e
> "magifranquesa at gmail.com" -o "magifranquesa at gmail.com-07222015-120911"
> -d "C:/Landsat/ESPA" runs ok when I use it within
> system console.
>
> I appreciate if someone could help me to solve this problem.
>
> Thank you
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>
More information about the R-help
mailing list