Local job, Object not found

So I have a few rmarkdown documents i'd like to compile as local jobs. To this end I wrote a simple script calling render(document). This works fine for most documents, but for one I encounter a super weird 'object not found' error. The function call looks like this:

ado_relab_GEN_bray = adonis2( otu_table( ps_relab_GEN) ~ sam_dat$group2, method ="bray" )

where sam_dat is just defined above this line and adonis2 is the adonis function from vegan. Knitting the document from rstudio works, so does calling the render script from a terminal with Rscript...

sam_dat or sam_data ?

sam_dat, correcting above!

so let me recap:

  1. knitting the doc from rstudio works (you open the doc, press knit, all fine)
  2. go to terminal use Rscript, send it your custom simple script calling render(document) and that works ?
  3. your simple script calling render(document) run from Rstudio rather than Rscript, doesnt work ?

Yes. When running 3., I select the script from the jobs -> run local jobs menu and thats the only time it fails.

is it a small enough script that it can be shared here?

Yeah its tiny:


if you replace this long function call, with something that simply prints the sam_dat$group2 that was imeddiately defined the moment before.
Would that work in this 3rd case?

Yes, I've tried this. It only halts at the adonis2 function call.

adonis2(formula, data, permutations = 999, method = "bray", sqrt.dist = FALSE, add = FALSE, by = "terms", parallel = getOption("mc.cores"), ...)

so I see a 'formula' thats

otu_table( ps_relab_GEN) ~ sam_dat$group2

this part right?

but it doesnt look right to me as a formula because its got the $ to pick a variable from a different data set. and theres no explict data param.
can you maybe restruce the function call, to more explicitly set data, have all the variables in one data frame, and the formula cleanly naming them ?
probably will fix it up for you.

Hang on, I thought I'd tried printing it earlier, and I had, but slightly differently. So sam_dat is made by calling sample_data() on a variable called ps_relab. so ps_relab is assigned, then I call:

sam_dat <- sample_data(ps_relab)

It now halts at sample_data(). But print() seems to be working? Include is false, could that be a cause?

I don't believe sample_data() is a base or common function.. so I have no experience with that sorry.

I'm sorry, it's from the phyloseq library. It returns a table given a phyloseq object.

Ok. So is it failing silently, or printing errors/warnings?


Quitting from lines 405-501 (doc.rmd)
Error in sample_data(ps_relab) : object 'ps_relab' not found
Calls: sourceWithProgress ... model.frame -> model.frame.default -> eval -> eval -> sample_data

Is ps_relab a object of data.frame-class , or a phyloseq-class ?
what sort of print did it give you before you sent it to sample_data?

ps_relab is a phyloseq-class object. I can't see the output because its a rmarkdown being knitted, but it fails before it can create any output. print(ps_relab) should output a description of the object...

It's quite a pickle. All my experience is in traditional scripts and shiny apps, I rarely touch knitr/markdown world. I'll back out and hopefully someone else here with experience debugging markdown renders can help

1 Like

If you could attempt a reprex, just some minimal data and the fewest transformations to demonstrate an example of the fault. Sharing that here would help people help you.
Best of luck.

1 Like

Thank you for your time! I'll see if I can reproduce it.