Open pulidofabs opened 1 year ago
Hi.
Conceptually, call batchMap()
the same way as you call lapply()
or purrr::map()
. So, when you do:
Njobs <- 1:4
ids <- batchMap(fun=myFct, x=Njobs)
and alternative would be to call:
Njobs <- 1:4
res <- lapply(FUN=myFct, X=Njobs)
If you try the latter, you'll get the same type of error;
Error in FUN(X[[i]], ...) : unused argument (X[[i]])
So, the problem is that lapply()
, and batchMap()
ends up calling myFct(1)
, myFct(2)
, ..., but your myFct()
function does not take any arguments.
This leads to the second thinko, I think you've got: Your myFct()
does not take any arguments. If you call the same function four times, wouldn't you expect it to do the exact same type of calculations four times? I suspect you don't want that. Instead, it looks like you're using physeq
as some type of input data; if so, you probably need to figure out how to load different physeq
data for each iteration.
PS. Please have a look at https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax how to do code-formatting here on GitHub; makes it all easier to read.
@HenrikBengtsson Thank you so much for your quick response, and my apologies for the formatting on the previous post.
So the issue here is then with my function. I have never created or even attempted to create a function, so this was my first try. When I run the function as a stand-alone using this code (see code 1), the code works correctly; it just breaks when submitting the job to the cluster.
Any advice on how to get this going would be greatly appreciated!
Code 1
myFct<- function() {
Fun <- tax_glom(physeq, "Function")
Fun1<-psmelt(Fun)
FunTrt <- merge_samples(Fun, "Treatment")
FunTrt1<-psmelt(FunTrt)
names(FunTrt1)[2]<-"Trt"
return(FunTrt1)
}
myFctNam() #get results
When I run the function as a stand-alone using this code (see code 1), the code works correctly
What do you expect from your function when you call it multiple times?
myFctNam() #get results
myFctNam() #get results
myFctNam() #get results
myFctNam() #get results
I'd say, it should be your first goal to figure that part out. That'll solve half of your problem.
I would not worry about batchtools at all, until you solved that. Instead, focus on how it should work with a for-loop or an lapply() call.
I don't have the resources to work with you on this - I recommend you reach out on Stack Overflow, or to some local R folks if you have those around.
Hi,
I am having an issue with getting batchtools to work. I am following this tutorial and have edited the function to work with my phyloseq function. When I just the function on it on and get the results it works. However, when I submit it with batchtools it always fails. Can you please help.
Here is my complete code and errors: #Create function
Run function to make sure it actually works
myFctNam()
#Submit slurm job