rstudio - is it possible to run a code in the background

前端 未结 4 1176
无人及你
无人及你 2021-02-03 23:09

Question regarding RStudio. Suppose I am running a code in the console:

> code1()

assume that code1() prints nothing on the con

相关标签:
4条回答
  • 2021-02-03 23:54

    The future package (I'm the author) provides this:

    library("future")
    plan(multisession)
    
    future(code1())
    code2()
    

    FYI, if you use

    plan(cluster, workers = c("n1", "n3", "remote.server.org"))
    

    then the future expression is resolved on one of those machines. Using

    plan(future.BatchJobs::batchjobs_slurm)
    

    will cause it to be resolved via a Slurm job scheduler queue.

    This question is closely related to Run asynchronous function in R

    0 讨论(0)
  • 2021-02-03 23:55

    The mcparallel() function in the parallel package will do the trick, if you are on Linux, that is ...

    library(parallel)
    Job1 = mcparallel(code1())
    JobResult1 = mccollect(Job1)
    
    0 讨论(0)
  • 2021-02-04 00:04

    You can always do this, which is not ideal but works for most purposes:

    shell(cmd = 'Rscript.exe some_script.R', wait=FALSE)
    
    0 讨论(0)
  • 2021-02-04 00:05

    RStudio as of version 1.2 provides this feature. To run a script in the background select "Start Job" in the "Jobs" panel. You also have the option of copying the background job result into the working environment.

    0 讨论(0)
提交回复
热议问题