R/build.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/>.

#' @noRd
build <- function(job, gargs=NULL, sargs=NULL, host=NULL) UseMethod("build")

#' @noRd
build.character <- function(job, gargs=NULL, sargs=NULL, host=NULL)
{
  if (!file.exists(job)) stop("File not found!")
  job.cmd <- paste("Rscript", job)
  .build.job(job.cmd, gargs, sargs, host)
}

#' @noRd
build.function <- function(job, gargs=NULL, sargs=NULL, host=NULL)
{
 stop("not yet implemented")
}

#' @noRd
.build.job <- function(job, gargs=NULL, sargs=NULL, host=NULL)
{
  if (is.null(host)) host <- "local"
  else if (host != "local")
    stop("Currently only local jobs allowed")
  if (missing(job)) stop("Please provide a job!")
  if (!is.null(gargs) & (!is.character(gargs) | !is.vector(gargs)))
    stop("gargs has to be a vector of strings or null!")
  if (!is.null(sargs) & (!is.character(sargs) | !is.vector(sargs)))
    stop("sargs has to be a vector of strings or null!")
  cmd <- "bsub"
  if (!is.null(gargs)) cmd <- paste(cmd, paste(gargs, collapse=" "))
  cmd <- paste(cmd, job)
  if (!is.null(sargs)) cmd <- paste(cmd, paste(sargs, collapse=" "))
  invisible(cmd)
}
dirmeier/submitr documentation built on May 15, 2019, 8:51 a.m.