code: def InGivenDirectory(path=None):
      """Change directory to given directory for duration of ``with`` block
  
      Useful when you want to use `InTemporaryDirectory` for the final test, but
      you are still debugging.  For example, you may want to do this in the end:
  
      >>> with InTemporaryDirectory() as tmpdir:
      ...     # do something complicated which might break
      ...     pass
  
      But indeed the complicated thing does break, and meanwhile the
      ``InTemporaryDirectory`` context manager wiped out the directory with the
      temporary files that you wanted for debugging.  So, while debugging, you
      replace with something like:
  
      >>> with InGivenDirectory() as tmpdir: # Use working directory by default
      ...     # do something complicated which might break
      ...     pass
  
      You can then look at the temporary file outputs to debug what is happening,
      fix, and finally replace ``InGivenDirectory`` with ``InTemporaryDirectory``
      again.
  
      Parameters
      ----------
      path : None or str, optional
          path to change directory to, for duration of ``with`` block.
          Defaults to ``os.getcwd()`` if None
      """
      if path is None:
          path = os.getcwd()
      os.makedirs(path, exist_ok=True)
      with _chdir(path):
          yield os.path.abspath(path)
  
file_path: nibabel/nibabel/tmpdirs.py
imports: import os
  import tempfile
  from contextlib import contextmanager
  from .deprecated import deprecate_with_version
label_desc: Use image node_id 2 for calling a global function with example usage: InGivenDirectory(path) without return types