在R中运行异步功能 [英] Run asynchronous function in R

查看:57
本文介绍了在R中运行异步功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

myfun <- function() {
  fun2()

  return(1+1)
}

我希望fun2()被调用,然后移到下一行而不等待结果. fun2函数不返回任何内容,我也不在乎它何时完成,我只需要启动它即可.最好的方法是什么?并行进程,多线程,异步调用?任何代码示例,不胜感激.

I want fun2() is invoked and then moved to the next lines without waiting for the result. Function fun2 does not return anything and I don't care when it finishes, I just need to launch it. What is the best way to achieve it? Parallel process, multithreading, async call? Any code samples are appreciated.

推荐答案

最终,我停止了以下解决方案:

Eventually I stopped on the following solution:

Rpath <- Find(file.exists, c(commandArgs()[[1]], file.path(R.home("bin"), commandArgs()[[1]]),
                             file.path(R.home("bin"), "R"), file.path(R.home("bin"), "Rscript.exe")))
out <- system('%s --no-save --slave -e \"Your R code here\" ', wait=FALSE)

第一行搜索R可执行文件的路径,第二行从命令行环境执行R代码,而不等待结果.

The first line searches for the path of R executable, and the second executes R code from the command-line environment not waiting for result.

这篇关于在R中运行异步功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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