JGCRI/gcamdata

driver_drake(xmldir) requires trailing slash

rjplevin opened this issue · 1 comments

In file gcamdata/R/driver.R, without a trailing slash on the xmldir argument, e.g., driver_drake(xmldir="my_xml_dir"), filenames are incorrect, e.g., "my_xml_dirfoo.xml" rather than "my_xml_dir/foo.xml".

I didn't bother with a pull request for this minor change. In driver.R, change the block that twice calls paste0(xmldir, po_xml) to use file.path() instead and save the result, then use this in the two places the paste0() had been used:

      # to actually run the XML conversion and write out the gcam inputs
      po_xml <- subset(chunkoutputs, name == chunk & to_xml)$output
      if(write_xml && length(po_xml) > 0) {
        # Add the xmldir to the XML output name and include those in the
        # target list.
        po_xml_path = file.path(xmldir, po_xml)        # HERE
        target <- c(target, make.names(po_xml_path))   # HERE
        # Generate the command to run the XML conversion:
        # `xml/out1.xml <- run_xml_conversion(set_xml_file_helper(out1.xml, file_out("xml/out1.xml")))`
        # Note, the `file_out()` wrapper notifies drake the XML file is an output
        # of this plan and allows it to know to re-produce missing/altered XML files
        command <- c(command, paste0("run_xml_conversion(set_xml_file_helper(", po_xml, "[[1]], 
             file_out('", po_xml_path, "')))"))        #HERE
      }

Addressed in 9c30009, thanks @rjplevin!