简体   繁体   English

自动化 R 来运行脚本

[英]Automating R to run scripts

I'm basically looking for any way to automatically run R scripts just like it would run as if I was copy and pasting it into console.我基本上是在寻找任何自动运行 R 脚本的方法,就像我将它复制并粘贴到控制台一样运行它。 I've tried the package 'taskscheduleR' however it just seems to output to a log file in the directory which isn't as if I were to just run it inside the Rstudio application.我已经尝试过“taskscheduleR”包,但它似乎只是输出到目录中的日志文件,而不是我只是在 Rstudio 应用程序中运行它。

An example might be, say I want to get the last closing stock prices of 5 stocks each night, then the script in Rstudio and have the variables there and all of the code would be in the script file.一个例子可能是,假设我想获得每晚 5 只股票的最后收盘价,然后是 Rstudio 中的脚本并在那里有变量,所有代码都在脚本文件中。

Any thoughts?有什么想法吗?

I would suggest the in-built Task Scheduler application if you using Windows.如果您使用 Windows,我建议您使用内置的任务计划程序应用程序。 Create a task that will run a batchscript file.创建一个将运行批处理脚本文件的任务。 This batchscript file has only 1 line which executes the Rscript you want.这个批处理脚本文件只有 1 行执行你想要的 Rscript。 Set it to run each night (or whatever time you want).将其设置为每晚(或您想要的任何时间)运行。

I am not that well-versed in linux and MacOS but here's what I know:我对 linux 和 MacOS 不是很精通,但这是我所知道的:

Linux has cron. Linux 有 cron。 Add a job to crontab with your preferred timing and execute your script 'path/to/bin/r /path/to/script.r'使用您喜欢的时间将作业添加到 crontab 并执行您的脚本 'path/to/bin/r /path/to/script.r'

MacOS has Automator + iCal (for scheduling). MacOS 有 Automator + iCal(用于调度)。 It also has crontab like Linux.它也有类似 Linux 的 crontab。

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

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