Skip to content

Commit

Permalink
Added 'schema' function parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
vruusmann committed Nov 10, 2024
1 parent 4fb97f6 commit 7c8e1a8
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions R/r2pmml.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#'
#' @param x An R model object.
#' @param file A filesystem path to the result file.
#' @param schema The PMML schema version for the PMML document.
#' @param converter The name of a custom JPMML-R converter class.
#' @param converter_classpath A list of filesystem paths to library JAR files that provide and support the custom JPMML-R converter class.
#' @param verbose A flag controlling the verbosity of the conversion process.
Expand Down Expand Up @@ -31,15 +32,15 @@
#' regPmmlFile = file.path(tempdir(), "Housing-LM.pmml")
#' r2pmml(housing.glm, regPmmlFile, converter = "org.jpmml.rexp.LMConverter")
#' }
r2pmml = function(x, file, converter = NULL, converter_classpath = NULL, verbose = FALSE, ...){
r2pmml = function(x, file, schema = NULL, converter = NULL, converter_classpath = NULL, verbose = FALSE, ...){
x = decorate(x, ...)

tempfile = tempfile("r2pmml-", fileext = ".rds")

main = function(){
saveRDS(x, tempfile, version = 2)

.convert(tempfile, file, converter, converter_classpath, verbose)
.convert(rds_input = tempfile, pmml_output = file, pmml_schema = schema, converter = converter, converter_classpath = converter_classpath, verbose = verbose)
}

tryCatch({ main() }, finally = { unlink(tempfile) })
Expand All @@ -59,7 +60,7 @@ r2pmml = function(x, file, converter = NULL, converter_classpath = NULL, verbose
return(paste(jar_files, collapse = .Platform$path.sep))
}

.convert = function(rds_input, pmml_output, converter = NULL, converter_classpath = NULL, verbose = FALSE){
.convert = function(rds_input, pmml_output, pmml_schema, converter, converter_classpath, verbose){
classpath = .classpath()

if(!is.null(converter) && !is.null(converter_classpath)){
Expand All @@ -73,6 +74,10 @@ r2pmml = function(x, file, converter = NULL, converter_classpath = NULL, verbose

args = c("-cp", shQuote(classpath), "com.r2pmml.Main", "--rds-input", shQuote(rds_input), "--pmml-output", shQuote(pmml_output))

if(!is.null(pmml_schema)){
args = c(args, "--pmml-schema", pmml_schema)
}

if(!is.null(converter)){
args = c(args, "--converter", converter)
}
Expand Down

0 comments on commit 7c8e1a8

Please sign in to comment.