Problem constructiing nc file from workspace variables

Hi Jaime,
Based on the error message, it looks like your object "vars_to_be_saved" needs to be an ncvar object, which you can create by calling the ncvar_def() function. Have you tried something like obj <- ncvar_def(vars_to_be_saved)?

That said, I'm not sure that that's right because I can't run your code--you haven't included everything necessary for a minimal reproducible example. When I pasted your code into my R session, I couldn't run it because 1) you're missing a library() call to the package ncdf4, which is necessary for some of the functions you're running, 2) the variables times_used and lat_values (and others, etc.) are not defined in your code. You probably defined them elsewhere, but to make it easier for us to help you, could you include the code necessary for those objects in your example?

I hope that helps! Happy to look more into this if you can post fully reproducible code.