<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def close(self, save_to=None):
 # type: (Optional[str]) -> None """Close the Research Object, optionally saving to specified folder. Closing will remove any temporary files used by this research object. After calling this method, this ResearchObject instance can no longer be used, except for no-op calls to .close(). The 'saveTo' folder should not exist - if it does, it will be deleted. It is safe to call this function multiple times without the 'saveTo' argument, e.g. within a try..finally block to ensure the temporary files of this Research Object are removed. """

        if save_to is None:
            if not self.closed:
                _logger.debug(u"[provenance] Deleting temporary %s", self.folder)
                shutil.rmtree(self.folder, ignore_errors=True)
        else:
            save_to = os.path.abspath(save_to)
            _logger.info(u"[provenance] Finalizing Research Object")
            self._finalize()  # write manifest etc.
            # TODO: Write as archive (.zip or .tar) based on extension?

            if os.path.isdir(save_to):
                _logger.info(u"[provenance] Deleting existing %s", save_to)
                shutil.rmtree(save_to)
            shutil.move(self.folder, save_to)
            _logger.info(u"[provenance] Research Object saved to %s", save_to)
            self.folder = save_to
        self.closed = True