## EXPORTS FROM R STUDIO TO REMOTE DISK (ON R BOX)

## Wrapping in braces so that a failure halts execution
if (TRUE) {
  ext = ".Rda"
  ExportJustLastQuery <- TRUE

  inds <- seq_along(QRES)
  if(ExportJustLastQuery) {
    if (exists("q.nm") && all(q.nm %in% names(QRES)))
      inds <- q.nm
    else 
      inds <- length(QRES)
  }


  QRES.Export <- QRES[inds]

  ## QRES.Export might be a sinle element list. We want the DT inside. 
  while (length(QRES.Export) == 1 && is.null(dim(QRES.Export)))
     QRES.Export <- QRES.Export[[1]]

  ## How to Save
  ext <- ifelse(grepl("^\\.", ext), ext, paste0(".", ext))  
  saveFUNC <- {if (toupper(ext)==".RDA")
                 save
               else if (toupper(ext)==".RDS")
                 saveRDS
               else 
                  stop("Auto Export not setup for file type '", ext, "'")
              }


  file     <- as.path(dataDir, "QRESExport", ext=ext, expand=FALSE)
  saveFile <- saveFUNC(QRES.Export, file=file, compress=TRUE)

  ## Output
  {
    if(.Pfm=="Darwin")
      clipCopy(dirname(file))
    else
      reproduce(file)
  }

  cat("\n\n", dirname(file), "\n\n", sep="")

}