What is the 'correct' way to completely end an RSelenium session (including all of its constituent parts) from R?
Background
When using RSelenium for browser automation, there are many technologies interacting, and it can sometimes create weird bugs where everything in the R session is cleaned up, but some underlying chrome / chromedriver / phantom.js / selenium / (other?) processes haven't ended. This can cause problems when future RSelenium sessions are attempted.
What I know so far
The RSelenium docs, show two ways to close some parts of the overall process:
Method 1
close
the browser, and then stop
the server:
# start a chrome browser
rD <- rsDriver()
remDr <- rD[["client"]]
remDr$navigate("http://www.google.com/ncr")
remDr$navigate("http://www.bbc.com")
remDr$close()
# stop the selenium server
rD[["server"]]$stop()
Method 2
Remove the rD
(remote driver) object, and call for garbage collection:
# if user forgets to stop server it will be garbage collected.
rD <- rsDriver()
rm(rD)
gc(rD)
Another thing I discovered (from a similar question about python)is rD$client$quit()
Question
With this assortment of methods available, precisely what should be done (i.e. is best practice) to be completely sure that an RSelenium session (and every process connected to that session - e.g. chrome/chromedriver etc) has completely closed, so it cannot possibly interfere with other RSelenium sessions?