的R - 运行源()在后台 [英] R - Run source() in background

查看:724
本文介绍了的R - 运行源()在后台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从R控制台后台执行A R脚本。

I want to execute a R script in the background from the R console.

在控制台中,我通常运行R.脚本作为源(〜/。主动-rstudio文档)
我要等到剧本完成我的工作,剩下的继续。
取而代之的是,我想R以在后台运行时,我可以用我在控制台的工作继续进行。
此外,我r应该完成的源命令的时候以某种方式通知。
这是可能的R'

From the console , i usually run R script as source('~/.active-rstudio-document') I have to wait until the script is completed to go ahead with my rest of work. Instead of this i want R to be running in the background while i can continue with my work in the console. Also i should be somehow notified when R completes the source command. Is this possible in R ?

因为我们经常看到的工作需要长时间,这可能是非常有用的。

This might be quite useful as we often sees jobs taking long time.

聚苯乙烯 - 我想源脚本在相同的内存空间,而不是一个新的运行。因此,像叉子解决方案,系统等不会为我工作。我看到,如果我可以作为一个单独的线程中运行第r脚本,而不是一个单独的进程。

PS - i want the source script to be running in the same memory space rather than a new one. Hence solutions like fork , system etc wont work for me. I am seeing if i can run the R script as a separate thread and not a separate process.

推荐答案

您可以使用系统()和RSCRIPT运行脚本作为异步后台进程:

You can use system() and Rscript to run your script as an asynchronous background process:

system("Rscript -e 'source(\"your-script.R\")'", wait=FALSE)

在你的脚本的末尾,你可以保存 save.image你的对象(),以便在以后加载它们,并以<$ C建成的通知$ C>猫():

At the end of your script, you may save your objects with save.image() in order to load them later, and notify of its completion with cat():

...
save.image("script-output.RData")
cat("Script completed\n\n")

希望这有助于!

这篇关于的R - 运行源()在后台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆