Reputation: 1022
I have written a function in python that takes two arguments one of which is a file path name. I have wrapped the call to this python function within a loop in R. I want to be able to update a variable in this R for loop and pass the value of this variable to the python function as the file path name. How can I do this?
R code:
for (file in filenames) {
file <- paste("/home/yyy/xx", file, sep="/")
system('python pylib/filefunction.py <TODO: file> divide') # divide is the 2nd argument
}
Upvotes: 2
Views: 1218
Reputation: 6625
I believe you can just use paste
again:
for (file in filenames) {
file <- paste('/home/yyy/xx', file, sep='/')
system(paste('python', 'pylib/filefunction.py', file, 'divide'))
}
Or, better yet, sprintf
:
for (file in filenames) {
system(sprintf('python pylib/filefunction.py /home/yyy/xx/%s divide', file))
}
Upvotes: 5