简体   繁体   English

R批处理文件夹中的所有文件

[英]R batch all files in folder

I have a list of .R files such as UK.R , France.R , Peru.R , Australia.R , and so on, in a folder called script_countries . 我在一个名为script_countries的文件夹中有一个.R文件列表,例如UK.RFrance.RPeru.RAustralia.R等。

Instead of doing each file separately 而不是分别处理每个文件

R CMD BATCH UK.R output.txt 

I was wondering if I could launch all the Rscripts with R CMD BATCH . 我想知道是否可以使用R CMD BATCH启动所有Rscripts

In other words, how can I R CMD BATCH all files in a directory? 换句话说, 如何R CMD BATCH目录中的所有文件?

I don't know anything about R, but a FOR loop should work: 我对R一无所知,但是FOR循环应该可以工作:

CD "C:\adjust\path"
FOR %%G IN ("*.R") DO (R CMD BATCH %%~nxG output.txt)

If you want mutliple output files you could replace output.txt with output_%%~nG.txt or something similar. 如果要使用多个输出文件,可以将output.txt替换为output_%%~nG.txt或类似的内容。

If your files contain spaces you might want to add quotation marks around the input and output, but I don't know how R handles that. 如果文件中包含空格,则可能需要在输入和输出周围添加引号,但是我不知道R是如何处理的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM