job icon indicating copy to clipboard operation
job copied to clipboard

Using job::job() within RMarkdown file

Open meghanmshea opened this issue 1 year ago • 1 comments

I am working on compiling one large RMarkdown file that reproduces all of the analyses for a scientific manuscript. A few of the analyses take a long time, so I've used job::job() to run them as jobs, which has worked great when I'm working through the RMarkdown file in RStudio.

But, I'd like to be able to knit the RMarkdown file to html/pdf to share with the manuscript too. But I get an error in the first chunk that includes a job::job() call when trying to render: Error in check_available(): ! You must run this from the RStudio main session. Backtrace:

  1. job::job(...)
  2. job:::check_available() Execution halted

Is there something I'm missing that would make it possible to render the RMarkdown even with the job sections? Or is this just fundamentally incompatible?

meghanmshea avatar Jun 28 '23 02:06 meghanmshea

I think you cannot do this based on these lines:

https://github.com/lindeloev/job/blob/452600154add99982b01bd029e39e3d6f8580d44/R/misc.R#L3-L4

This function only works in an RStudio main session.

psychelzh avatar Jul 18 '23 01:07 psychelzh

Hi @meghanmshea Sorry for the late reply, but @psychelzh is right. For your use case, you may want to look at the IDE-agnostic solutions mentioned under "See also" on https://lindeloev.github.io/job/. Namely {callr}.

lindeloev avatar May 02 '24 19:05 lindeloev