setTimeLimit 如何在 R 中工作? [英] How does setTimeLimit work in R?

查看:31
本文介绍了setTimeLimit 如何在 R 中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试掌握 R 中的 setTimeLimit() 并且我的经验导致了几个相关的问题,所以基本问题可能是:这到底是如何工作的?(我也一直在查看 R.utils 中的 evalWithTimeout(),它可能更适合我的目的,但它是基于此函数构建的.)

I am trying to master setTimeLimit() in R and my experience has led to several related questions, so maybe the fundamental question is: how does this really work? (I have been looking at evalWithTimeout() from R.utils as well, and it may suit my purposes slightly better, but it's built on this function.)

以下是我想弄清楚的关键问题:

Here are the key things I am trying to figure out:

  1. 它如何监控经过的时间?IE.它似乎被插入到流量控制中,那么它是如何做到的呢?能够拥有后台"进程很酷,可用于报告状态、检查点等.

  1. How does it monitor the elapsed time? I.e. it seems to get inserted into the flow control, so how does it do that? Being able to have "background" processes is cool, and could be used for reporting status, checkpointing, and more.

我能确定距离触发还有多长时间吗?我意识到我可以将它包装起来并在某处存储过去的 &大约在调用点(即 proc.time() 的输出)消耗的 CPU 时间.但是,这个函数已经将这些存储在某个地方,我想知道在哪里,或者至少如何确定剩余时间.

Can I determine how much time remains until it is triggered? I realize I can wrap it and store, somewhere, the elapsed & CPU time consumed at about the point of invocation (i.e. the output of proc.time()). But, this function is already storing these somewhere and I'd like to know where, or at least how to determine the time remaining.

如果 R 控制台空闲,它可以做一些有用的事情吗?能够监控 elapsed.time()cpu.time() 非常有用.我希望能够监视 R 何时空闲,但从修补看来,它需要提交或完成命令.此外,仅输出错误不会触发后续操作.(也许我需要更多关注 evalWithTimeout.)

Can it be made to do something useful if the R console is idle? Being able to monitor elapsed.time() and cpu.time() is very useful. I'd like to be able to monitor when R is idle, but it seems from tinkering that it requires a command to be submitted or completed. Moreover, just outputting an error doesn't trigger a subsequent action. (Maybe I need to give more attention to evalWithTimeout.)

帮助信息说可以用C或Fortran,但没有给出例子.关于如何做到这一点有什么建议吗?

The help information says that it can be applicable with C or Fortran, but doesn't give examples. Any suggestions on how this should be done?

推荐答案

要显示 setTimeLimit 在 C 函数调用期间不起作用:

To show that setTimeLimit does not work during a C function call:

rfunction <- function(){
    repeat{
        x <- rnorm(100);
    }
}

cfunction <- function(){
    x <- eigen(matrix(rnorm(1e6), 1e3));
}

setTimeLimit(3);
system.time(try(rfunction(), silent=TRUE))
system.time(try(cfunction(), silent=TRUE))

这篇关于setTimeLimit 如何在 R 中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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