attic/uploadMlrLearner.R

#' @title Upload an mlr learner to the server.
#'
#' @description This is a convenience function that generates an OpenML implementation (flow) as
#'   well as a sourcefile for your mlr learner. If the learner is not stored on the OpenML server
#'   yet, it is uploaded. The flow's implementation ID is returned in any case.
#'
#' @param lrn [\code{\link[mlr]{Learner}}]\cr
#'   The mlr learner.
#' @param hash [\code{character(1)}]\cr
#'   A session token returned by \code{\link{authenticateUser}}.
#' @param ... [\code{any}]\cr
#'   Further arguments that are passed to \code{\link{createOpenMLImplementationForMlrLearner}}.
#'   This could be an optional description of the learner or a name for the implementation. By
#'   default, these are autogenerated.
#' @param dir [\code{character(1)}]\cr
#'   A directory where to save the sourcefile. Default is the current working directory.
#' @param delete.source [\code{logical(1)}]\cr
#'   Should the autogenerated source file be removed at the end? Default is \code{TRUE}.
#' @template arg_showinfo
#'
#' @return [\code{integer(1)}]. Unique implementation ID.
#' @seealso \code{\link[mlr]{makeLearner}}, \code{\link{authenticateUser}},
#'   \code{\link{uploadOpenMLImplementation}}
#' @export
uploadMlrLearner = function(lrn, hash, dir = getwd(), delete.source = TRUE, ...,
  show.info = getOpenMLOption("show.info")) {

  assertClass(lrn, "Learner")
  assertString(hash)
  assertDirectoryExists(dir)
  assertFlag(delete.source)
  assertFlag(show.info)

  flow = createOpenMLImplementationForMlrLearner(lrn, ...)
  sourcefile = generateSourcefileForMlrLearner(lrn, dir)
  flow.id = uploadOpenMLImplementation(flow, sourcefile = sourcefile, session.hash = hash,
    delete.source.binary = delete.source, show.info = show.info)
  return(flow.id)
}
openml/openml-r documentation built on Oct. 21, 2022, 2:16 a.m.