Skip to main content

User Defined Function


Sudip_Chatterje
In case of R Udf when you are describing an 'outtypecallback' function, I am wondering if there is any example of describing scale for example: ret = data.frame(datatype = rep(NA,1), length = rep(NA,1), scale = rep(NA,1), name = rep(NA,1)). How do you define scale ??

2 replies

Forum|alt.badge.img+2
  • Participating Frequently
  • April 24, 2013
Hi Sudip, thanks for your question! We'll see if any of our community members can give you a hand with this.

Forum|alt.badge.img+2
  • Participating Frequently
  • April 25, 2013
Hi Sudip, The scale parameter is used only for the NUMERIC data type - e.g., if your UDF wants to return a NUMERIC(10,2), you'd use length=rep(10, 1), scale=rep(2, 1). E.g.:
   NumericReturntype <- function(x)  {        ret <- data.frame(datatype=rep("numeric", 1), length=rep(10, 1), scale=rep(2,1), name=rep("my_numeric_col",1))         ret  }  
You can also use the input data types to determine your length and scale - in the above example, 10 and 2 need not be constants - you can compute them in the function. Hope this helps!