0

I am trying to run an R script that is in the same directory as the python script while executing the python script.

So far, I have:

if condition is True:
    import subprocess
    subprocess.call (["C:/Program Files/R/R-3.4.3/Rscript", "./testing.r"])
    sys.exit()

I keep getting the error:

OSError: [WinError 193] %1 is not a valid Win32 application

I've tried replacing "C:/Program Files/R/R-3.4.3/Rscript" with "/usr/bin/Rscript" but keep getting the same error. I was wondering if anybody would know why it keeps throwing this error?

4

1 Answer 1

2

I believe the arguments of subprocess.call get passed straight to the command line, so you need to escape your quotation marks as such "\"C:/Program Files/R/R-3.4.3/Rscript\"". That being said, I get a [WinError 5] Access violation error when I use this. A workaround is to use the executable argument:

import sys
import subprocess

if True is True:
    subprocess.call(["C:/Program Files/R/R-3.4.3/Rscript.exe", "./testing.r"], 
                    executable="C:/Program Files/R/R-3.4.3/Rscript.exe")
    sys.exit()

Also, make sure that C:/Program Files/R/R-3.4.3/Rscript.exe is the location of your Rscript.exe. Mine is C:/Program Files/R/R-3.4.3/bin/Rscript.exe.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, I was missing the "bin" in "C:/Program Files/R/R-3.4.3/bin/Rscript.exe". Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.