sql server - How to check if number of parameters is less than 2 in R? -


i tried write procedure compute cronbach alpha if there more 1 parameter , return 0 othwerwise. works correct input fails if number of field alpha calls 0 or 1. how can check if input suitable alpha? tried check number of parameters less 2 somehow fails.

use [jaakko] go /****** object:  storedprocedure [dbo].[sp_alpha]    script date: 15.8.2017 11.30.30 ******/ set ansi_nulls on go set quoted_identifier on go  alter procedure [dbo].[sp_alpha]     @input nvarchar(max) begin     -- set nocount on added prevent result sets     -- interfering select statements.     set nocount on;      exec sp_execute_external_script     @language = n'r'     , @script = n'library(psych);          if (dim(test)<2) {             return(0)          } else {              = trycatch(alpha(test), warning = function(w) {alpha(test,check.keys=true)})              str(a)          }'      , @input_data_1 = @input     , @input_data_1_name = n'test' end 

i call procedure as

exec sp_alpha 'select cast(ky1 float) vuodet' 

it outputs

msg 39004, level 16, state 20, line 1 'r' script error occurred during execution of 'sp_execute_external_script' hresult 0x80004004. msg 39019, level 16, state 1, line 1 external script error occurred:  error in r[1, 2] : subscript out of bounds calls: source ... trycatch -> trycatchlist -> trycatchone -> dotrycatch -> alpha in addition: warning message: in if (dim(test) < 2) { :   condition has length > 1 , first element used  error in scaler.  check output more information. error in eval(expr, envir, enclos) :    error in scaler.  check output more information. calls: source -> withvisible -> eval -> eval -> .call execution halted 


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -