| Title: | The sasctl package enables easy communication between the SAS Viya platform APIs and the R runtime |
|---|---|
| Description: | The sasctl package enables easy communication between the SAS Viya platform APIs and the R runtime. |
| Authors: | Eduardo Hellas |
| Maintainer: | Eduardo Hellas <[email protected]> |
| License: | file LICENSE |
| Version: | 0.8.1.9000 |
| Built: | 2026-06-02 08:56:52 UTC |
| Source: | https://github.com/sassoftware/r-sasctl |
Add model content
add_model_content(session, file, model, role = NULL, exact = TRUE, ...)add_model_content(session, file, model, role = NULL, exact = TRUE, ...)
session |
viya_connection object, obtained through |
file |
path to file |
model |
|
role |
file role, such as "scoreResource" and "score" |
exact |
the filter query should use "contains" for partial match or "eq" for exact match |
... |
pass to |
a MMcontent class list
## Not run: my_model <- get_model(sess, "MyModel") myContent <- add_model_content(sess, file = "my_fancy_file.R", model = my_model) myContent ## End(Not run)## Not run: my_model <- get_model(sess, "MyModel") myContent <- add_model_content(sess, file = "my_fancy_file.R", model = my_model) myContent ## End(Not run)
Add model version
add_model_version(session, model, exact = TRUE, minor = FALSE, ...)add_model_version(session, model, exact = TRUE, minor = FALSE, ...)
session |
viya_connection object, obtained through |
model |
|
exact |
the filter query should use "contains" for partial match or "eq" for exact match |
minor |
if |
... |
additional parameters to be passed to |
A data.frame with the list of projects
## Not run: my_model <- get_model(sess, model = "MyModel") nvmodel <- add_model_version(sess, my_model) nvmodel ## End(Not run)## Not run: my_model <- get_model(sess, model = "MyModel") nvmodel <- add_model_version(sess, my_model) nvmodel ## End(Not run)
Calculates fit statistics from user data and writes it to a JSON file for importing into the common model repository.
calculateFitStat( targetName, targetPredicted, validadedf = NULL, traindf = NULL, testdf = NULL, type = "binary", targetEventValue = 1, path = "./", label.ordering = c(0, 1), cutoff = 0.5, noFile = FALSE )calculateFitStat( targetName, targetPredicted, validadedf = NULL, traindf = NULL, testdf = NULL, type = "binary", targetEventValue = 1, path = "./", label.ordering = c(0, 1), cutoff = 0.5, noFile = FALSE )
targetName |
target variable column name (actuals) |
targetPredicted |
target variable column name. When |
validadedf |
|
traindf |
|
testdf |
|
type |
|
targetEventValue |
if |
path |
default to current work dir |
label.ordering |
The default ordering (cf.details) of the classes can be changed by supplying a vector containing the negative and the positive class label. See |
cutoff |
cutoff to be used for calculation of miss classification for binary |
noFile |
if you don't want to write to a file, only the output |
list that reflects the 'dmcas_fitstat.json'
'dmcas_fitstat.json' file written to path
df <- data.frame(label = sample(c(1,0), 6000, replace = TRUE), prob = runif(6000), partition = rep_len(1:3, 6000)) calculateFitStat(targetName = "label", targetPredicted = "prob", df[df$partition == 1, ], df[df$partition == 2, ], df[df$partition == 3, ], noFile = TRUE) df2 <- data.frame(actual = rnorm(6000, 1000, 100), predicted = rnorm(6000, 1000, 100), partition = rep_len(1:3, 6000)) calculateFitStat(targetName = "actual", targetPredicted = "predicted", df2[df2$partition == 1, ], df2[df2$partition == 2, ], df2[df2$partition == 3, ], type = "interval", noFile = TRUE)df <- data.frame(label = sample(c(1,0), 6000, replace = TRUE), prob = runif(6000), partition = rep_len(1:3, 6000)) calculateFitStat(targetName = "label", targetPredicted = "prob", df[df$partition == 1, ], df[df$partition == 2, ], df[df$partition == 3, ], noFile = TRUE) df2 <- data.frame(actual = rnorm(6000, 1000, 100), predicted = rnorm(6000, 1000, 100), partition = rep_len(1:3, 6000)) calculateFitStat(targetName = "actual", targetPredicted = "predicted", df2[df2$partition == 1, ], df2[df2$partition == 2, ], df2[df2$partition == 3, ], type = "interval", noFile = TRUE)
Calculates the lift curves from user data and writes to a JSON file for importing into the common model repository. Binary response only.
calculateLiftStat( targetName, targetPredicted, validadedf = NULL, traindf = NULL, testdf = NULL, targetEventValue = 1, path = "./", noFile = FALSE )calculateLiftStat( targetName, targetPredicted, validadedf = NULL, traindf = NULL, testdf = NULL, targetEventValue = 1, path = "./", noFile = FALSE )
targetName |
target variable column name (actuals) |
targetPredicted |
target variable predicted probability column name |
validadedf |
|
traindf |
|
testdf |
|
targetEventValue |
target class name for ROC reference, if model is nominal, all other class will be counted as "not target" |
path |
default to current work dir |
noFile |
if you don't want to write to a file, only the output |
list that reflects the 'dmcas_roc.json'
'dmcas_roc.json' file written to path
df <- data.frame(label = sample(c(1,0), 6000, replace = TRUE), prob = runif(6000), partition = rep_len(1:3, 6000)) ## partition will be ignored since it is 3rd column calculateLiftStat(targetName = "label", targetPredicted = "prob", df[df$partition == 1, ], df[df$partition == 2, ], df[df$partition == 3, ], noFile = TRUE)df <- data.frame(label = sample(c(1,0), 6000, replace = TRUE), prob = runif(6000), partition = rep_len(1:3, 6000)) ## partition will be ignored since it is 3rd column calculateLiftStat(targetName = "label", targetPredicted = "prob", df[df$partition == 1, ], df[df$partition == 2, ], df[df$partition == 3, ], noFile = TRUE)
Calculates the ROC curve from user data and writes it to a JSON file for importing into the common model repository. Binary response only.
calculateROCStat( targetName, targetPredicted, validadedf = NULL, traindf = NULL, testdf = NULL, targetEventValue = 1, label.ordering = c(0, 1), path = "./", noFile = FALSE )calculateROCStat( targetName, targetPredicted, validadedf = NULL, traindf = NULL, testdf = NULL, targetEventValue = 1, label.ordering = c(0, 1), path = "./", noFile = FALSE )
targetName |
target variable column name (actuals) |
targetPredicted |
target variable predicted probability column name |
validadedf |
|
traindf |
|
testdf |
|
targetEventValue |
target class name for ROC reference, if model is nominal, all other class will be counted as "not target" |
label.ordering |
The default ordering (cf.details) of the classes can be changed by supplying a vector containing the negative and the positive class label. See |
path |
default to current work dir |
noFile |
if you don't want to write to a file, only the output |
list that reflects the 'dmcas_roc.json'
'dmcas_roc.json' file written to path
df <- data.frame(label = sample(c(1,0), 6000, replace = TRUE), prob = runif(6000), partition = rep_len(1:3, 6000)) ## partition will be ignored since it is 3rd column calculateROCStat(targetName = "label", targetPredicted = "prob", df[df$partition == 1, ], df[df$partition == 2, ], df[df$partition == 3, ], noFile = TRUE)df <- data.frame(label = sample(c(1,0), 6000, replace = TRUE), prob = runif(6000), partition = rep_len(1:3, 6000)) ## partition will be ignored since it is 3rd column calculateROCStat(targetName = "label", targetPredicted = "prob", df[df$partition == 1, ], df[df$partition == 2, ], df[df$partition == 3, ], noFile = TRUE)
EXPERIMENTAL STATE - MAY NOT WORK AS INTENDED
Score code will only be generated successfully for supported models.
Other models and frameworks will be added in due time.
Use create_scoreSample() to get a structure sample
Disclaimer: The score code that is generated is designed to be a working template for an R model, but is not guaranteed to work out of the box for scoring, publishing, or validating the model.
codegen( model, path, rds, libs, inputs, output_as_df = TRUE, add_target_name = TRUE, ... ) ## S3 method for class 'lm' codegen( model, path = "scoreCode.R", rds = "model.rds", libs = c(), inputs = NULL, output_as_df = TRUE, add_target_name = TRUE, ... ) ## S3 method for class 'glm' codegen( model, path = "scoreCode.R", rds = "model.rds", libs = c(), inputs = NULL, output_as_df = TRUE, add_target_name = TRUE, cutoff = 0.5, ... ) ## S3 method for class 'workflow' codegen( model, path = "scoreCode.R", rds = "model.rds", libs = c(), inputs = NULL, output_as_df = TRUE, add_target_name = TRUE, referenceLevel = NULL, ... )codegen( model, path, rds, libs, inputs, output_as_df = TRUE, add_target_name = TRUE, ... ) ## S3 method for class 'lm' codegen( model, path = "scoreCode.R", rds = "model.rds", libs = c(), inputs = NULL, output_as_df = TRUE, add_target_name = TRUE, ... ) ## S3 method for class 'glm' codegen( model, path = "scoreCode.R", rds = "model.rds", libs = c(), inputs = NULL, output_as_df = TRUE, add_target_name = TRUE, cutoff = 0.5, ... ) ## S3 method for class 'workflow' codegen( model, path = "scoreCode.R", rds = "model.rds", libs = c(), inputs = NULL, output_as_df = TRUE, add_target_name = TRUE, referenceLevel = NULL, ... )
model |
model object (lm, glm, tidymodels workflow, ...) |
path |
file name and path to write |
rds |
.rds file name to be called |
libs |
vector of libraries to be added to the code. Some may be guessed from the type. |
inputs |
define inputs as the passed vector instead of guessed |
output_as_df |
logical; when |
add_target_name |
logical; when |
... |
to be passes to individual code generators |
cutoff |
classification probability cutoff |
referenceLevel |
reference level for a factor target value |
a code string
codegen(lm): Code generator for lm class models
codegen(glm): generator for glm class models, specifically logistic regression
codegen(workflow): generator for tidymodels workflow class models
## Not run: # SAS viya doesn't play nice with variables with '.' in the names colnames(iris) <- gsub("\\.", "_", colnames(iris)) # simple regression model <- lm(Petal.Length ~ ., data = iris) codegen(model) ## End(Not run)## Not run: # SAS viya doesn't play nice with variables with '.' in the names colnames(iris) <- gsub("\\.", "_", colnames(iris)) # simple regression model <- lm(Petal.Length ~ ., data = iris) codegen(model) ## End(Not run)
Converts a pmml header text file from 4.x version to 4.2.
convert_to_pmml42(file_in, file_out)convert_to_pmml42(file_in, file_out)
file_in |
path to a .pmml file |
file_out |
path to write the converted .pmml file |
NOTE: As of SAS Viya 2025.9, it is no longer required to convert PMML 4.x to 4.2
nothing
## Not run: hmeq <- read.csv("https://support.sas.com/documentation/onlinedoc/viya/exampledatasets/hmeq.csv", stringsAsFactors = TRUE) hmeq[hmeq == ""] <- NA hmeq <- na.omit(hmeq) hmeq$BAD <- as.factor(hmeq$BAD) model1 <- glm(BAD ~ ., hmeq, family = binomial("logit")) summary(model1) XML::saveXML(pmml::pmml(model1, model.name = "General_Regression_Model", app.name = "Rattle/PMML", description = "Linear Regression Model"), "dev/my_model44.pmml") convert_to_pmml42("my_model.pmml", "my_model_conv.pmml") ## End(Not run)## Not run: hmeq <- read.csv("https://support.sas.com/documentation/onlinedoc/viya/exampledatasets/hmeq.csv", stringsAsFactors = TRUE) hmeq[hmeq == ""] <- NA hmeq <- na.omit(hmeq) hmeq$BAD <- as.factor(hmeq$BAD) model1 <- glm(BAD ~ ., hmeq, family = binomial("logit")) summary(model1) XML::saveXML(pmml::pmml(model1, model.name = "General_Regression_Model", app.name = "Rattle/PMML", description = "Linear Regression Model"), "dev/my_model44.pmml") convert_to_pmml42("my_model.pmml", "my_model_conv.pmml") ## End(Not run)
Returns a sasctl MMproject object from Model Manager
create_project( session, name, description = NULL, model_function = NULL, input_vars = NULL, output_vars = NULL, image = NULL, additional_parameters = NULL, ... )create_project( session, name, description = NULL, model_function = NULL, input_vars = NULL, output_vars = NULL, image = NULL, additional_parameters = NULL, ... )
session |
viya_connection object, obtained through |
name |
The name of the project |
description |
The description of the project. |
model_function |
The project model function of the project. Valid values: analytical, classification, cluster, forecasting, prediction, Text categorization, Text extraction, Text sentiment, Text topics, transformation |
input_vars |
|
output_vars |
|
image |
Image URI to be used as project cover |
additional_parameters |
|
... |
additional parameters to be passed to |
A data.frame with the list of projects
## Not run: new_project <- create_project(sess, name = "ModelProj", description = "My fancy project", model_function = "classification") new_project ## End(Not run)## Not run: new_project <- create_project(sess, name = "ModelProj", description = "My fancy project", model_function = "classification") new_project ## End(Not run)
Creates an R file in the path with an example. The file structure are as follows: For official documentation go to Scoring R models documentation
create_scoreSample(path = ".", openFile = TRUE)create_scoreSample(path = ".", openFile = TRUE)
path |
path to create file, default current working directory |
openFile |
automatically open file for editing |
The file should start with a function with all the input variables which SAS Viya will use to insert data
Then it is followed by a comment line #output: outvar1, outvar2 which is case sensitive and must follow that
structure so SAS can receive the function output properly.
If you are using a previously created model, it should be read, we recommend .rda format, but could be
a pmml file or other format that suits you, just make sure that it is properly classified as scoring resource
when using inside SAS Model Manager.
You then can use any logic to score the model or just an arbitrary R code.
To pass the information back to SAS it must return a list of the variables defined at the beginning of the script.
nothing
## Not run: create_scoreSample() ## End(Not run) # SAS does not expect the following outputs necessarily # but if you follow that structure it will play nice with other SAS Features # EM_CLASSIFICATION - Predicted for target # EM_EVENTPROBABILITY - Probability target=1 # EM_PROBABILITY - Probability of Classification # I_<<target>> - eg.: I_BAD - Into: BAD # I_<<target>><<level>> eg.: I_BAD1 - predicted level## Not run: create_scoreSample() ## End(Not run) # SAS does not expect the following outputs necessarily # but if you follow that structure it will play nice with other SAS Features # EM_CLASSIFICATION - Predicted for target # EM_EVENTPROBABILITY - Probability target=1 # EM_PROBABILITY - Probability of Classification # I_<<target>> - eg.: I_BAD - Into: BAD # I_<<target>><<level>> eg.: I_BAD1 - predicted level
Delete a client
delete_client(session, client)delete_client(session, client)
session |
viya_connection object, obtained through |
client |
|
A httr::response object.
## Not run: new_client <- register_client(sess, 'my_client', 'my_s3cr3t!') delete_client(sess, "my_client") ## End(Not run)## Not run: new_client <- register_client(sess, 'my_client', 'my_s3cr3t!') delete_client(sess, "my_client") ## End(Not run)
Delete a module/model published on MAS.
delete_masmodule(session, module, exact = TRUE)delete_masmodule(session, module, exact = TRUE)
session |
viya_connection object, obtained through |
module |
|
exact |
the filter query should use "contains" for partial match or "eq" for exact match |
A httr::response object.
## Not run: deleted_module <- delete_masmodule(sess, module = "ModuleName") deleted_module ## End(Not run)## Not run: deleted_module <- delete_masmodule(sess, module = "ModuleName") deleted_module ## End(Not run)
delete a model from Model Manager
delete_model(session, model, exact = TRUE)delete_model(session, model, exact = TRUE)
session |
viya_connection object, obtained through |
model |
|
exact |
the filter query should use "contains" for partial match or "eq" for exact match |
A httr::response object.
## Not run: my_model <- get_model(sess, "MyModel") delete_model(sess, my_model) ## End(Not run)## Not run: my_model <- get_model(sess, "MyModel") delete_model(sess, my_model) ## End(Not run)
delete model from Manager
delete_model_contents(session, model, content, exact = TRUE)delete_model_contents(session, model, content, exact = TRUE)
session |
viya_connection object, obtained through |
model |
|
content |
|
exact |
the filter query should use "contains" for partial match or "eq" for exact match |
A httr::response object.
## Not run: my_model <- get_model(sess, "MyModel") delete_model_contents(sess, my_model) ## End(Not run)## Not run: my_model <- get_model(sess, "MyModel") delete_model_contents(sess, my_model) ## End(Not run)
Delete a project and all associated models and resources
delete_project(session, project, exact = TRUE)delete_project(session, project, exact = TRUE)
session |
viya_connection object, obtained through |
project |
|
exact |
the filter query should use "contains" for partial match or "eq" for exact match |
A httr::response object.
## Not run: new_project <- create_project(sess, name = "ModelProj", description = "My fancy project", model_function = "classification") delete_project(sess, new_project) ## End(Not run)## Not run: new_project <- create_project(sess, name = "ModelProj", description = "My fancy project", model_function = "classification") delete_project(sess, new_project) ## End(Not run)
Calculates and writes fit statistics, roc and lift for binary and fit statistics for interval.
diagnosticsJson( targetName, targetPredicted, validadedf = NULL, traindf = NULL, testdf = NULL, type = "binary", targetEventValue = 1, cutoff = 0.5, label.ordering = c(0, 1), path = "./", noFile = FALSE )diagnosticsJson( targetName, targetPredicted, validadedf = NULL, traindf = NULL, testdf = NULL, type = "binary", targetEventValue = 1, cutoff = 0.5, label.ordering = c(0, 1), path = "./", noFile = FALSE )
targetName |
target variable name (actuals) |
targetPredicted |
target variable probability column name |
validadedf |
|
traindf |
|
testdf |
|
type |
|
targetEventValue |
if |
cutoff |
cutoff to be used for calculation of miss classification for binary |
label.ordering |
The default ordering (cf.details) of the classes can be changed by supplying a vector containing the negative and the positive class label. See |
path |
default to current work dir |
noFile |
if you don't want to write to a file, only the output |
list of lists that reflects the 'dmcas_fitstat.json', 'dmcas_roc.json' and 'dmcas_lift.json'
'dmcas_fitstat.json', 'dmcas_roc.json' and 'dmcas_lift.json' files written to path
All parameters are passed to calculateLiftStat(), calculateLiftStat() and calculateLiftStat() for matching parameters.
df <- data.frame(label = sample(c(1,0), 6000, replace = TRUE), prob = runif(6000), partition = rep_len(1:3, 6000)) ## partition will be ignored since it is 3rd column diagnosticsJson(df[df$partition == 1, ], df[df$partition == 2, ], df[df$partition == 3, ], targetName = "label", targetPredicted = "prob", noFile = TRUE )df <- data.frame(label = sample(c(1,0), 6000, replace = TRUE), prob = runif(6000), partition = rep_len(1:3, 6000)) ## partition will be ignored since it is 3rd column diagnosticsJson(df[df$partition == 1, ], df[df$partition == 2, ], df[df$partition == 3, ], targetName = "label", targetPredicted = "prob", noFile = TRUE )
Viya MAS requires a very specific json format which is the goal of this function to create
format_data_json(df, scr = FALSE, scr_batch = FALSE, metadata_columns = NULL)format_data_json(df, scr = FALSE, scr_batch = FALSE, metadata_columns = NULL)
df |
data frame to be transformed in JSON format rows |
scr |
boolean, if |
scr_batch |
boolean, if |
metadata_columns |
columns names to be used as metadata. If scr is set to |
a vector of JSON strings or a single json string when scr_batch is set to TRUE
json_output <- format_data_json(mtcars) json_output json_output <- format_data_json(mtcars, scr = TRUE) json_output json_output <- format_data_json(mtcars, scr_batch = TRUE) jsonlite::prettify(json_output)json_output <- format_data_json(mtcars) json_output json_output <- format_data_json(mtcars, scr = TRUE) json_output json_output <- format_data_json(mtcars, scr_batch = TRUE) jsonlite::prettify(json_output)
Returns a single sasctl MMclient from SAS Model Manager
get_client(session, client, ...)get_client(session, client, ...)
session |
viya_connection object, obtained through |
client |
|
... |
additional parameters to be passed to |
list with sasctl attribute
## Not run: my_client <- get_client(sess, client = ModelProj) my_client ## End(Not run)## Not run: my_client <- get_client(sess, client = ModelProj) my_client ## End(Not run)
Returns a publishing destination
get_destination(session, name, ...)get_destination(session, name, ...)
session |
viya_connection object, obtained through |
name |
destination name |
... |
additional parameters to be passed to |
A data.frame with the list of projects
## Not run: destination <- get_destination(sess, 'maslocal') destination ## End(Not run)## Not run: destination <- get_destination(sess, 'maslocal') destination ## End(Not run)
Returns a single module MASmodule object with module and steps information
get_masmodule(session, module, id = NULL, exact = TRUE, ...)get_masmodule(session, module, id = NULL, exact = TRUE, ...)
session |
viya_connection object, obtained through |
module |
|
id |
module id, will replace |
exact |
the filter query should use "contains" for partial match or "eq" for exact match |
... |
additional parameters to be passed to |
list with sasctl attribute
## Not run: my_module <- get_masmodule(sess, model = "name") my_module ## End(Not run)## Not run: my_module <- get_masmodule(sess, model = "name") my_module ## End(Not run)
Returns a single sasctl MMmodel from SAS Model Manager
get_model(session, model, exact = TRUE, ...)get_model(session, model, exact = TRUE, ...)
session |
viya_connection object, obtained through |
model |
|
exact |
the filter query should use "contains" for partial match or "eq" for exact match |
... |
additional parameters to be passed to |
list with sasctl attribute
## Not run: my_model <- get_model(sess, model = MMmodel) my_model ## End(Not run)## Not run: my_model <- get_model(sess, model = MMmodel) my_model ## End(Not run)
Returns a single sasctl MMProject from SAS Model Manager
get_project(session, project, exact = TRUE, ...)get_project(session, project, exact = TRUE, ...)
session |
viya_connection object, obtained through |
project |
|
exact |
the filter query should use "contains" for partial match or "eq" for exact match |
... |
additional parameters to be passed to |
list with sasctl attribute
## Not run: my_project <- get_project(sess, project = ModelProj) my_project ## End(Not run)## Not run: my_project <- get_project(sess, project = ModelProj) my_project ## End(Not run)
Returns a list of clients
list_clients( session, start = 1, count = 100, filter = NULL, exact = FALSE, ... )list_clients( session, start = 1, count = 100, filter = NULL, exact = FALSE, ... )
session |
viya_connection object, obtained through |
start |
the index of the first project to return |
count |
The number of results per page. The default is 100. |
filter |
character string of client_id name to be filtered |
exact |
boolean, If the filter query should use "co" for partial match or "eq" for exact match |
... |
additional parameters to be passed to |
A data.frame of sasclientList class with the list of clients
## Not run: clients <- list_clients(sess, filter = list(createdBy = "creatorUser", name = "projectName")) clients ## End(Not run)## Not run: clients <- list_clients(sess, filter = list(createdBy = "creatorUser", name = "projectName")) clients ## End(Not run)
Returns a list of Publish Destinations
list_destinations( session, start = 0, limit = 10, filters = list(), exact = FALSE, ... )list_destinations( session, start = 0, limit = 10, filters = list(), exact = FALSE, ... )
session |
viya_connection object, obtained through |
start |
the index of the first project to return |
limit |
maximum number of projects to return |
filters |
list of of names vectors for filter parameters (createdBy, modifiedBy, name). By default it will use the |
exact |
boolean, If the filter query should use "contains" for partial match or "eq" for exact match |
... |
additional parameters to be passed to |
A data.frame with the list of projects
## Not run: destinations <- list_destinations(sess) destinations ## End(Not run)## Not run: destinations <- list_destinations(sess) destinations ## End(Not run)
Returns a list of models from Model Manager
list_model_contents(session, model, start = 0, limit = 20, exact = FALSE, ...)list_model_contents(session, model, start = 0, limit = 20, exact = FALSE, ...)
session |
viya_connection object, obtained through |
model |
|
start |
the index of the first content to return |
limit |
maximum number of models to return |
exact |
boolean, If the filter query should use "contains" for partial match or "eq" for exact match |
... |
additional parameters to be passed to |
A MMmodelContentList list with the list of contents
## Not run: models <- list_models(sess, filter = list(createdBy = "creatorUser", name = "modelName")) models ## End(Not run)## Not run: models <- list_models(sess, filter = list(createdBy = "creatorUser", name = "modelName")) models ## End(Not run)
Returns a list of models from Model Manager
list_models( session, start = 0, limit = 10, filters = list(), exact = FALSE, ... )list_models( session, start = 0, limit = 10, filters = list(), exact = FALSE, ... )
session |
viya_connection object, obtained through |
start |
the index of the first model to return |
limit |
maximum number of models to return |
filters |
list of of names vectors for filter parameters (createdBy, modifiedBy, name). By default it will use the |
exact |
boolean, If the filter query should use "contains" for partial match or "eq" for exact match |
... |
additional parameters to be passed to |
A data.frame with the list of models
## Not run: models <- list_models(sess, filter = list(createdBy = "creatorUser", name = "modelName")) models ## End(Not run)## Not run: models <- list_models(sess, filter = list(createdBy = "creatorUser", name = "modelName")) models ## End(Not run)
Return a data.frame of metadata of available models/decisions
list_modules( session, filters = list(), start = 0, limit = 20, verbose = FALSE, exact = FALSE, ... )list_modules( session, filters = list(), start = 0, limit = 20, verbose = FALSE, exact = FALSE, ... )
session |
viya_connection object, obtained through |
filters |
list of of names vectors for filter parameters (createdBy, modifiedBy, name). By default it will use the |
start |
the index of the first module to return |
limit |
maximum number of modules to return |
verbose |
logical, return print API call information |
exact |
boolean, If the filter query should use "contains" for partial match or "eq" for exact match |
... |
additional parameters to be passed to |
A data.frame with the list of models
## Not run: models <- list_modules(sess, filters = list(createdBy = 'myUser')) models ## End(Not run)## Not run: models <- list_modules(sess, filters = list(createdBy = 'myUser')) models ## End(Not run)
Returns a list of projects from Model Manager
list_projects( session, start = 0, limit = 10, filters = list(), exact = FALSE, ... )list_projects( session, start = 0, limit = 10, filters = list(), exact = FALSE, ... )
session |
viya_connection object, obtained through |
start |
the index of the first project to return |
limit |
maximum number of projects to return |
filters |
list of of names vectors for filter parameters (createdBy, modifiedBy, name). By default it will use the |
exact |
boolean, If the filter query should use "contains" for partial match or "eq" for exact match |
... |
additional parameters to be passed to |
A data.frame with the list of projects
## Not run: projects <- list_projects(sess, filter = list(createdBy = "creatorUser", name = "projectName")) projects ## End(Not run)## Not run: projects <- list_projects(sess, filter = list(createdBy = "creatorUser", name = "projectName")) projects ## End(Not run)
Returns a list of model repositories. This is required to be able to create model projects
list_repositories( session, start = 0, limit = 10, filters = list(), exact = FALSE, ... )list_repositories( session, start = 0, limit = 10, filters = list(), exact = FALSE, ... )
session |
viya_connection object, obtained through |
start |
the index of the first project to return |
limit |
maximum number of repositories to return |
filters |
list of of names vectors for filter parameters (createdBy, modifiedBy, name). By default it will use the |
exact |
boolean, If the filter query should use "contains" for partial match or "eq" for exact match |
... |
additional parameters to be passed to |
A data.frame with the list of repositories
## Not run: repositories <- list_repositories(sess, filter = list(createdBy = "creatorUser", name = "projectName") ) repositories ## End(Not run)## Not run: repositories <- list_repositories(sess, filter = list(createdBy = "creatorUser", name = "projectName") ) repositories ## End(Not run)
score a data.frame MASmodule/model
masScore( session, module, data, exact = TRUE, ScoreType = "score", forceTrail = TRUE, ... )masScore( session, module, data, exact = TRUE, ScoreType = "score", forceTrail = TRUE, ... )
session |
viya_connection object, obtained through |
module |
|
data |
|
exact |
the filter query should use "contains" for partial match or "eq" for exact match |
ScoreType |
|
forceTrail |
boolean, if the mas model is a decision ( |
... |
additional parameters to be passed to |
When the furrr package is installed, masScore uses furrr::future_map_dfr()
for scoring, which allows parallel execution via a future plan. Without furrr,
scoring runs sequentially using base R. Install both furrr and future to
enable parallel scoring.
data.frame with scored rows
## Not run: # single row (sequential) scored <- masScore(sess, "module_name", data[1,]) scored # Parallel scoring — requires the furrr and future packages # Not recommended for single rows due to parallelisation overhead future::plan(future::multisession, workers = future::availableCores() - 1) scored <- masScore(sess, "module_name", data) # Return to sequential execution future::plan(future::sequential) ## End(Not run)## Not run: # single row (sequential) scored <- masScore(sess, "module_name", data[1,]) scored # Parallel scoring — requires the furrr and future packages # Not recommended for single rows due to parallelisation overhead future::plan(future::multisession, workers = future::availableCores() - 1) scored <- masScore(sess, "module_name", data) # Return to sequential execution future::plan(future::sequential) ## End(Not run)
Test if the model exists inside SAS Model Manager
model_exists(session, model, ...)model_exists(session, model, ...)
session |
viya_connection object, obtained through |
model |
|
... |
additional parameters to be passed to |
boolean
## Not run: model_exists(sess, model = ModelProj) ## End(Not run)## Not run: model_exists(sess, model = ModelProj) ## End(Not run)
Requests a viya oauthtoken
oauth_consul(hostname, consul_token, verbose = FALSE)oauth_consul(hostname, consul_token, verbose = FALSE)
hostname |
string, SAS Viya url |
consul_token |
consul token uuid |
verbose |
logical, return print API call information |
list of API call request data
Other authentication:
refresh_session(),
session()
## Not run: token <- oauth_consul("http://myserver.com", consul_token = "47817a5a-3751-4fad-9558-b12b8a702b69") #token is an uuid ## End(Not run)## Not run: token <- oauth_consul("http://myserver.com", consul_token = "47817a5a-3751-4fad-9558-b12b8a702b69") #token is an uuid ## End(Not run)
Test if the project exists inside SAS Model Manager
project_exists(session, project, ...)project_exists(session, project, ...)
session |
viya_connection object, obtained through |
project |
|
... |
additional parameters to be passed to |
boolean
## Not run: project_exists(sess, project = ModelProj) ## End(Not run)## Not run: project_exists(sess, project = ModelProj) ## End(Not run)
Publish a model from Model Manager to a given destination
publish_model( session, model, name, destination = "maslocal", exact = TRUE, force = FALSE, publishInfo = FALSE, ... )publish_model( session, model, name, destination = "maslocal", exact = TRUE, force = FALSE, publishInfo = FALSE, ... )
session |
viya_connection object, obtained through |
model |
|
name |
publish endpoint, if missing, the model name will be used |
destination |
the publish destination |
exact |
the filter query should use "contains" for partial match or "eq" for exact match |
force |
force replace of a published model with the same name |
publishInfo |
boolean, returns the |
... |
additional parameters to be passed to |
A MASmodule object from get_masmodule(). If return_publish_info = TRUE or destination != maslocal, returns a publishInfo object
## Not run: mas_module <- publish_model(sess, mod, "maslocal", "R_model_published") scored <- masScore(sess, mas_module, hmeq[1,-1]) ## End(Not run)## Not run: mas_module <- publish_model(sess, mod, "maslocal", "R_model_published") scored <- masScore(sess, mas_module, hmeq[1,-1]) ## End(Not run)
Refresh a viya session object Oauth token
refresh_session(session, verbose = FALSE)refresh_session(session, verbose = FALSE)
session |
viya_connection object, obtained through |
verbose |
logical, return print API call information |
Other authentication:
oauth_consul(),
session()
## Not run: sess <- refresh_session(sess) ## End(Not run)## Not run: sess <- refresh_session(sess) ## End(Not run)
Create a new client for API call
register_client( session, client_id, client_secret, scope = list("openid"), access_token_validity = 36000, authorized_grant_types = list("client_credentials"), authorities = list("uaa.none"), additional_parameters = NULL, ... )register_client( session, client_id, client_secret, scope = list("openid"), access_token_validity = 36000, authorized_grant_types = list("client_credentials"), authorities = list("uaa.none"), additional_parameters = NULL, ... )
session |
viya_connection object, obtained through |
client_id |
name of the new client to be created |
client_secret |
client secret of the new client |
scope |
The scopes allowed for the client to obtain on behalf of users, when using any grant type other than "client_credentials". Groups are treated as scopes. Therefore, the scopes that can be obtained by the client on behalf of a user will be the intersection of the user's groups and the scopes registered to the client via this property. Use the wildcard "" to match all groups. Since SAS Viya allows authorization rules to explicitly deny access to specific groups, SAS recommends always using "". The wildcard "*" will not match internal UAA scopes. This list should always include the scope "openid", which is used to assert the identity of the user that the client is acting on behalf of. For clients that only use the grant type "client_credentials" and therefore do not act on behalf of users, use the default scope "uaa.none". |
access_token_validity |
The time in seconds to access token expiration after it is issued. |
authorized_grant_types |
The list of grant types that can be used to obtain a token with this client. Types can include authorization_code, password, implicit, and client_credentials. |
authorities |
The scopes that the client is able to grant itself when using the "client_credentials" grant type. Wildcards are not allowed. |
additional_parameters |
|
... |
additional parameters to be passed to |
A sasClient object list
## Not run: new_client <- register_client(sess, 'my_client', 'my_s3cr3t!') new_client ## End(Not run)## Not run: new_client <- register_client(sess, 'my_client', 'my_s3cr3t!') new_client ## End(Not run)
Registers a zip formatted model in SAS Model Manager.
register_model( session, file, name, project, type, force_pmml_translation = FALSE, exact = TRUE, force = FALSE, model_function = NULL, additional_project_parameters = NULL, version = "latest", project_description = "R SASctl automatic project", ... )register_model( session, file, name, project, type, force_pmml_translation = FALSE, exact = TRUE, force = FALSE, model_function = NULL, additional_project_parameters = NULL, version = "latest", project_description = "R SASctl automatic project", ... )
session |
viya_connection object, obtained through |
file |
path to file to be uploaded |
name |
model name that will be used when registering |
project |
|
type |
string, pmml, spk, zip or astore |
force_pmml_translation |
default is FALSE, set to false will upload pmml as is, but may not work properly. Only if |
exact |
the filter query should use "contains" for partial match or "eq" for exact match |
force |
Boolean, force the creation of project if unavailable |
model_function |
|
additional_project_parameters |
list of additional parameters to be passed to |
version |
This parameter indicates to create a new project version, use the latest version, or use an existing version to import the model into. Valid values are 'NEW', 'LATEST', or a number. |
project_description |
description string of additional parameters to be passed to |
... |
pass to |
a MMmodel class list
## Not run: ### Building and registering a pmml model library("pmml") hmeq <- read.csv("https://support.sas.com/documentation/onlinedoc/viya/exampledatasets/hmeq.csv", stringsAsFactors = TRUE) hmeq <- na.omit(hmeq) model1 <- lm(BAD ~ ., hmeq) saveXML(pmml(model1, model.name="General_Regression_Model", app.name="Rattle/PMML", description="Linear Regression Model"), "my_model.pmml") output <- register_model(session = sess, file = "my_model.pmml", name = "R_LinearModel", type = "pmml", ## Project UUID example projectId = "2322da44-9b24-43f6-96f4-456456231") output ### Bulding and registering an astore model with SWAT library("swat") conn <- swat::CAS(hostname = "https://my.sas.server", ## change if needed port = 8777, username = "sasuser", password = "!s3cr3t") swat::loadActionSet(conn, "astore") swat::loadActionSet(conn, "decisionTree") hmeq <- read.csv("https://support.sas.com/documentation/onlinedoc/viya/exampledatasets/hmeq.csv") castbl <- cas.upload.frame(conn, hmeq) colinfo <- cas.table.columnInfo(conn, table = castbl)$ColumnInfo target <- colinfo$Column[1] inputs <- colinfo$Column[-1] nominals <- c(target, subset(colinfo, Type == 'varchar')$Column) dt <- cas.decisionTree.dtreeTrain(conn, table = castbl, target = target, inputs = inputs, nominals = nominals, varImp = TRUE, ## save astore saveState = list(name = "dt_model_astore", replace = TRUE), casOut = list(name = 'dt_model', replace = TRUE) ) dt ## downloading astore astore_blob <- cas.astore.download(conn, rstore = list(name = "dt_model_astore") ) ## saving astore as binary file astore_path <- "./rf_model.astore" con <- file(astore_path, "wb") ### file is downloaded as base64 encoded writeBin(object = jsonlite::base64_dec(astore_blob$blob$data), con = con, useBytes = T) close(con) ### sasctl connecting sess <- session(hostname = "https://my.sas.server", username = "sasuser", password = "!s3cr3t") output <- register_model(session = sess, file = astore_path, name = "R_swatModel", type = "astore", projectId = "a0c2923b-67e9-4e7f-b5d0-549a04103523") ### Registering a Zip model output <- register_model(session = sess, file = "model.zip", name = "R_LinearModel", type = "zip", projectId = "2322da44-9b24-43f6-96f4-456456231") output ## End(Not run)## Not run: ### Building and registering a pmml model library("pmml") hmeq <- read.csv("https://support.sas.com/documentation/onlinedoc/viya/exampledatasets/hmeq.csv", stringsAsFactors = TRUE) hmeq <- na.omit(hmeq) model1 <- lm(BAD ~ ., hmeq) saveXML(pmml(model1, model.name="General_Regression_Model", app.name="Rattle/PMML", description="Linear Regression Model"), "my_model.pmml") output <- register_model(session = sess, file = "my_model.pmml", name = "R_LinearModel", type = "pmml", ## Project UUID example projectId = "2322da44-9b24-43f6-96f4-456456231") output ### Bulding and registering an astore model with SWAT library("swat") conn <- swat::CAS(hostname = "https://my.sas.server", ## change if needed port = 8777, username = "sasuser", password = "!s3cr3t") swat::loadActionSet(conn, "astore") swat::loadActionSet(conn, "decisionTree") hmeq <- read.csv("https://support.sas.com/documentation/onlinedoc/viya/exampledatasets/hmeq.csv") castbl <- cas.upload.frame(conn, hmeq) colinfo <- cas.table.columnInfo(conn, table = castbl)$ColumnInfo target <- colinfo$Column[1] inputs <- colinfo$Column[-1] nominals <- c(target, subset(colinfo, Type == 'varchar')$Column) dt <- cas.decisionTree.dtreeTrain(conn, table = castbl, target = target, inputs = inputs, nominals = nominals, varImp = TRUE, ## save astore saveState = list(name = "dt_model_astore", replace = TRUE), casOut = list(name = 'dt_model', replace = TRUE) ) dt ## downloading astore astore_blob <- cas.astore.download(conn, rstore = list(name = "dt_model_astore") ) ## saving astore as binary file astore_path <- "./rf_model.astore" con <- file(astore_path, "wb") ### file is downloaded as base64 encoded writeBin(object = jsonlite::base64_dec(astore_blob$blob$data), con = con, useBytes = T) close(con) ### sasctl connecting sess <- session(hostname = "https://my.sas.server", username = "sasuser", password = "!s3cr3t") output <- register_model(session = sess, file = astore_path, name = "R_swatModel", type = "astore", projectId = "a0c2923b-67e9-4e7f-b5d0-549a04103523") ### Registering a Zip model output <- register_model(session = sess, file = "model.zip", name = "R_LinearModel", type = "zip", projectId = "2322da44-9b24-43f6-96f4-456456231") output ## End(Not run)
Creates a Viya session object to be used in other calls
session( hostname, username = NULL, password = NULL, client_id = NULL, client_secret = NULL, oauth_token = NULL, authinfo = NULL, auth_code = FALSE, verbose = FALSE, verify_ssl = TRUE, cacert = NULL, openBrowser = TRUE, platform = TRUE )session( hostname, username = NULL, password = NULL, client_id = NULL, client_secret = NULL, oauth_token = NULL, authinfo = NULL, auth_code = FALSE, verbose = FALSE, verify_ssl = TRUE, cacert = NULL, openBrowser = TRUE, platform = TRUE )
hostname |
string, SAS Viya url |
username |
string, username for login |
password |
string, username password |
client_id |
string, client_id used for authentication, if left blank will use default |
client_secret |
string, client_secret used for authentication, if left blank will use default |
oauth_token |
string, if Oauth token is provided, a viya_connection is created |
authinfo |
A |
auth_code |
logical, if TRUE will open a browser with the user and request the authentication code to continue the authentication process. Viya 2022+ only. |
verbose |
logical, return print API call information |
verify_ssl |
boolean, verify SSL (Use it with caution) |
cacert |
ca certificate list |
openBrowser |
boolean, if |
platform |
logical, make a get call to get platform information (release, OS, siteName) |
viya_connection class object
Other authentication:
oauth_consul(),
refresh_session()
## Not run: sess <- session(hostname = "http://myserver.com", username = "myuser", password = "mysecret") ## End(Not run)## Not run: sess <- session(hostname = "http://myserver.com", username = "myuser", password = "mysecret") ## End(Not run)
Returns a sasctl MMmodel object from Model Manager
update_model( session, name, model, input_vars = NULL, output_vars = NULL, additional_parameters = NULL, update_variables = TRUE, exact = TRUE, ... )update_model( session, name, model, input_vars = NULL, output_vars = NULL, additional_parameters = NULL, update_variables = TRUE, exact = TRUE, ... )
session |
viya_connection object, obtained through |
name |
The name of the model |
model |
|
input_vars |
|
output_vars |
|
additional_parameters |
|
update_variables |
logical, TRUE, will make additional rest call to update variables using |
exact |
the filter query should use "contains" for partial match or "eq" for exact match |
... |
additional parameters to be passed to |
A MMmodel object with the model information
## Not run: updated_model <- update_model(sess, model = new_model, additional_parameters = list(description = "Updated fancy description", modeler = "BAD")) updated_model ## End(Not run)## Not run: updated_model <- update_model(sess, model = new_model, additional_parameters = list(description = "Updated fancy description", modeler = "BAD")) updated_model ## End(Not run)
Update a SAS Model Manager model variables
update_model_variables( session, model, input_vars = NULL, output_vars = NULL, exact = TRUE, ... )update_model_variables( session, model, input_vars = NULL, output_vars = NULL, exact = TRUE, ... )
session |
viya_connection object, obtained through |
model |
|
input_vars |
|
output_vars |
|
exact |
the filter query should use "contains" for partial match or "eq" for exact match |
... |
additional parameters to be passed to |
A MMmodelVariables variables
## Not run: new_variables <- update_model_variables(sess, model = new_model, input_vars = iris[,1:4], output_vars = iris[,5, drop = F] ) new_variables ## End(Not run)## Not run: new_variables <- update_model_variables(sess, model = new_model, input_vars = iris[,1:4], output_vars = iris[,5, drop = F] ) new_variables ## End(Not run)
Returns a sasctl MMproject object from Model Manager
update_project( session, name, project, input_vars = NULL, output_vars = NULL, additional_parameters = NULL, update_variables = TRUE, exact = TRUE, ... )update_project( session, name, project, input_vars = NULL, output_vars = NULL, additional_parameters = NULL, update_variables = TRUE, exact = TRUE, ... )
session |
viya_connection object, obtained through |
name |
The name of the project |
project |
|
input_vars |
|
output_vars |
|
additional_parameters |
|
update_variables |
logical, TRUE, will make additional rest call to update variables using |
exact |
the filter query should use "contains" for partial match or "eq" for exact match |
... |
additional parameters to be passed to |
A data.frame with the list of projects
## Not run: new_project <- create_project(sess, name = "ModelProj", description = "My fancy project", model_function = "classification") updated_project <- update_project(sess, project = new_project, additional_parameters = list(description = "Updated fancy description", scoreInputTable = "myTable", predictionVariable = "BAD")) updated_project ## End(Not run)## Not run: new_project <- create_project(sess, name = "ModelProj", description = "My fancy project", model_function = "classification") updated_project <- update_project(sess, project = new_project, additional_parameters = list(description = "Updated fancy description", scoreInputTable = "myTable", predictionVariable = "BAD")) updated_project ## End(Not run)
Returns a sasctl MMproject object from Model Manager
update_project_variables( session, project, input_vars = NULL, output_vars = NULL, exact = TRUE, sasctl_vars, ... )update_project_variables( session, project, input_vars = NULL, output_vars = NULL, exact = TRUE, sasctl_vars, ... )
session |
viya_connection object, obtained through |
project |
|
input_vars |
|
output_vars |
|
exact |
the filter query should use "contains" for partial match or "eq" for exact match |
sasctl_vars |
|
... |
additional parameters to be passed to |
A data.frame with the list of projects
## Not run: new_project <- create_project(sess, name = "ModelProj", description = "My fancy project", model_function = "classification") new_variables <- update_project_variables(sess, project = new_project, input_vars = iris[,1:4], output_vars = iris[,5, drop = F]) new_variables ## End(Not run)## Not run: new_project <- create_project(sess, name = "ModelProj", description = "My fancy project", model_function = "classification") new_variables <- update_project_variables(sess, project = new_project, input_vars = iris[,1:4], output_vars = iris[,5, drop = F]) new_variables ## End(Not run)
Wrapper to make generic DELETE calls to SAS Viya
vDELETE(session, path, ..., verbose = FALSE)vDELETE(session, path, ..., verbose = FALSE)
session |
viya_connection object, obtained through |
path |
character, path to the GET api endpoint |
... |
additional parameters to be passed to |
verbose |
logical, return print API call information |
An httr::response() type object
httr::GET(), httr::POST(), httr::PUT(), httr::DELETE()
Other core API requests:
vGET(),
vHEAD(),
vPOST(),
vPUT()
## Not run: folders <- vGET(session, path = "folders/folders/") newFolder <- vPOST(session, path = paste0("folders/folders/"), query = list(parentFolderUri = folders$items$parentFolderUri[1]), payload = list(name = "newFolder")) deletedFolder <- vDELETE(session, path = "folders/folders/", resourceID = newFolder$id) ## End(Not run)## Not run: folders <- vGET(session, path = "folders/folders/") newFolder <- vPOST(session, path = paste0("folders/folders/"), query = list(parentFolderUri = folders$items$parentFolderUri[1]), payload = list(name = "newFolder")) deletedFolder <- vDELETE(session, path = "folders/folders/", resourceID = newFolder$id) ## End(Not run)
Wrapper to make generic GET calls to SAS Viya
vGET(session, path, ..., query, verbose = FALSE, output = "json")vGET(session, path, ..., query, verbose = FALSE, output = "json")
session |
viya_connection object, obtained through |
path |
character, path to the GET api endpoint |
... |
additional parameters to be passed to |
query |
list, additional URL query parameters |
verbose |
logical, return print API call information |
output |
string, if |
list if output = "json" default. httr::response() if output = response.
httr::GET(), httr::POST(), httr::PUT(), httr::DELETE()
Other core API requests:
vDELETE(),
vHEAD(),
vPOST(),
vPUT()
## Not run: folders <- vGET(session, path = "folders/folders/") newFolder <- vPOST(session, path = paste0("folders/folders/"), query = list(parentFolderUri = folders$items$parentFolderUri[1]), payload = list(name = "newFolder"), httr::content_type("application/json")) deletedFolder <- vDELETE(session, path = "folders/folders/", resourceID = newFolder$id) ## End(Not run)## Not run: folders <- vGET(session, path = "folders/folders/") newFolder <- vPOST(session, path = paste0("folders/folders/"), query = list(parentFolderUri = folders$items$parentFolderUri[1]), payload = list(name = "newFolder"), httr::content_type("application/json")) deletedFolder <- vDELETE(session, path = "folders/folders/", resourceID = newFolder$id) ## End(Not run)
Wrapper to make generic DELETE calls to SAS Viya
vHEAD(session, path, payload, ..., verbose = FALSE, output = "response")vHEAD(session, path, payload, ..., verbose = FALSE, output = "response")
session |
viya_connection object, obtained through |
path |
character, path to the GET api endpoint |
payload |
list or json string, if it is a list, will be transformed in a json string using |
... |
additional parameters to be passed to |
verbose |
logical, return print API call information |
output |
string, if |
This function in built on top of httr for convenience when calling SAS Viya API endpoints..
list if output = "json" default. httr::response() if output = response.
httr::GET(), httr::POST(), httr::PUT(), httr::DELETE(), httr::response()
Other core API requests:
vDELETE(),
vGET(),
vPOST(),
vPUT()
## Not run: folders <- vGET(session, path = "folders/folders/") newFolder <- vPOST(session, path = paste0("folders/folders/"), query = list(parentFolderUri = folders$items$parentFolderUri[1]), payload = list(name = "newFolder"), httr::content_type("application/json")) deletedFolder <- vDELETE(session, path = "folders/folders/", resourceID = newFolder$id) ## End(Not run)## Not run: folders <- vGET(session, path = "folders/folders/") newFolder <- vPOST(session, path = paste0("folders/folders/"), query = list(parentFolderUri = folders$items$parentFolderUri[1]), payload = list(name = "newFolder"), httr::content_type("application/json")) deletedFolder <- vDELETE(session, path = "folders/folders/", resourceID = newFolder$id) ## End(Not run)
Wrapper to make generic POST calls to SAS Viya
vPOST( session, path, payload, ..., query, fragment, encode = "json", verbose = FALSE, output = "json" )vPOST( session, path, payload, ..., query, fragment, encode = "json", verbose = FALSE, output = "json" )
session |
viya_connection object, obtained through |
path |
character, path to the GET api endpoint |
payload |
list or json string, if it is a list, will be transformed in a json string using |
... |
additional parameters to be passed to |
query |
list, additional URL query parameters |
fragment |
string, additional URL fragment parameter |
encode |
payload encoding type, to be passed to |
verbose |
logical, return print API call information |
output |
string, if |
list if output = "json" default. httr::response() if output = response.
httr::GET(), httr::POST(), httr::PUT(), httr::DELETE()
Other core API requests:
vDELETE(),
vGET(),
vHEAD(),
vPUT()
## Not run: folders <- vGET(session, path = "folders/folders/") newFolder <- vPOST(session, path = paste0("folders/folders/"), query = list(parentFolderUri = folders$items$parentFolderUri[1]), payload = list(name = "newFolder"), httr::content_type("application/json")) deletedFolder <- vDELETE(session, path = "folders/folders/", resourceID = newFolder$id) ## End(Not run)## Not run: folders <- vGET(session, path = "folders/folders/") newFolder <- vPOST(session, path = paste0("folders/folders/"), query = list(parentFolderUri = folders$items$parentFolderUri[1]), payload = list(name = "newFolder"), httr::content_type("application/json")) deletedFolder <- vDELETE(session, path = "folders/folders/", resourceID = newFolder$id) ## End(Not run)
Wrapper to make generic DELETE calls to SAS Viya
vPUT( session, path, payload, ..., verbose = FALSE, encode = "json", output = "json" )vPUT( session, path, payload, ..., verbose = FALSE, encode = "json", output = "json" )
session |
viya_connection object, obtained through |
path |
character, path to the GET api endpoint |
payload |
list or json string, if it is a list, will be transformed in a json string using |
... |
additional parameters to be passed to |
verbose |
logical, return print API call information |
encode |
payload encoding type, to be passed to |
output |
string, if |
This function in built on top of httr for convenience when calling SAS Viya API endpoints..
list if output = "json" default. httr::response() if output = response.
httr::GET(), httr::POST(), httr::PUT(), httr::DELETE(), httr::response()
Other core API requests:
vDELETE(),
vGET(),
vHEAD(),
vPOST()
## Not run: folders <- vGET(session, path = "folders/folders/") newFolder <- vPOST(session, path = paste0("folders/folders/"), query = list(parentFolderUri = folders$items$parentFolderUri[1]), payload = list(name = "newFolder"), httr::content_type("application/json")) deletedFolder <- vDELETE(session, path = "folders/folders/", resourceID = newFolder$id) ## End(Not run)## Not run: folders <- vGET(session, path = "folders/folders/") newFolder <- vPOST(session, path = paste0("folders/folders/"), query = list(parentFolderUri = folders$items$parentFolderUri[1]), payload = list(name = "newFolder"), httr::content_type("application/json")) deletedFolder <- vDELETE(session, path = "folders/folders/", resourceID = newFolder$id) ## End(Not run)
Writes a variable descriptor JSON file for fileMetadata, it will configure the models files metadata within Model Manager in the first upload
write_fileMetadata_json( scoreCodeName = "scoreCode.R", scoreResource = "model.rda", additionalFilesNames = c(), additionalFilesRoles = c(), path = "./", noFile = FALSE )write_fileMetadata_json( scoreCodeName = "scoreCode.R", scoreResource = "model.rda", additionalFilesNames = c(), additionalFilesRoles = c(), path = "./", noFile = FALSE )
scoreCodeName |
Name of the scoring code file |
scoreResource |
rda file name or other score resources. |
additionalFilesNames |
additional files names. |
additionalFilesRoles |
additional files role names. |
path |
filepath where to write the json (don't include the filename) |
noFile |
if you don't want to write to a file, only list the output |
list of the mapped properties and values.
'ModelProperties.json' file written to path
## Using default names and files write_fileMetadata_json(noFile = TRUE) ## addition file resources ## send 2 vectors with file names and role name, must be of same length write_fileMetadata_json(additionalFilesNames = c("myFileName.ext", "myFileName2.ext"), additionalFilesRoles = c("scoreResource", "scoreResource"), noFile = TRUE )## Using default names and files write_fileMetadata_json(noFile = TRUE) ## addition file resources ## send 2 vectors with file names and role name, must be of same length write_fileMetadata_json(additionalFilesNames = c("myFileName.ext", "myFileName2.ext"), additionalFilesRoles = c("scoreResource", "scoreResource"), noFile = TRUE )
Writes a variable descriptor JSON file for input or output variables, based on an input dataframe containing predictor and prediction columns.
write_in_out_json(data, input = TRUE, path = "./", noFile = FALSE)write_in_out_json(data, input = TRUE, path = "./", noFile = FALSE)
data |
|
input |
|
path |
default to current work dir |
noFile |
if you don't want to write to a file, only the output |
list of the mapped types and sizes.
'inputVar.json' or 'outputVar.json' file written to path
write_in_out_json(iris[,5, drop = FALSE], input = FALSE, noFile = TRUE) write_in_out_json(iris[,1:4], input = TRUE, noFile = TRUE)write_in_out_json(iris[,5, drop = FALSE], input = FALSE, noFile = TRUE) write_in_out_json(iris[,1:4], input = TRUE, noFile = TRUE)
Writes a descriptor JSON file for ModelProperties, it will configure the model properties within Model Manager
write_ModelProperties_json( modelName, modelDescription = "R model", modelFunction, trainTable = " ", algorithm, numTargetCategories, targetEvent, targetVariable, eventProbVar, modeler = " ", tool = "R", toolVersion = "default", path = "./", noFile = FALSE )write_ModelProperties_json( modelName, modelDescription = "R model", modelFunction, trainTable = " ", algorithm, numTargetCategories, targetEvent, targetVariable, eventProbVar, modeler = " ", tool = "R", toolVersion = "default", path = "./", noFile = FALSE )
modelName |
Name of the model |
modelDescription |
String describing the model |
modelFunction |
Classification, Prediction, Segmentation, Analytical or Clustering. |
trainTable |
Name of the training table |
algorithm |
Algorithm name (Random Forest, GLM, Linear Regression, etc.) |
numTargetCategories |
number of possible classes for classification |
targetEvent |
Target event label eg: "1", "versicolor" etc. |
targetVariable |
Target variable name |
eventProbVar |
Variable name that has the |
modeler |
Modeler's name |
tool |
Name of the tool used to build the model |
toolVersion |
Version of the tool used to build the model |
path |
file path where to write the json (don't include the filename) |
noFile |
if you don't want to write to a file, only list the output |
list of the mapped properties and values.
'ModelProperties.json' file written to path
write_ModelProperties_json(modelName = "My R Model", modelDescription = "Awesome Description", modelFunction = "Classification", trainTable = " ", algorithm = "Logistic Regression", numTargetCategories = 2, targetEvent = "BAD", targetVariable = "P_BAD1", eventProbVar = "P_BAD1", modeler = "John SAS", noFile = TRUE)write_ModelProperties_json(modelName = "My R Model", modelDescription = "Awesome Description", modelFunction = "Classification", trainTable = " ", algorithm = "Logistic Regression", numTargetCategories = 2, targetEvent = "BAD", targetVariable = "P_BAD1", eventProbVar = "P_BAD1", modeler = "John SAS", noFile = TRUE)