0

I want to call python script using the system command. I am passing a parameter with it, but the variable is dynamic. I am not sure how to paste the filename dynamically. I would like the Filename to be changed depending on the user input.

system('python testMethod.py Filename', wait = TRUE)
2
  • Wrap system in a function that takes user input or use some system level reader/prompt? Commented May 15, 2020 at 16:27
  • 1
    Just paste the variable. Commented May 15, 2020 at 16:29

1 Answer 1

4

Use paste0 to create the command string:

filenname <- "Filename"
system(paste0("python testMethod.py ", filename), wait = TRUE)

Edit: M--'s suggestion does make it cleaner:

filenname <- "Filename"
system(paste("python testMethod.py", filename), wait = TRUE)
Sign up to request clarification or add additional context in comments.

2 Comments

Use paste instead of paste0 and get rid of that manually entered space at the end of first string. That's cleaner.
also paste is more portable than paste0 to older versions of R

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.