2

Let me start by saying I am new to programming.

I am hoping to run a python script from the command line within an R script. I am running windows xp but also have a machine that runs Windows 7. I can run the following code without error for the dos-prompt.

cd C:\Documents and Settings\USER\workspace\UGA - Website
python test1.py

I have tried all sorts of different attempts in R using ?system, but am hoping someone can point me to what I am doing wrong. For example, here is just one attempt (it was recommended to use absolute paths)

cmd.1 <- shQuote("C:Python26/python.exe C:/Documents and Settings/USER/Desktop/UGA New Website", type="cmd")
system(cmd.1)

Any guidance will be very much appreciated

2
  • Aren't you just missing / in C:Python26..? Commented Jul 19, 2010 at 19:41
  • @Bitbert3: Not tested, but I think since your target path contains spaces you also need to quote that. Commented Jul 20, 2010 at 13:05

3 Answers 3

2

Thanks for the help everyone. My issue was a combination of things, but this chunk of code worked.

shell(paste("python", shQuote("C:\\Documents and Settings\\USER\\Desktop\\UGA New Website\\metrics_get.py")))

Many thanks

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

Comments

1

Add a / after C:, which would make it look like this:

cmd.1 <- shQuote("C:Python26/python.exe C:/Documents and Settings/USER/Desktop/UGA New Website", type="cmd")
system(cmd.1)

Comments

1

Not tested but try this:

cmd.1 <- shQuote('C:\\Python26\\python.exe "C:\\Documents and Settings\\USER\\Desktop\\UGA New Website"', type="cmd")
system(cmd.1)

If this doesn't work, try variations on \, \\ and /, and where you put your quotes.

You could also try a system cd command to change the directory, so you don't need an absolute path.

Comments

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.