Partilhar via


OutputParameter: parâmetro de saída para procedimento armazenado SQL: gerador de classe

OutputParameter: gera um objeto OutputParameter que captura as informações sobre os parâmetros de saída da função que deve ser inserida em um procedimento armazenado do SQL Server. Eles se tornarão os parâmetros de saída do procedimento armazenado. Os tipos de R com suporte dos parâmetros de saída são POSIXct, numeric, character, integer, logical e raw. Esse objeto deverá ser criado se a função R estiver retornando uma lista nomeada para membros da lista que não são estruturas de dados

Uso

  OutputParameter(name, type)

Argumentos

name

Uma cadeia de caracteres, o nome do objeto de parâmetro de saída.

type

Tipo R do objeto do parâmetro de saída.

Valor

Objeto OutputParameter

Exemplos


 ## Not run:

 # See ?StoredProcedure for creating the "cleandata" table.

 # train 2 takes a data frame with clean data and outputs a model
 # as well as the data on the basis of which the model was built
 train2 <- function(in_df) {
 in_df[,"DayOfWeek"] <- factor(in_df[,"DayOfWeek"], levels=c("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"))
   # The model formula
   formula <- ArrDelay ~ CRSDepTime + DayOfWeek + CRSDepHour:DayOfWeek
   # Train the model
   rxSetComputeContext("local")
   mm <- rxLinMod(formula, data=in_df, transformFunc=NULL, transformVars=NULL)
   mm <- rxSerializeModel(mm)
   return(list(mm = mm, in_df = in_df))
 }
 # create InpuData Object for an input parameter that is a data frame
 # note: if the input parameter is not a data frame use InputParameter object
 id <- InputData(name = "in_df",
                 defaultQuery = paste0("select top 10000 ArrDelay,CRSDepTime,",
                                       "DayOfWeek,CRSDepHour from cleanData"))
 out1 <- OutputData("in_df")
 # create an OutputParameter object for the variable "mm" inside the return list
 out2 <- OutputParameter("mm", "raw")
 # connections string
 conStr <- paste0("Driver={ODBC Driver 13 for SQL Server};Server=.;Database=RevoTestDB;",
                  "Trusted_Connection=Yes;")
 # create the stored procedure object
 sp_df_op <- StoredProcedure(train2, "spTest2", id, out1, out2,
                         filePath = ".")
 registerStoredProcedure(sp_df_op, conStr)
 result <- executeStoredProcedure(sp_df_op, connectionString = conStr)
 # Get back the linear model.
 mm <- rxUnserializeModel(result$params$op1)
## End(Not run)