Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将R变量传递给python函数的系统调用?_Python_R - Fatal编程技术网

如何将R变量传递给python函数的系统调用?

如何将R变量传递给python函数的系统调用?,python,r,Python,R,我已经用python编写了一个函数,它接受两个参数,其中一个是文件路径名。我已经将对这个python函数的调用封装在R中的一个循环中。我希望能够更新这个R for循环中的一个变量,并将这个变量的值作为文件路径名传递给python函数。我该怎么做 R代码: for (file in filenames) { file <- paste("/home/yyy/xx", file, sep="/") system('python pylib/filefunction.py &

我已经用python编写了一个函数,它接受两个参数,其中一个是文件路径名。我已经将对这个python函数的调用封装在R中的一个循环中。我希望能够更新这个R for循环中的一个变量,并将这个变量的值作为文件路径名传递给python函数。我该怎么做

R代码:

for (file in filenames) {
     file <- paste("/home/yyy/xx", file, sep="/")
     system('python pylib/filefunction.py <TODO: file> divide') # divide is the 2nd argument
}
for(文件名中的文件){

文件我相信您可以再次使用
粘贴

for (file in filenames) {
  file <- paste('/home/yyy/xx', file, sep='/')
  system(paste('python', 'pylib/filefunction.py', file, 'divide'))
}

如何将divide转换为字符串并将其连接到系统调用的末尾?(可能使用粘贴?)如果这不是正确答案,那么我不理解问题。(+1)
for (file in filenames) {
  system(sprintf('python pylib/filefunction.py /home/yyy/xx/%s divide', file))
}