You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using curl() following usage I see in the official examples, like so:
x<- readLines(curl(SOME_URL)
but inside a loop over SOME_URL. I then got lots of warnings about closing unused connections. Am I supposed to be more careful and always store then close the connection? Does it even matter?
It is good practice to close() the connection. If you forget to, the garbage collector closes the connection when it cleans up the con object (with a warning). This holds for all connection types by the way (url(), file(), socket() etc), not just curl(). See also this topic.
Within a function, it is common to use the on.exit finalizer for housekeeping. The benefit of on.exit is that it also runs if the function exits with an error, so you can be sure the connection always gets closed.
Thanks that is helpful. Yes I had already decided to properly close the connections because the sheer volume of warnings was alarming. Good tip re: on.exit().
I am using
curl()
following usage I see in the official examples, like so:but inside a loop over
SOME_URL
. I then got lots of warnings about closing unused connections. Am I supposed to be more careful and always store then close the connection? Does it even matter?The text was updated successfully, but these errors were encountered: