Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Error in (function () : unused argument (x = 3) #290

Open
pulidofabs opened this issue Jan 14, 2023 · 3 comments
Open

Error in (function () : unused argument (x = 3) #290

pulidofabs opened this issue Jan 14, 2023 · 3 comments

Comments

@pulidofabs
Copy link

pulidofabs commented Jan 14, 2023

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

myFct<- function() {
Fun <- tax_glom(physeq, "Function")
Fun1<-psmelt(Fun)
FunTrt <- merge_samples(Fun, "Treatment") 
FunTrt1<-psmelt(FunTrt)
names(FunTrt1)[2]<-"Trt" 
return(FunTrt1)
}

#Run function to make sure it actually works
myFctNam()

**#Submit slurm job **

reg <- makeRegistry(file.dir="myregdir", conf.file=".batchtools.conf.R")
Njobs <- 1:4 # Define number of jobs (here 4)
ids <- batchMap(fun=myFct, x=Njobs) 
done <- submitJobs(ids, reg=reg, resources=list(partition="short", walltime=60, ntasks=10, ncpus=1, memory=1024))
waitForJobs()
``` # Wait until jobs are completed


**#Results**
**waitForJobs() # Wait until jobs are completed                               
[1] FALSE **

**getStatus()** 
Status for 4 jobs at 2023-01-13 21:27:41:
  Submitted    : 4 (100.0%)
  -- Queued    : 0 (  0.0%)
  -- Started   : 4 (100.0%)
  ---- Running : 0 (  0.0%)
  ---- Done    : 0 (  0.0%)
  ---- Error   : 4 (100.0%)
  ---- Expired : 0 (  0.0%)


**> getErrorMessages(ids, reg = getDefaultRegistry())**
   job.id terminated error                                          message
1:      1       TRUE  TRUE Error in (function ()  : unused argument (x = 1)
2:      2       TRUE  TRUE Error in (function ()  : unused argument (x = 2)
3:      3       TRUE  TRUE Error in (function ()  : unused argument (x = 3)
4:      4       TRUE  TRUE Error in (function ()  : unused argument (x = 4)
@HenrikBengtsson
Copy link

HenrikBengtsson commented Jan 15, 2023

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.

@pulidofabs
Copy link
Author

@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 

@HenrikBengtsson
Copy link

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.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants