This project has moved and is read-only. For the latest updates, please go here.

Compatibility Error Occured while running R code in MicroStrategy

Jul 28, 2014 at 8:16 AM
Hi All,
I have created an RScript which is like this
Its working fine in the RGui Console and verified when I paste this code via deployR() in creating new metric.But the data is not coming and error is logged in the error file which is given below
"Actual data type CLOSXP (3) is not compatible with expected data type double for output 'twosam'."
Please help me what Iam doing wrong and how to solve it asap.
Jul 30, 2014 at 6:24 AM
Please Help Me..Its Important and I can't find any clue
Jul 31, 2014 at 9:35 PM
Thanks for your question and sorry that you are having issues running your script.

It’s good that you have a function “twosam” that you wish to deploy to MicroStrategy. However, based on the code you’ve provided, all you have is a function created in R code. There’s nothing in your script that calls that function.

MicroStrategy treats the R Script as a black box with your code inside and MicroStrategy just needs to know how to pass data to that black box and consume the results from it. Unfortunately, It appears you are trying to return an R variable called “twosam” to MicroStrategy but twosam is a function (with an odd R data type CLOSXP). We pass data (scalars or vectors as numbers or text or booleans), not functions. This is all discussed in the R Integration Pack User Guide, see

We would suggest modifying your script with three main changes (hopefully the comments added makes it clear what we’ve done and why):
1) We cleaned up your function code without changing its behavior
2) We added “Dual Execution Mode” so the code runs both in the R Console and the MicroStrategy environment (see page 17 of the User Guide)
3) We added code that actually calls your twosam function
twosam <- function(y1, y2) {   #twosam is a function that returns the doubled sum of two numbers 

if(!exists("mstr.ExFlag")) {   #If this is NOT executed by MicroStrategy
  y1 <- 10                     #  Then set the y1 value for when this is run from the R Console 
  y2 <- 20                     #  Then set the y2 value for when this is run from the R Console 
}                              #  When run from the R Console, this will return 60 if y1=10 and y2=20

X <- twosam(Y1, Y2)            #Execute the twosam function
You should then use the deployR tool to capture the analytic’s signature (see page 26 of the User Guide) which will appear as this header block at the top of your script:
#RVAR Y1 -input -numeric -vector
#RVAR Y2 -input -numeric -vector
#RVAR X -output -numeric -vector  #Metric Expression: RScript<_RScriptFile="twosam.R", _InputNames="Y1, Y2">(Y1, Y2)
if(exists("mstr.WorkingDir")) setwd(mstr.WorkingDir)  #Working Directory if executed by MicroStrategy
Save the script with these changes to the RScripts folder. Then, to create a new metric that executes your R Script, paste into any metric editor the metric expression “RScript<_RScriptFile="twosam.R", _InputNames="Y1, Y2">(Y1, Y2)” and replace Y1 and Y2 with MicroStrategy metrics. When the new metric executes, MicroStratetgy will pass the data to your script, execute it inside R and consume the results.

Hopefully this makes sense. Good luck and please let us know how it goes!
Marked as answer by martin92 on 8/4/2014 at 8:13 AM
Aug 1, 2014 at 10:10 AM
Thank you Sir,Now it works and I came to know what Iam doing wrong.Actually Iam new to MicroStrategy and R Analytics and I have assigned a task to create function in R and call it in MicroStrategy.I couldn't find any simple example in any pdf..Thank you once gain for your help.Hope you will help again.
Aug 1, 2014 at 10:24 AM
Can u suggest any good pdf or link in which R Analytic with MicroStrategy is given with basic examples that will be usefull to primer like me.
Aug 1, 2014 at 4:43 PM
Yes, of course.

First of all, there's the User Guide which is part of the installation and available any time from this website, just go to the Home or Documentation tab and CLICK HERE for the R Integration Pack User Guide. If you hadn't used this before, that would explain a lot of your confusion.

We also ship a sample R Script that's part of the installation, SeasonalForecasting.R. That script and other "Off-the-Shelf" R Scripts ready for you to deploy with complete documentation can also be found on this website, just go to the Home or Documentation tab and CLICK HERE for the R Script "Shelf" that contains ready-to-go R Analytics. If you hadn't seen these before, they should meet your needs.

Finally, on the MicroStrategy Corporate Site", you'll find two ½ hour video Webcasts on our R integration with more examples and tips: Part 1 for End-Users (installation/deployment) and Part 2 for R Developers.

Hope this helps, and good luck!