mschubert / clustermq

R package to send function calls as jobs on LSF, SGE, Slurm, PBS/Torque, or each via SSH
https://mschubert.github.io/clustermq/
Apache License 2.0
146 stars 27 forks source link

remove warning if exported data to foreach has more than one class #207

Closed quirinmanz closed 3 years ago

quirinmanz commented 3 years ago

Hi, first of all, thank you for the very helpful package! For me, the register_dopar_cmq function enables great compatibility with SLURM.

Still, this warning keeps coming up: In if (class(data$export[[i]]) == "function") environment(data$export[[i]]) = .GlobalEnv : the condition has length > 1 and only the first element will be used

It is not too bad but I would rather not use supressWarnings() all the time. My proposal is to replace if (class(data$export[[i]]) == "function") with if ("function" %in% class(data$export[[i]])).

I know it is a minor issue but maybe you can find time to incorporate it.

Best, Quirin Manz

mschubert commented 3 years ago

Thank you for pointing that out!

The correct way to check would be:

if (inherits(data$export[[i]], "function"))

ref: https://github.com/mschubert/clustermq/blob/master/R/foreach.r#L59-L60

mschubert commented 3 years ago

@quirinmanz I've got a follow-up question: What is your object that has more than one class including function? Is function the first or second class, and does stripping the environment (this will happen if function is the first class but not otherwise) cause any issues for you?

quirinmanz commented 3 years ago

Hi,

there are other objects with more than one class. They don't inherit from function but from e.g. [1] "matrix" "array". Therefore I didn't have any issues in terms of errors, only warnings that could be avoided.

Best, Quirin

mschubert commented 3 years ago

That makes sense, thanks!