diff --git a/nrrd/writer.py b/nrrd/writer.py
index b9187f7..24d78b0 100644
--- a/nrrd/writer.py
+++ b/nrrd/writer.py
@@ -180,6 +180,11 @@ def write(filename, data, header=None, detached_header=False, relative_data_path
     if 'encoding' not in header:
         header['encoding'] = 'gzip'
 
+    # If 'datafile' is specified, then we rename to 'data file'
+    # The standard seems to advocate for 'data file' OVER 'datafile'
+    if 'datafile' in header:
+        header['data file'] = header.pop('datafile')
+
     # A bit of magic in handling options here.
     # If *.nhdr filename provided, this overrides `detached_header=False`
     # If *.nrrd filename provided AND detached_header=True, separate header and data files written.
@@ -188,7 +193,9 @@ def write(filename, data, header=None, detached_header=False, relative_data_path
     if filename.endswith('.nhdr'):
         detached_header = True
 
-        if 'data file' not in header:
+        # TODO This will cause issues for relative data files because it will not save in the correct spot
+        data_filename = header.get('datafile', None)
+        if not data_filename:
             # Get the base filename without the extension
             base_filename = os.path.splitext(filename)[0]
 
@@ -207,9 +214,6 @@ def write(filename, data, header=None, detached_header=False, relative_data_path
 
             header['data file'] = os.path.basename(data_filename) \
                 if relative_data_path else os.path.abspath(data_filename)
-        else:
-            # TODO This will cause issues for relative data files because it will not save in the correct spot
-            data_filename = header['data file']
     elif filename.endswith('.nrrd') and detached_header:
         data_filename = filename
         header['data file'] = os.path.basename(data_filename) \

diff --git a/nrrd/tests/test_writing.py b/nrrd/tests/test_writing.py
index 535b75d..7c0c1c7 100644
--- a/nrrd/tests/test_writing.py
+++ b/nrrd/tests/test_writing.py
@@ -310,6 +310,26 @@ class TestWritingFunctions(object):
             self.assertTrue('space units: "mm" "cm" "in"' in lines)
             self.assertTrue('labels: "X" "Y" "f(log(X, 10), Y)"' in lines)
 
+    def test_write_detached_datafile_check(self):
+        output_filename = os.path.join(self.temp_write_dir, 'testfile_detached.nhdr')
+
+        nrrd.write(output_filename, self.data_input, {'datafile': 'testfile_detached.gz'}, detached_header=True,
+                   index_order=self.index_order)
+
+        # Read back the same file
+        data, header = nrrd.read(output_filename, index_order=self.index_order)
+        self.assertEqual(header['data file'], 'testfile_detached.raw.gz')
+
+    def test_write_detached_datafile_check2(self):
+        output_filename = os.path.join(self.temp_write_dir, 'testfile_detached.nhdr')
+
+        nrrd.write(output_filename, self.data_input, {'data file': 'testfile_detached.gz'}, detached_header=True,
+                   index_order=self.index_order)
+
+        # Read back the same file
+        data, header = nrrd.read(output_filename, index_order=self.index_order)
+        self.assertEqual(header['data file'], 'testfile_detached.raw.gz')
+
 
 class TestWritingFunctionsFortran(TestWritingFunctions, unittest.TestCase):
     index_order = 'F'

Need to account for both 'datafile' and 'data file'
We should account for both 'data file' and 'datafile' in [Ln 190](https://github.com/mhe/pynrrd/blob/master/nrrd/writer.py#L190) and [Ln 211](https://github.com/mhe/pynrrd/blob/master/nrrd/writer.py#L211) just like:
https://github.com/mhe/pynrrd/blob/master/nrrd/reader.py#L354
nrrd/tests/test_writing.py::TestWritingFunctionsFortran::test_write_detached_datafile_check nrrd/tests/test_writing.py::TestWritingFunctionsFortran::test_write_detached_datafile_check2 nrrd/tests/test_writing.py::TestWritingFunctionsC::test_write_detached_datafile_check nrrd/tests/test_writing.py::TestWritingFunctionsC::test_write_detached_datafile_check2
nrrd/tests/test_writing.py::TestWritingFunctionsFortran::test_invalid_custom_field nrrd/tests/test_writing.py::TestWritingFunctionsFortran::test_invalid_index_order nrrd/tests/test_writing.py::TestWritingFunctionsFortran::test_quoted_string_list_header nrrd/tests/test_writing.py::TestWritingFunctionsFortran::test_remove_endianness nrrd/tests/test_writing.py::TestWritingFunctionsFortran::test_unsupported_encoding nrrd/tests/test_writing.py::TestWritingFunctionsFortran::test_write_ascii_1d nrrd/tests/test_writing.py::TestWritingFunctionsFortran::test_write_ascii_2d nrrd/tests/test_writing.py::TestWritingFunctionsFortran::test_write_ascii_3d nrrd/tests/test_writing.py::TestWritingFunctionsFortran::test_write_bzip2 nrrd/tests/test_writing.py::TestWritingFunctionsFortran::test_write_bzip2_level1 nrrd/tests/test_writing.py::TestWritingFunctionsFortran::test_write_custom_fields_with_custom_field_map nrrd/tests/test_writing.py::TestWritingFunctionsFortran::test_write_custom_fields_without_custom_field_map nrrd/tests/test_writing.py::TestWritingFunctionsFortran::test_write_default_header nrrd/tests/test_writing.py::TestWritingFunctionsFortran::test_write_detached_ascii nrrd/tests/test_writing.py::TestWritingFunctionsFortran::test_write_detached_bz2 nrrd/tests/test_writing.py::TestWritingFunctionsFortran::test_write_detached_gz nrrd/tests/test_writing.py::TestWritingFunctionsFortran::test_write_detached_raw nrrd/tests/test_writing.py::TestWritingFunctionsFortran::test_write_detached_raw_as_nrrd nrrd/tests/test_writing.py::TestWritingFunctionsFortran::test_write_detached_raw_odd_extension nrrd/tests/test_writing.py::TestWritingFunctionsFortran::test_write_fake_encoding nrrd/tests/test_writing.py::TestWritingFunctionsFortran::test_write_gz nrrd/tests/test_writing.py::TestWritingFunctionsFortran::test_write_gz_level1 nrrd/tests/test_writing.py::TestWritingFunctionsFortran::test_write_raw nrrd/tests/test_writing.py::TestWritingFunctionsC::test_invalid_custom_field nrrd/tests/test_writing.py::TestWritingFunctionsC::test_invalid_index_order nrrd/tests/test_writing.py::TestWritingFunctionsC::test_quoted_string_list_header nrrd/tests/test_writing.py::TestWritingFunctionsC::test_remove_endianness nrrd/tests/test_writing.py::TestWritingFunctionsC::test_unsupported_encoding nrrd/tests/test_writing.py::TestWritingFunctionsC::test_write_ascii_1d nrrd/tests/test_writing.py::TestWritingFunctionsC::test_write_ascii_2d nrrd/tests/test_writing.py::TestWritingFunctionsC::test_write_ascii_3d nrrd/tests/test_writing.py::TestWritingFunctionsC::test_write_bzip2 nrrd/tests/test_writing.py::TestWritingFunctionsC::test_write_bzip2_level1 nrrd/tests/test_writing.py::TestWritingFunctionsC::test_write_custom_fields_with_custom_field_map nrrd/tests/test_writing.py::TestWritingFunctionsC::test_write_custom_fields_without_custom_field_map nrrd/tests/test_writing.py::TestWritingFunctionsC::test_write_default_header nrrd/tests/test_writing.py::TestWritingFunctionsC::test_write_detached_ascii nrrd/tests/test_writing.py::TestWritingFunctionsC::test_write_detached_bz2 nrrd/tests/test_writing.py::TestWritingFunctionsC::test_write_detached_gz nrrd/tests/test_writing.py::TestWritingFunctionsC::test_write_detached_raw nrrd/tests/test_writing.py::TestWritingFunctionsC::test_write_detached_raw_as_nrrd nrrd/tests/test_writing.py::TestWritingFunctionsC::test_write_detached_raw_odd_extension nrrd/tests/test_writing.py::TestWritingFunctionsC::test_write_fake_encoding nrrd/tests/test_writing.py::TestWritingFunctionsC::test_write_gz nrrd/tests/test_writing.py::TestWritingFunctionsC::test_write_gz_level1 nrrd/tests/test_writing.py::TestWritingFunctionsC::test_write_raw