R/submit.R

# submitr: submit jobs to a grid engine easily
#
# Copyright (C) 2016 Simon Dirmeier
#
# This file is part of submitr.
#
# submitr is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# submitr is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with submitr. If not, see <http://www.gnu.org/licenses/>.

#' Submit a job to a computing cluster.
#'
#' @description Submit a job to a local or remote grid engine automatically.
#'
#' @author Simon Dirmeier, \email{simon.dirmeier@@bsse.ethz.ch}
#' @export
#'
#' @param job  the job you want to submit
#' @param gargs  the arguments for the grid engine, as vector of character
#' @param sargs  the arguments for the script, as vector of characters
#' @param host  the address of the host
#' @param ...  additional arguments
#'
#' @examples
#' \dontrun{
#'    # submit using a file
#'    submit(job="/Users/user/file.R", gargs=c("-W4:30", "-M10000", "-n8"))
#'
#'    # submit using a function
#'    f <- function() do.fancy.computation()
#'    submit(job=f, gargs=c("-W4:30", "-M10000", "-n8"))
#' }
submit <- function(job, gargs=NULL, sargs=NULL, host=NULL, ...)
  UseMethod("submit")

#' @noRd
#' @export
submit.character <- function(job, gargs=NULL, sargs=NULL, host=NULL, ...)
{
 .submit(job, gargs, sargs, host, ...)
}

#' @noRd
#' @export
submit.function <- function(job, gargs=NULL, sargs=NULL, host=NULL, ...)
{
  .submit(job, gargs, sargs, host, ...)
}

#' @noRd
.submit <- function(job, gargs=NULL, sargs=NULL, host=NULL, ...)
{
  .submit.job(build(job, gargs, sargs, host))
}

#' @noRd
#' @importFrom methods hasArg
.submit.job <- function(cmd, ...)
{
  if (methods::hasArg("intern"))
    intern <- system(cmd, intern=list(...)$intern)
  else
  {
    system(cmd)
    intern <- NA_character_
  }
  invisible(intern)
}
dirmeier/submitr documentation built on May 15, 2019, 8:51 a.m.